Installations
npm install eslint-plugin-tree-shaking
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=6.0.0
Node Version
18.20.4
NPM Version
9.8.1
Score
96.3
Supply Chain
99.5
Quality
77.7
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.55%)
Shell (0.29%)
JavaScript (0.16%)
Developer
lukastaegert
Download Statistics
Total Downloads
3,480,776
Last Day
881
Last Week
13,599
Last Month
99,177
Last Year
1,530,714
GitHub Statistics
201 Stars
149 Commits
9 Forks
5 Watching
278 Branches
6 Contributors
Package Meta Information
Latest Version
1.12.2
Package Id
eslint-plugin-tree-shaking@1.12.2
Unpacked Size
57.61 kB
Size
10.63 kB
File Count
8
NPM Version
9.8.1
Node Version
18.20.4
Publised On
19 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
3,480,776
Last day
-81.5%
881
Compared to previous day
Last week
-42.3%
13,599
Compared to previous week
Last month
-36.3%
99,177
Compared to previous month
Last year
22%
1,530,714
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
22
eslint-plugin-tree-shaking
Marks all side-effects in module initialization that will interfere with tree-shaking
Usage
This plugin is intended as a means for library developers to identify patterns that will interfere with the tree-shaking algorithm of their module bundler (i.e. rollup or webpack).
JavaScript:
1myGlobal = 17; 2const x = { [globalFunction()]: "myString" }; 3 4export default 42;
Rollup output:
1myGlobal = 17; 2const x = { [globalFunction()]: "myString" }; 3 4var index = 42; 5 6export default index;
ESLint output:
1:1 error Cannot determine side-effects of assignment to global variable
2:13 error Cannot determine side-effects of calling global function
This plugin is most useful when you integrate ESLint with your editor.
Installation and Setup
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-tree-shaking
:
$ npm install eslint-plugin-tree-shaking --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-tree-shaking
globally.
Add tree-shaking
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
1{ 2 "plugins": ["tree-shaking"] 3}
Then add the rule no-side-effects-in-initialization
to the rules section:
1{ 2 "rules": { 3 "tree-shaking/no-side-effects-in-initialization": 2 4 } 5}
To prevent false positives, configure like this:
1{ 2 "rules": { 3 "tree-shaking/no-side-effects-in-initialization": [ 4 2, 5 { 6 "noSideEffectsWhenCalled": [ 7 { "function": "Object.freeze" }, 8 { 9 "module": "react", 10 "functions": ["createContext", "createRef"] 11 }, 12 { 13 "module": "zod", 14 "functions": ["array", "string", "nativeEnum", "number", "object", "optional"] 15 }, 16 { 17 "module": "my/local/module", 18 "functions": ["foo", "bar", "baz"] 19 } 20 ] 21 } 22 ] 23 } 24}
Magic Comments
ESLint only ever analyzes one file at a time and by default, this plugin assumes that all imported functions have side-effects. If this is not the case, this plugin supports magic comments you can add before identifiers in imports and exports to specify that you assume an import or export to be a pure function. Examples:
-
By default, imported functions are assumed to have side-effects:
JavaScript:
1import { x } from "./some-file"; 2x();
ESLint output:
1:9 error Cannot determine side-effects of calling imported function
-
You can mark a side-effect free import with a magic comment:
JavaScript:
1import { /* tree-shaking no-side-effects-when-called */ x } from "./some-file"; 2x();
No ESLint errors
-
By default, exported functions are not checked for side-effects:
JavaScript:
1export const x = globalFunction;
No ESLint errors
-
You can check exports for side-effects with a magic comment:
JavaScript:
1export const /* tree-shaking no-side-effects-when-called */ x = globalFunction;
ESLint output:
1:65 error Cannot determine side-effects of calling global function
Background and Planned Development
This plugin is in development. If you want to contribute, please read CONTRIBUTING.md.
This plugin implements a side-effect detection algorithm similar to what rollup uses to determine if code can be removed safely. However, there is no one-to-one correspondence. If you find that you have code that
- is not removed by rollup (even though tree-shaking is enabled) but
- has no ESLint issues
please--if no-one else has done so yet--check the guidelines and file an issue!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
all changesets reviewed
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/lukastaegert/eslint-plugin-tree-shaking/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/release.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/lukastaegert/eslint-plugin-tree-shaking/release.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/style.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/lukastaegert/eslint-plugin-tree-shaking/style.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/style.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/lukastaegert/eslint-plugin-tree-shaking/style.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/lukastaegert/eslint-plugin-tree-shaking/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/lukastaegert/eslint-plugin-tree-shaking/test.yml/master?enable=pin
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 5 out of 5 npmCommand dependencies pinned
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Warn: no topLevel permission defined: .github/workflows/style.yml:1
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to eslint-plugin-tree-shaking
eslint-plugin-better-tree-shaking
ESLint plugin for better tree shaking
eslint-plugin-you-dont-need-momentjs
Check better alternatives you can use without momentjs
@emiplegiaqmnpm/aliquid-porro-quidem
The @emiplegiaqmnpm/aliquid-porro-quidem library is a 0 dependency library with several exports to support general app development. This library has several exports to limit what is loaded into memory & to make tree-shaking less intensive. Some of the und