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.

Add "variables" option to `no-use-before-define` rule

See original GitHub issue
  • ESLint Version: 3.5.0

I want no-use-before-define to check for classes or functions that are used before they are defined. But I do not want to check for variables that are used before they are defined.

Right now there exist two options, which modify whether functions and classes are checked. For example, I can disable these two checks:

"no-use-before-define": [2, { "functions": false, "classes": false }]

But I cannot disable checking if variables are used before they are defined. I propose adding a “variables” option to address this:

"no-use-before-define": [2, { "variables": false }]

There is already a precedent for an option like this, in the “blocks” option to the padded-blocks rule. It’s used like this:

"padded-blocks": [2, { "blocks": "never", "switches": "never", "classes": "never" }]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:11
  • Comments:25 (18 by maintainers)

github_iconTop GitHub Comments

8reactions
ferosscommented, Sep 11, 2016

I’m not opposed, but I’d love to see a real-world case where this is a problem (especially if it’s something that “standard” recommends but cannot enforce, or wants to recommend but cannot, due to this limitation).

In standard, we would like to prevent clearly incorrect use-before-define cases like the following:

console.log(foo);
var foo = 5;

While still allowing cases that may be correct if the program executes in the right order:


function printFoo() {
     // Variable "foo" is not used before it is defined, even though it
     // appears in the source before foo is defined.
    console.log(foo);
}
var foo = 5;
printFoo();

There are just too many false positives for us when the latter example is disallowed.

5reactions
not-an-aardvarkcommented, Jan 20, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

no-use-before-define - ESLint - Pluggable JavaScript Linter
Rule Details. This rule will warn when it encounters a reference to an identifier that has not yet been declared. Examples of incorrect...
Read more >
ESLint no-use-before-define - javascript - Stack Overflow
This flag determines whether or not the rule checks variable declarations in upper scopes. ... eslint-disable-next-line no-use-before-define.
Read more >
typescript-eslint/no-use-before-define.md at main - GitHub
This rule extends the base eslint/no-use-before-define rule. It adds support for type , interface and enum declarations. Options. This rule adds the following ......
Read more >
no-use-before-define - TypeScript ESLint
Disallow the use of variables before they are defined. Examples​. This rule extends the base eslint/no-use-before-define rule. It adds support for ...
Read more >
How to fix Definition for rule typescript-eslint no-use-before ...
For my .eslintrc.js file I have the following rules set up: ... '@typescript-eslint/no-use-before-declare': ['error', { functions: true, ...
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