{"name":"eslint-plugin-tree-shaking","description":"Marks all side-effects in module initialization that will interfere with tree-shaking","keywords":["eslint","eslintplugin","eslint-plugin","tree-shaking","side-effects","rollup","webpack"],"author":{"name":"Lukas Taegert"},"main":"lib/index.js","scripts":{"test":"mocha tests/lib/rules/no-side-effects-in-initialization.js","lint":"prettier-standard *.js lib/**/*.js tests/**/*.js","precommit":"lint-staged","commitmsg":"validate-commit-msg","postcommit":"git reset","prepush":"npm test","postmerge":"npm install && npm prune","postrewrite":"npm install && npm prune","semantic-release":"semantic-release pre && npm publish && semantic-release post"},"lint-staged":{"*.js":["prettier-standard","standard --fix","git add"]},"devDependencies":{"babel-eslint":"^7.2.3","eslint":"^4.4.1","husky":"^0.14.3","lint-staged":"^4.0.3","mocha":"^3.5.0","prettier-standard":"^6.0.0","rollup":"^0.49.3","semantic-release":"^7.0.2","standard":"^10.0.3","validate-commit-msg":"^2.14.0"},"engines":{"node":">=6.0.0"},"license":"MIT","repository":{"type":"git","url":"git+https://github.com/lukastaegert/eslint-plugin-tree-shaking.git"},"version":"1.6.0","gitHead":"604a3e784f5da3021ccef13d50d261c5bc3fb8ca","bugs":{"url":"https://github.com/lukastaegert/eslint-plugin-tree-shaking/issues"},"homepage":"https://github.com/lukastaegert/eslint-plugin-tree-shaking#readme","_id":"eslint-plugin-tree-shaking@1.6.0","_npmVersion":"5.3.0","_nodeVersion":"8.4.0","_npmUser":{"name":"lukastaegert","email":"lukas.taegert@tngtech.com"},"dist":{"integrity":"sha512-z5oLglwrI8jOmnG4GNo/zNNlh36in6UWbCsvKFFN0QhdFeGlYgLa2f686b2L6oLShd/RkYI+a75GQgFC6RpY3A==","shasum":"6d6ee56dffcf517dd4d3f5edc50ad2448cbe84bc","tarball":"http://registry-npm.ywwl.com/eslint-plugin-tree-shaking/download/eslint-plugin-tree-shaking-1.6.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDzldhS2KVVt1wH7I7ST1uuDug6l2fXOiu8jQfEV6HmDAIgN6Yp6vymiAok2qgx88jDCKzScgwgd/XtYtrKvkfmPpk="}],"size":18652,"noattachment":false,"key":"/eslint-plugin-tree-shaking/-/eslint-plugin-tree-shaking-1.6.0.tgz"},"maintainers":[{"name":"lukastaegert","email":"lukas.taegert@tngtech.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eslint-plugin-tree-shaking-1.6.0.tgz_1505108466412_0.7618228397332132"},"directories":{},"readme":"# eslint-plugin-tree-shaking\n\nMarks all side-effects in module initialization that will interfere with tree-shaking\n\n[![npm](https://img.shields.io/npm/v/eslint-plugin-tree-shaking.svg?maxAge=3600)](https://www.npmjs.com/package/eslint-plugin-tree-shaking)\n[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?maxAge=3600)](http://standardjs.com/)\n[![Greenkeeper badge](https://badges.greenkeeper.io/lukastaegert/eslint-plugin-tree-shaking.svg)](https://greenkeeper.io/)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?maxAge=3600)](https://github.com/semantic-release/semantic-release)\n\n## Usage\n\nThis plugin is intended as a means for library developers to identify patterns that will\ninterfere with the tree-shaking algorithm of their module bundler (i.e.\n[rollup or webpack](https://medium.com/webpack/webpack-and-rollup-the-same-but-different-a41ad427058c)).\n\n**JavaScript:**\n\n```javascript\nmyGlobal = 17;\nconst x = { [globalFunction()]: \"myString\" };\n\nexport default 42;\n```\n\n**Rollup output:**\n\n```javascript\nmyGlobal = 17;\nconst x = { [globalFunction()]: \"myString\" };\n\nvar index = 42;\n\nexport default index;\n```\n\n**ESLint output:**\n\n```\n1:1   error  Cannot determine side-effects of assignment to global variable\n2:13  error  Cannot determine side-effects of calling global function\n```\n\nThis plugin is most useful when you\n[integrate ESLint with your editor](http://eslint.org/docs/user-guide/integrations).\n\n## Installation and Setup\n\nYou'll first need to install [ESLint](http://eslint.org):\n\n```\n$ npm i eslint --save-dev\n```\n\nNext, install `eslint-plugin-tree-shaking`:\n\n```\n$ npm install eslint-plugin-tree-shaking --save-dev\n```\n\n**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-tree-shaking` globally.\n\nAdd `tree-shaking` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:\n\n```json\n{\n  \"plugins\": [\"tree-shaking\"]\n}\n```\n\nThen add the rule `no-side-effects-in-initialization` to the rules section:\n\n```json\n{\n  \"rules\": {\n    \"tree-shaking/no-side-effects-in-initialization\": 2\n  }\n}\n```\n\nTo prevent false positives, configure like this:\n\n```json\n{\n  \"rules\": {\n    \"tree-shaking/no-side-effects-in-initialization\": [\n      2,\n      {\n        \"noSideEffectsWhenCalled\": [\n          { \"function\": \"Object.freeze\" },\n          {\n            \"module\": \"react\",\n            \"functions\": [\"createContext\", \"createRef\"]\n          },\n          {\n            \"module\": \"zod\",\n            \"functions\": [\"array\", \"string\", \"nativeEnum\", \"number\", \"object\", \"optional\"]\n          },\n          {\n            \"module\": \"my/local/module\",\n            \"functions\": [\"foo\", \"bar\", \"baz\"]\n          }\n        ]\n      }\n    ]\n  }\n}\n```\n\n## Magic Comments\n\nESLint only ever analyzes one file at a time and by default, this plugin assumes that all imported\nfunctions have side-effects. If this is not the case, this plugin supports magic comments you can\nadd before identifiers in imports and exports to specify that you assume an import or export to be a\npure function. Examples:\n\n- By default, imported functions are assumed to have side-effects:\n\n  **JavaScript:**\n\n  ```javascript\n  import { x } from \"./some-file\";\n  x();\n  ```\n\n  **ESLint output:**\n\n  ```\n  1:9  error  Cannot determine side-effects of calling imported function\n  ```\n\n- You can mark a side-effect free import with a magic comment:\n\n  **JavaScript:**\n\n  ```javascript\n  import { /* tree-shaking no-side-effects-when-called */ x } from \"./some-file\";\n  x();\n  ```\n\n  **No ESLint errors**\n\n- By default, exported functions are not checked for side-effects:\n\n  **JavaScript:**\n\n  ```javascript\n  export const x = globalFunction;\n  ```\n\n  **No ESLint errors**\n\n- You can check exports for side-effects with a magic comment:\n\n  **JavaScript:**\n\n  ```javascript\n  export const /* tree-shaking no-side-effects-when-called */ x = globalFunction;\n  ```\n\n  **ESLint output:**\n\n  ```\n  1:65  error  Cannot determine side-effects of calling global function\n  ```\n\n## Background and Planned Development\n\nThis plugin is in development. If you want to contribute, please read\n[CONTRIBUTING.md](./CONTRIBUTING.md).\n\nThis plugin implements a side-effect detection algorithm similar to what rollup uses to determine\nif code can be removed safely. However, there is no one-to-one correspondence. If you find that you have code that\n\n- is not removed by rollup (even though tree-shaking is enabled) but\n- has no ESLint issues\n\nplease--if no-one else has done so yet--[check the guidelines](./CONTRIBUTING.md) and **file an issue!**\n","publish_time":1505108467372,"_cnpm_publish_time":1505108467372,"dist-tags":{"latest":"1.12.2"}}