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

no-use-before-define doesn't check ArrowFunctionExpressions #1895

Closed
btmills opened this Issue Feb 27, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@btmills
Member

btmills commented Feb 27, 2015

// test.js
(function() {
    console.log(foo);
})();

(() => {
    console.log(foo);
})();

var foo = 42;
// config.json
{
    "rules": {
        "no-use-before-define": 2
    },
    "ecmaFeatures": {
        "arrowFunctions": true
    }
}
$ eslint --reset --no-eslintrc -c config.json test.js

test.js
  3:16  error  foo was used before it was defined  no-use-before-define

✖ 1 problem (1 error, 0 warnings)

foo is used before it is defined on lines 3 and 7 of test.js, but only the former case is caught because no-use-before-define doesn't check ArrowFunctionExpressions.

@btmills

This comment has been minimized.

Show comment
Hide comment
@btmills

btmills Feb 27, 2015

Member

Looks like this might be an escope issue?

Member

btmills commented Feb 27, 2015

Looks like this might be an escope issue?

@nzakas

This comment has been minimized.

Show comment
Hide comment
@nzakas

nzakas Feb 27, 2015

Member

I'm not sure, it's only escope is we're using getScope() to figure this out.

Member

nzakas commented Feb 27, 2015

I'm not sure, it's only escope is we're using getScope() to figure this out.

@btmills

This comment has been minimized.

Show comment
Hide comment
@btmills

btmills Feb 28, 2015

Member

Aha! I guessed that because scope.references was empty for arrow function expressions. We are using getScope(), but it turns out it's the implementation of getScope() that doesn't look for the arrow function expression. Working on this; PR coming soon I hope.

Member

btmills commented Feb 28, 2015

Aha! I guessed that because scope.references was empty for arrow function expressions. We are using getScope(), but it turns out it's the implementation of getScope() that doesn't look for the arrow function expression. Working on this; PR coming soon I hope.

@btmills btmills closed this in c93e4a9 Feb 28, 2015

nzakas added a commit that referenced this issue Feb 28, 2015

Merge pull request #1899 from eslint/issue1895
Fix: getScope and no-use-before-define for arrow functions (fixes #1895)

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.