How to disable the rule of discouraging the use of var and encouraging the use of const or let instead on ESlint?
-
1It is boolean flag. Set it to true or false in eslint.json config file. – Vayrex Mar 28 '18 at 02:31
3 Answers
In your package.json
(assuming that is what you are using), include:
"eslintConfig": {
"rules": {
"no-var": 0
}
}
no-var
is the rule, and 0
sets the rule to "off".
If you're not using package.json
, you can set the the same in an .eslintrc.js
, or, on a per-file basis, include a comment at the top of the file /* eslint no-var: 0 */
.
All this comes from the ESlint Configuration Documentation.

- 12,804
- 4
- 25
- 45
Extending the previous answer, all of these variants work for comments at the beginning of the block:
/* eslint no-var: off */
...
/* eslint no-var: */
...
/* eslint no-var: 0 */
...

- 19,236
- 15
- 93
- 97
The valid cases for using var
are extremely limited, so it's good to consider disabling the no-var
rule only on specific lines where's it's justified.
The //eslint-disable-line [RULE]
comment can be used to turn off a single rule on a single line.
For example, if you're working with the Google Tracking dataLayer
array:
declare global { var dataLayer: unknown[] } //eslint-disable-line no-var
...
globalThis.dataLayer.push(args);
For more details:
https://eslint.org/docs/latest/use/configure/rules#disabling-rules

- 5,625
- 6
- 39
- 67