no-unused-vars behavior with global variables
See original GitHub issueWhen the scope is all
, and you declare a global variable in one file:
// file1.js
myGlobal = 123;
but you only consume the variable in another file:
// file2.js
console.log(myGlobal);
ESLint doesn’t pass (because it’s only looking at each file individually). Since almost invariably global variables are used across files, this really reduces the utility of the all
option.
Any chance ESLint can do a quick pass across all files first so it’s aware of global var definitions and usages? Thanks for the awesome project @nzakas !
Issue Analytics
- State:
- Created 8 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
ESLint - Configuring "no-unused-vars" for TypeScript
My issue was with using decorators and wanting to have a variable with an appropriate name for clarity, for example:.
Read more >no-unused-vars - ESLint - Pluggable JavaScript Linter
This rule is aimed at eliminating unused variables, functions, and function ... /*eslint no-unused-vars: "error"*/ /*global some_unused_var*/ // It checks ...
Read more >Global Variables - Opsive
Global Variables. Global variables are similar to local variables except any behavior tree can access an instance of the same variable.
Read more >The 3 Best ESLint No-Unused-Vars Option Settings (Make it ...
The no-unused-vars rule is one of the most important ESLint rules for keeping ... All three of these options change the default behavior....
Read more >Why global variables are bad - Code with Jason
Why are global variables so often advised against? ... involve the instance variable in order to understand the behavior of the function.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m sorry, this is very far outside the scope of what ESLint is meant to do and I don’t see addressing this. I think the best advice we can offer is that you build a tool that grabs global definitions from your files and outputs an eslintrc file with the
globals
predefined. Then, you can useextends
to import it.I was experiencing the same thing. I ended up just putting all the globals I was using inside the
globals
property within my.eslintrc.js
file. The only drag was that each one had to be named individually like such:Since each global is going to get a value of
true
anyway, would have been nice to be able to do it in an array like so: