Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/manantank/eslint-plugin-better-tree-shaking
https://github.com/manantank/eslint-plugin-better-tree-shaking
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/manantank/eslint-plugin-better-tree-shaking
- Owner: MananTank
- License: mit
- Created: 2023-06-19T10:50:29.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-04T22:50:39.000Z (about 1 year ago)
- Last Synced: 2024-11-17T15:54:45.353Z (3 days ago)
- Language: TypeScript
- Size: 97.7 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-plugin-better-tree-shaking
## What?
Improve tree-shaking of your app/library by annotating top-level side-effects with `/* @__PURE__ */` comment.
## Examples
```js
import FOO from './foo'// accessing member's member
export const t1_wrong = FOO.bar.bazz // ❌
export const t1_correct = /* @__PURE__ */ (() => FOO.bar.bazz)() // ✅// calling method
export const t2_wrong = FOO.bar() // ❌
export const t2_correct = /* @__PURE__ */ FOO.bar() // ✅// calling function
export const t3_wrong = FOO() // ❌
export const t3_correct = /* @__PURE__ */ FOO() // ✅// multiple side effects in object
export const t4_wrong = {
a: FOO(),
[FOO.bar.bazz]: FOO.bar(),
c: FOO.bar.bazz,
} // ❌export const t4_correct = /* @__PURE__ */ (() => ({
a: FOO(),
[FOO.bar.bazz]: FOO.bar(),
c: FOO.bar.bazz,
}))() // ✅// accessing implicit global variable's member
export const t5_wrong = SOME_GLOBAL.FOO // ❌
export const t5_correct = /* @__PURE__ */ (() => SOME_GLOBAL.FOO)() // ✅// calling implicit global variable's method
export const t6_wrong = SOME_GLOBAL.FOO() // ❌
export const t6_correct = /* @__PURE__ */ SOME_GLOBAL.FOO() // ✅
```
## Install
```bash
npm i -D eslint-plugin-better-tree-shaking
```
## Setup with ESLint
### Step 1: Add the plugin in ESLint Config
Add `"better-tree-shaking"` to the plugins section of your ESLint configuration file.
```json
{
"plugins": ["better-tree-shaking"]
}
```### Step 2: Add the Plugin's rule
Add the `"better-tree-shaking/no-top-level-side-effects"` rule in your ESLint config file as shown below
```json
"rules": {
"better-tree-shaking/no-top-level-side-effects": "error"
}
```
### Licence
MIT