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 issue #4280

Closed
rohanorton opened this Issue Oct 28, 2015 · 12 comments

Comments

Projects
None yet
6 participants
@rohanorton
Copy link

rohanorton commented Oct 28, 2015

Hi, I'm new to eslint so there might be something that I'm missing, but I was expecting the rule "no-use-before-define" to pick up the following (contrived) syntax issue:

... ....
version v1.7.3
rule no-use-before-define
code see below
expected output error
actual no output

code:

var a = a

eslintrc:

{
    "extends": "eslint:recommended",
    "rules": {
         "no-use-before-define": 2
    }
}
@eslintbot

This comment has been minimized.

Copy link

eslintbot commented Oct 28, 2015

Thanks for the issue! If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

@ilyavolodin ilyavolodin added rule question and removed triage labels Oct 28, 2015

@ilyavolodin

This comment has been minimized.

Copy link
Member

ilyavolodin commented Oct 28, 2015

Hmm.. That's an interesting case. I think the code above is valid, and will be resolved as:

var a;
a = a;

I'm not 100% sure that it should be marked as an issue by this rule it feels more in line with no-self-compare. @eslint/eslint-team

@mysticatea

This comment has been minimized.

Copy link
Member

mysticatea commented Oct 28, 2015

let a = a; // this second `a` is in the TDZ.

This pattern is going to throw a runtime error, so I think there is a reason that this rule should report this pattern.

image

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Oct 28, 2015

That's a good point. Let's add it.

@nzakas nzakas added enhancement accepted and removed question labels Oct 28, 2015

OzgrCn added a commit to OzgrCn/eslint that referenced this issue Nov 11, 2015

OzgrCn added a commit to OzgrCn/eslint that referenced this issue Nov 12, 2015

@unional

This comment has been minimized.

Copy link

unional commented Dec 4, 2015

Another issue eslint 1.10.3:

var b = function() {
    a = 2;
};

var a = {
    x: b
};
@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 4, 2015

@unional what's the issue?

@unional

This comment has been minimized.

Copy link

unional commented Dec 4, 2015

Circular reference. Seems like function scope was not considered for this rule?

var b = function () {
  a = 2; // no-used-before-defined
};
var a = {
  x: b
};
@unional

This comment has been minimized.

Copy link

unional commented Dec 4, 2015

Here is a more liberate example:

var x = {
  a: {
    fn: function() {
        $.post('sofa', null, y.someCallback.bind(y)); // no-used-before-defined
        y.doSomething();  // no-used-before-defined
    }
  }
};

var y = new SomeComponent({
  b: [x]
  someCallback: () => {...},
  doSomething: () => {....}
});
@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Dec 5, 2015

This is working as expected. You need to disable the rule to allow those patterns. Remember, this rule is not about when something is safe to use, is about whether something is defined prior to its use in your source code.

@mysticatea

This comment has been minimized.

Copy link
Member

mysticatea commented Dec 5, 2015

I will work on this after #4597 is merged.

@mysticatea mysticatea self-assigned this Dec 5, 2015

mysticatea added a commit to mysticatea/eslint that referenced this issue Dec 9, 2015

mysticatea added a commit to mysticatea/eslint that referenced this issue Dec 9, 2015

@mysticatea

This comment has been minimized.

Copy link
Member

mysticatea commented Dec 9, 2015

I found several mistakes in ESLint by this enhancement 😄

mysticatea added a commit to mysticatea/eslint that referenced this issue Dec 9, 2015

mysticatea added a commit to mysticatea/eslint that referenced this issue Dec 9, 2015

@unional

This comment has been minimized.

Copy link

unional commented Dec 9, 2015

Nice! 👍

@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.
You can’t perform that action at this time.