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

[no-use-before-define] Not considering hoisting #221

Closed
Tarnadas opened this issue Feb 6, 2019 · 3 comments
Closed

[no-use-before-define] Not considering hoisting #221

Tarnadas opened this issue Feb 6, 2019 · 3 comments
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look wontfix This will not be worked on

Comments

@Tarnadas
Copy link

Tarnadas commented Feb 6, 2019

The no-use-before-define rule is not considering hoisting, therefore giving me errors, when declaring a function below its usage.

Repro

{
  "rules": {
    "@typescript-eslint/no-use-before-define": "error"
  }
}
fn(); // [eslint] 'fn' was used before it was defined. [@typescript-eslint/no-use-before-define]

function fn() {}

Expected Result

No linting error.

Actual Result

Linting error: [eslint] 'fn' was used before it was defined. [@typescript-eslint/no-use-before-define]

Versions

package version
@typescript-eslint/eslint-plugin 1.2.0
@typescript-eslint/parser 1.2.0
TypeScript 3.2.4
ESLint 5.13.0
node 8.15.0
@Tarnadas Tarnadas added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Feb 6, 2019
@platinumazure
Copy link
Contributor

Hi @Tarnadas, thanks for the issue.

I can't speak to the typescript-eslint version of the rule, but in core ESLint, this would be functioning as designed. The entire point of this rule is to flag all uses before definitions-- not to flag if a variable use would be undefined. It is more of a stylistic/readability rule. The no-undef rule (or typescript-eslint's equivalent) detects if the value is actually not defined (for example, if you used let fn = function() {}, which is not hoisted.

Maintainers-- please correct me if I've misstated anything.

@Tarnadas
Copy link
Author

Tarnadas commented Feb 6, 2019

Hey @platinumazure,
I just read through the ESLint page for this rule and it looks like you're right and this is WAI.

@Tarnadas Tarnadas closed this as completed Feb 6, 2019
@bradzacher bradzacher added the wontfix This will not be worked on label Feb 6, 2019
@aMarCruz
Copy link

@Tarnadas , use this:

{
  "rules": {
    "no-use-before-define": "off",
    "@typescript-eslint/no-use-before-define": ["error", {"functions": false, "typedefs": false}]
  }

Note there's a bug with typeof ignoring typedefs:false, but once fixed the rule must work like intended.

kaicataldo pushed a commit to kaicataldo/typescript-eslint that referenced this issue Aug 27, 2019
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

4 participants