question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

no-use-before-define with global variable reassign

See original GitHub issue

Hi, 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:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, Aug 28, 2018

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.

0reactions
eslint-deprecated[bot]commented, Dec 11, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found