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

block-scoped-var fails on mutual recursion #2747

Closed
RReverser opened this issue Jun 11, 2015 · 10 comments
Closed

block-scoped-var fails on mutual recursion #2747

RReverser opened this issue Jun 11, 2015 · 10 comments
Assignees
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules

Comments

@RReverser
Copy link

Simplified my case to the following code:

function a(n) {
    return n > 0 ? b(n - 1) : "a";
}

function b(n) {
    return n > 0 ? a(n - 1) : "b";
}

And simplified eslintrc that allows to reproduce the issue:

{
  "ecmaFeatures": {
    "blockBindings": true,
    "modules": true
  },
  "rules": {
    "no-use-before-define": 2,
    "block-scoped-var": 2
  }
}

Without blockBindings enabled, only no-use-before-define fails.
Turning modules on/off doesn't affect the result, only adds use strict-related check in this case.

@gyandeeps gyandeeps added the triage An ESLint team member will look at this issue soon label Jun 11, 2015
@michaelficarra
Copy link
Member

@RReverser no-use-before-define doesn't allow the reference to appear anywhere before the definition in the program text. The more sane configuration, in my opinion, is the nofunc option, and it should fix your problem.

@RReverser
Copy link
Author

@michaelficarra Doesn't help for classes though (which was my original case).

I'd just wish the rule would be somewhat smarter and wouldn't warn when definition outside of the function/class boundary is referenced.

Also - what about block-scoped-var?

@michaelficarra
Copy link
Member

There's a proposal to fix that: #2750

What's the problem you're having with block-scoped-var?

@RReverser
Copy link
Author

See title - it also fails with given example & config.

@RReverser
Copy link
Author

There's a proposal to fix that: #2750

Haha, just in time :)

@nzakas
Copy link
Member

nzakas commented Jun 11, 2015

@RReverser can you provide the actual ESLint output as well as what you'd expect the output to be?

@RReverser
Copy link
Author

Sure, here it is:

x.js
  2:19  error  b was used before it was defined     no-use-before-define
  2:19  error  "b" used outside of binding context  block-scoped-var

✖ 2 problems (2 errors, 0 warnings)

I expected not to see any of these errors.

@nzakas
Copy link
Member

nzakas commented Jun 12, 2015

It looks like nofunc solves your problem here, and #2750 would take care of the rest of your concerns there. So let's focus this issue on block-scoped-var.

block-scoped-var probably would need to be rewritten in order to properly support hoisting, as this looks like a bug.

@nzakas nzakas changed the title "block-scoped-var" and "no-use-before-define" rules fail on mutual recursion "block-scoped-var fails on mutual recursion Jun 12, 2015
@nzakas nzakas added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Jun 12, 2015
@RReverser
Copy link
Author

Thanks!

@RReverser RReverser changed the title "block-scoped-var fails on mutual recursion block-scoped-var fails on mutual recursion Jun 12, 2015
@mysticatea
Copy link
Member

I will try to fix bugs around block-scoped-var rule.

mysticatea added a commit to mysticatea/eslint that referenced this issue Jul 22, 2015
mysticatea added a commit to mysticatea/eslint that referenced this issue Jul 23, 2015
mysticatea added a commit to mysticatea/eslint that referenced this issue Jul 23, 2015
@mysticatea mysticatea self-assigned this Jul 24, 2015
mysticatea added a commit to mysticatea/eslint that referenced this issue Jul 24, 2015
mysticatea added a commit to mysticatea/eslint that referenced this issue Jul 27, 2015
mysticatea added a commit to mysticatea/eslint that referenced this issue Jul 27, 2015
nzakas added a commit that referenced this issue Jul 29, 2015
Fix: `block-scoped-var` issues (fixes #2253, fixes #2747)
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 7, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

5 participants