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

Fix: block-scoped-var issues (fixes #2253, fixes #2747) #3126

Merged
merged 1 commit into from Jul 29, 2015

Conversation

mysticatea
Copy link
Member

I remade the rule with using escope.

@mysticatea
Copy link
Member Author

Oops, this implement is checking let/const also, so I will fix a bit tomorrow.

@olalonde
Copy link

👍

@mysticatea
Copy link
Member Author

OK, ready for review.

escope knows relations between variables and references, so the process for this rule became simple a bit.


I found this rule is not emulating behaviors no-redeclare and no-shadow.
I can add the behaviors easily, so I will send a PR later.

@mysticatea
Copy link
Member Author

This test case make this rule ignore a switch block, why is that?

@michaelficarra
Copy link
Member

Looks like a bug to me.

@nzakas
Copy link
Member

nzakas commented Jul 23, 2015

Why is that a bug? Switch statements create a block but case statements do not.

@michaelficarra
Copy link
Member

@nzakas There's a reference outside the switch.

@mysticatea
Copy link
Member Author

Ah.... I'm sorry, I got a behavior which is same as the test case, on Chrome.
I had not known this behavior, switch statement seems to not make a block. I will study later....

image

@michaelficarra
Copy link
Member

That also looks like a bug. Switch statements do make a block.

@mysticatea
Copy link
Member Author

I found: http://www.ecma-international.org/ecma-262/6.0/#sec-switch-statement-runtime-semantics-evaluation

Yeah, switch statement should make a block.
And firefox does correctly.

image

@mysticatea
Copy link
Member Author

I modified a bit for switch statement. The diff is here: mysticatea@cc1af6c

@nzakas
Copy link
Member

nzakas commented Jul 23, 2015

@michaelficarra ah, right you are. Thanks, completely missed that.

@mysticatea
Copy link
Member Author

I added tests for #2967.

And my misunderstanding was corrected in #3158, so I removed a logic which allows multiple blocks (e.g. if (true) { var a = 0; foo(a); } else { var a = 1; foo(a); }).
The logic of this rule became simple more.


I have a question.

  • Why does this rule report the same warnings as no-undef?

For example:

> echo "var a = b;" | node .\bin\eslint.js --stdin --no-eslintrc --rule "block-scoped-var:2, no-undef:2"

<text>
  1:10  error  "b" used outside of binding context  block-scoped-var
  1:10  error  "b" is not defined                   no-undef

✖ 2 problems (2 errors, 0 warnings)

I guess the warnings can be removed.
Specifically, I guess this function can be removed.

@mysticatea
Copy link
Member Author

Coverage decreased.... but block-scoped-var is 100%...

@gyandeeps
Copy link
Member

this is new. I have never seen coveralls to display here.

@mysticatea
Copy link
Member Author

When the tests of node v0.12 finished lastly, it seems to decrease coverage.
It's a mystery.

@mysticatea
Copy link
Member Author

I complement my question.

It needs to rewrite some tests in order to remove the duplicate warnings of no-undef.
I want to do it, but can I do it?

@nzakas
Copy link
Member

nzakas commented Jul 28, 2015

The function can be removed, but you should create a separate issue and pull request because it's a breaking change.

@mysticatea
Copy link
Member Author

OK, thank you.

So this PR is ready for review again.

@nzakas
Copy link
Member

nzakas commented Jul 29, 2015

LGTM

nzakas added a commit that referenced this pull request Jul 29, 2015
Fix: `block-scoped-var` issues (fixes #2253, fixes #2747)
@nzakas nzakas merged commit ee88d45 into eslint:master Jul 29, 2015
@mysticatea mysticatea deleted the block-scoped-var/scratch branch September 9, 2015 01:06
@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
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants