9.0.0 β€’ Published 1 month ago

@putout/plugin-remove-unused-variables v9.0.0

Weekly downloads
3,165
License
MIT
Repository
github
Last release
1 month ago

@putout/plugin-remove-unused-variables NPM version

A variable is a container for a value, like a number we might use in a sum, or a string that we might use as part of a sentence.

(c) MDN

🐊Putout plugin adds ability to find and remove the variables that are declared, but:

  • not passed as argument to a function;
  • not used as operand in expression;

That is unused variables. Most likely it is a leftovers due to incomplete transforming of the code. Such variables take up space and gives no value so they must be removed.

☝️Remember, when you writing a transform you can skip all parts related to removing unused variables and just reuse current plugin it will make your code simpler and less error prone.

☝️No, you cannot just look at referenced and constant fields to determine if you can remove variable and here is why one of the biggest plugins exists.

Install

npm i @putout/plugin-remove-unused-variables -D

Rule

Rule remove-unused-variables is enabled by default, to disable add to .putout.json:

{
    "rules": {
        "remove-unused-variables": "off"
    }
}

❌ Example of incorrect code

const a = 'hello';
const b = 'world';

console.log(a);

βœ… Example of correct code

const a = 'hello';
console.log(a);

Comparison

LinterRuleFix
🐊 Putoutremove-unused-variablesβœ…
⏣ ESLintno-unused-vars❌

License

MIT

9.0.0

1 month ago

8.1.0

4 months ago

8.0.0

4 months ago

7.0.0

7 months ago

6.0.1

9 months ago

6.0.0

9 months ago

6.0.2

9 months ago

5.3.0

11 months ago

5.4.0

11 months ago

5.2.0

11 months ago

5.0.0

1 year ago

5.1.0

12 months ago

4.2.0

1 year ago

4.1.0

2 years ago

4.0.0

2 years ago

3.8.0

2 years ago

3.8.1

2 years ago

3.6.1

2 years ago

3.6.0

2 years ago

3.7.0

2 years ago

3.5.3

2 years ago

3.5.1

2 years ago

3.4.0

3 years ago

3.2.0

3 years ago

3.3.0

3 years ago

3.5.0

3 years ago

3.1.0

4 years ago

3.0.0

4 years ago

2.6.1

4 years ago

2.6.0

4 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.2.0

4 years ago

2.3.0

4 years ago

2.1.0

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.57.0

4 years ago

1.56.0

4 years ago

1.55.0

4 years ago

1.54.0

4 years ago

1.53.0

4 years ago

1.52.0

5 years ago

1.51.1

5 years ago

1.51.0

5 years ago

1.50.0

5 years ago

1.49.0

5 years ago

1.48.0

5 years ago

1.47.0

5 years ago

1.46.0

5 years ago

1.45.0

5 years ago

1.44.0

5 years ago

1.43.0

5 years ago

1.42.0

5 years ago

1.41.0

5 years ago

1.40.0

5 years ago

1.39.0

5 years ago

1.38.0

5 years ago

1.37.1

5 years ago

1.37.0

5 years ago

1.36.0

5 years ago

1.35.1

5 years ago

1.35.0

5 years ago

1.34.0

5 years ago

1.33.0

5 years ago

1.32.0

5 years ago

1.31.0

5 years ago

1.30.1

5 years ago

1.30.0

5 years ago

1.29.0

5 years ago

1.28.0

5 years ago

1.27.1

5 years ago

1.27.0

5 years ago

1.26.1

5 years ago

1.26.0

5 years ago

1.25.1

5 years ago

1.25.0

5 years ago

1.24.0

5 years ago

1.23.0

5 years ago

1.22.0

5 years ago

1.21.0

5 years ago

1.20.0

5 years ago

1.19.0

5 years ago

1.18.0

5 years ago

1.17.0

5 years ago

1.16.0

5 years ago

1.15.1

5 years ago

1.15.0

5 years ago

1.14.0

5 years ago

1.13.0

5 years ago

1.12.1

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago