Is there any way to exclude specific patterns from no-undef
error. I tried 'no-undef': [2, { ignoreBuiltinGlobals: ['app'] }]
where app
is my global variable defined by webpack.defineplugin. If I switch this rule off - no errors appear.
I also tried to insert app: true
in globals
section of .eslintrc.js
Or another way to get my variable 'def'
without errors
This produces a different outcome than defining var x = undefined in the loop, as x is no longer reset to undefined each time through the loop. If you’re using such an initialization inside of a loop, then you should disable this rule. Example of correct code for this rule, because it is disabled on a specific line:
If you tell ESLint the environment is jest test () and expect () won't be considered as undefined. And since the default test files for jest are "**/*.spec.js", "**/__mocks__/**" I'd suggest you to add
There is one situation where initializing to undefined behaves differently than omitting the initialization, and that’s when a var declaration occurs inside of a loop. For example: In this case, the var x is hoisted out of the loop, effectively creating: If you were to remove the initialization, then the behavior of the loop changes:
Errors can be ignored by adding a regular expression to the configuration file under the ignoreErrors key. To ignore an error by a regular expression in the whole project, add a string entry: To ignore errors by a regular expression only in a specific file, add an entry with message and path or paths keys.
I understand that you want eslint to ignore the app
global variable.
Did you try /*global app */
?
More info here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With