no-use-before-define with global variable reassign
See original GitHub issueHi,
no-use-before-define
triggers an error for this kind of code:
var global = global || 'default';
The variable is defined in the globals
section of the eslint file. So in my opinion, it shouldn’t trigger the error.
What do you think?
My environment
- ESLint Version: 4.2.0
- Node Version: 8.9.1
- npm Version: 5.5.1
- default parser
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
no-use-before-define wrongly catches use of the global ...
I tried setting my rules as "no-use-before-define": ["error", { "variables": false }], but it didn't help. Adding window as a global also ...
Read more >The Ultimate Guide to ESLint Global Variables
Learn how to specify global variables in ESLint and see the results of 'readonly', 'writable', and 'off' values with these seven examples.
Read more >no-global-assign - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Disallow specific global variables (no-restricted-globals) - ESLint
This rule allows you to specify global variable names that you don't want to use in your application. Options. This rule takes a...
Read more >How to change the value of a global variable inside of a ...
Assign a value to a variable inside a function without declaring it using the “var” keyword. Example: In this example, we will define...
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 think this is actually the correct behavior. When it’s being redeclared,
global
is actually undefined because it is now referencing the variable that was just declared. When it’s reassigned, it references the previously declared variable in the outer/global scope. Check out this quick illustration I put together in JS Bin.Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.
Thanks for contributing to ESLint and we appreciate your understanding.