Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining a variable to itself that is undefined raises no errors #615

Closed
pinn3 opened this issue Sep 7, 2016 · 5 comments

Comments

@pinn3
Copy link

commented Sep 7, 2016

Example:

var variable1 = variable1
let variable2 = variable2
const variable3 = variable3
@not-an-aardvark

This comment has been minimized.

Copy link

commented Sep 7, 2016

Relevant ESLint rule: no-use-before-define

@feross

This comment has been minimized.

Copy link
Member

commented Sep 10, 2016

Good catch. We could try enabling the following rule:

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

Even with the most lax options to no-use-before-define, there are still way too many false positives (and this rule is not automatically fixable with standard --fix)

1..422
# tests 422
# pass  402
# fail  20

If eslint adds an option that doesn't flag the following as invalid, then we can do this. Otherwise, it's just too disruptive to valid code.

function myFn () {
  // Variable "a" is not necessarily used before it is defined
  console.log(a)
}
var a = 5
@feross

This comment has been minimized.

Copy link
Member

commented Sep 10, 2016

I opened an issue on eslint to add the necessary option: eslint/eslint#7111

@feross

This comment has been minimized.

Copy link
Member

commented Feb 9, 2017

Duplicate of #636

@feross feross closed this Feb 9, 2017

@feross

This comment has been minimized.

Copy link
Member

commented Feb 9, 2017

(Btw, this will be part of standard v9.)

feross added a commit to standard/eslint-config-standard that referenced this issue Feb 9, 2017

Disallow Incorrect Early Use (no-use-before-define)
Using hoisting is still allowed, but it is prevented when clearly
incorrect, e.g.:

console.log(foo)
var foo = 1

var variable1 = variable1

Fixes: standard/standard#615
Fixes: standard/standard#636

feross added a commit to standard/eslint-config-standard that referenced this issue Feb 9, 2017

Disallow Incorrect Early Use (no-use-before-define)
Using hoisting is still allowed, but it is prevented when clearly
incorrect, e.g.:

console.log(foo)
var foo = 1

var variable1 = variable1

Fixes: standard/standard#615
Fixes: standard/standard#636

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
3 participants
You can’t perform that action at this time.