How to disable the rule of discouraging the use of var and encouraging the use of const or let instead on ESlint?

1

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.

0

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 */ ... 

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:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.