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: make no-unused-vars ignore for-in loops (fixes #2342) #6126

Merged
merged 1 commit into from Jul 4, 2016

Conversation

markelog
Copy link
Member

Also clean jsdocs for internal helpers

@eslintbot
Copy link

LGTM

@mention-bot
Copy link

By analyzing the blame information on this pull request, we identified @vitorbal, @nzakas and @mysticatea to be potential reviewers

@markelog
Copy link
Member Author

I assume phantom issue is known problem

@ilyavolodin
Copy link
Member

Yes, phantom issue has been screwing our builds for a while now...

@alberto
Copy link
Member

alberto commented May 10, 2016

@markelog I think the agreed-upon change was to ignore only for (x in y) return;, not any for..in/of loop

@markelog
Copy link
Member Author

@ilyavolodin

Is there ticket about this? Downloading phantom binary is known bottleneck and that's syntactic environment, since alternative would be to actually make ci run tests in real browsers, i would propose to do that instead.

@alberto

mm, i was under impression for (x in y) return; example was to illustrate the point.

Otherwise we would need to inspect body of the loop, which would introduce it seems unnecessary complexity. I'm not sure what kind of disadvantages we would try to avoid by doing that, i could see though breaking a use-case of object getters on which that loop could be iterated upon if we would be specific with return keyword.

@nzakas
Copy link
Member

nzakas commented May 15, 2016

Agree with @alberto - the resolution of #2342 is to explicitly exempt for-in when it's body is just return (see #2342 (comment)). We definitely don't want to exempt all loops.

@markelog can you update this PR accordingly? Also, can you update the commit message to begin with "Update" instead of "Fix"? (The issue is labeled as an enhancement, so we use " Update" for that.)

@markelog
Copy link
Member Author

ok-ok, so we targeting only loops with one statement which should be return, correct?

@nzakas
Copy link
Member

nzakas commented May 17, 2016

Only for-in loops with return, yes.

@markelog
Copy link
Member Author

markelog commented May 17, 2016

Sorry to keep asking about this, but i want to be clear about it - only one statement with return is not violation? Like this -

for (var key in obj) {
 i++;
 return false;
}

Is violation or not? Also your last comment was #2342 (comment) yeah, but then there was #2342 (comment)

which includes

and same pattern for for..of

Those statements confuse a bit

@nzakas
Copy link
Member

nzakas commented May 18, 2016

Just for-in and only when the loop body just has a return statement. So your example would still be flagged as a problem.

@markelog
Copy link
Member Author

ok, thank you for clarification

@platinumazure
Copy link
Member

@markelog @nzakas Hard to tell if this is ready for merge- if not, can we put "do not merge" on here?

@markelog markelog added the do not merge This pull request should not be merged yet label May 30, 2016
@markelog
Copy link
Member Author

Done, thank you

@eslintbot
Copy link

LGTM

@ilyavolodin ilyavolodin removed the do not merge This pull request should not be merged yet label Jun 4, 2016
@eslintbot
Copy link

Thanks for the pull request, @markelog! I took a look to make sure it's ready for merging and found some changes are needed:

  • The commit summary must be 72 characters or shorter. Please check out our guide for how to properly format your commit summary and update it on this pull request.

Can you please update the pull request to address these?

(More information can be found in our pull request guide.)

@eslintbot
Copy link

LGTM

@@ -99,7 +99,6 @@ module.exports = {
* Determines if a given variable is being exported from a module.
* @param {Variable} variable - EScope variable object.
* @returns {boolean} True if the variable is exported, false if not.
* @private
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove @private everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a lot of rules that do use this keyword and there is a lot of rules that don't, some of the helpers of this particular rule also do and do not.

So it seems we have to choose with or without it, since in my view it is already obvious they are private, i choice the latter.

Trying to make it consistent, what way seems better to you?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what should i do?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to have @private, as it will prevent JSDoc from generating docs for them if we ever get that working again. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok-ok, also, i think it would the right move to do this everywhere else, how about creating a ticket about this?

@markelog markelog mentioned this pull request Jun 8, 2016
4 tasks
@markelog
Copy link
Member Author

markelog commented Jun 8, 2016

Will make a fix for other remarks after clarification, so it could be done in one move

@markelog markelog added the do not merge This pull request should not be merged yet label Jun 8, 2016
@markelog
Copy link
Member Author

Done, sorry for the delay

@ilyavolodin
Copy link
Member

@markelog It looks like there's a still merge conflict in this PR. Could you rebase please?

@eslintbot
Copy link

LGTM

@markelog
Copy link
Member Author

Donzo, there is a lot of interesting code in there.

target = target.body;
}

return target.type === "ReturnStatement";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this may cause null dereference error at empty block body.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, could you elaborate with some code?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(function(obj) { var name; for ( name in obj ) { } })({});

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed thanks, btw, was about to cc you here and there you are :)

@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member

I'd like to see a test for the following code:

for (const key in obj) return true;

@markelog
Copy link
Member Author

You mean for const? I guess it also makes sense to add similar test for let too?

@mysticatea
Copy link
Member

I'm seeing that this is checking whether the parent node of an identifier is a ForInStatement or not.
My example is that the parent node is a VariableDeclarator.

@markelog markelog changed the title Fix: make no-unused-vars ignore for...(in | of) loops (fixes #2342) Fix: make no-unused-vars ignore for-in loops (fixes #2342) Jul 1, 2016
Applied only for `for-in` loops with only one `return` statement.

Also clean jsdocs for internal helpers
@eslintbot
Copy link

LGTM

@markelog
Copy link
Member Author

markelog commented Jul 1, 2016

@mysticatea done

@mysticatea
Copy link
Member

Thank you very much!
Looks good to me.

@markelog
Copy link
Member Author

markelog commented Jul 4, 2016

Okay, so it seems i have addressed all concerns, so if no one objects, i will land this today

@markelog markelog merged commit f86f860 into eslint:master Jul 4, 2016
@nzakas
Copy link
Member

nzakas commented Jul 4, 2016

@markelog why was the commit message changed from "Fix" to "Update" here?

Note that as soon as it becomes "Update", a TSC member needs to merge the code (because it causes a minor semver bump).

ilyavolodin pushed a commit that referenced this pull request Jul 4, 2016
Applied only for `for-in` loops with only one `return` statement.

Also clean jsdocs for internal helpers
nzakas pushed a commit that referenced this pull request Jul 4, 2016
Applied only for `for-in` loops with only one `return` statement.

Also clean jsdocs for internal helpers
nzakas pushed a commit that referenced this pull request Jul 4, 2016
Applied only for `for-in` loops with only one `return` statement.

Also clean jsdocs for internal helpers
@nzakas
Copy link
Member

nzakas commented Jul 4, 2016

FYI: We changed the commit message back to "Fix" as it seems like that is what is appropriate given the semver policy.

@alberto
Copy link
Member

alberto commented Jul 4, 2016

Thanks @markelog for keeping up!

@markelog
Copy link
Member Author

markelog commented Jul 8, 2016

@nzakas Probably is, on #2342 it has label enhancement that is why i change commit tag, should we change label on that issue?

Note that as soon as it becomes "Update", a TSC member needs to merge the code (because it causes a minor semver bump).

Ok-ok, i understand correlation now

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 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 6, 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

9 participants