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: no-unused-vars false positive in loop (fixes #6646) #6649

Merged
merged 6 commits into from
Jul 15, 2016
Merged

Conversation

mysticatea
Copy link
Member

Fixes #6646.

no-unused-vars comes to mark (as used) self-modification inside of a loop because the reference inside of a loop can be used in the next iteration.

@mention-bot
Copy link

@mysticatea, thanks for your PR! By analyzing the annotation information on this pull request, we identified @vitorbal, @nzakas and @markelog to be potential reviewers

@eslintbot
Copy link

LGTM

* Checks whether a given node is inside of a loop or not.
*
* @param {ASTNode} node - A node to check.
* @returns {boolean} `true` if the node is inside of a loop.
Copy link
Member

Choose a reason for hiding this comment

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

@private is missing

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, thank you!

@eslintbot
Copy link

LGTM

@@ -97,6 +97,8 @@ module.exports = {
//--------------------------------------------------------------------------

var STATEMENT_TYPE = /(?:Statement|Declaration)$/;
var LOOP_TYPE = /^(?:DoWhile|For|ForIn|ForOf|While)Statement$/;
Copy link
Member

Choose a reason for hiding this comment

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

Seems this kinda thing is needed among the rules, like -

"IfStatement", "WhileStatement", "ForStatement", "ForInStatement", "ForOfStatement", "DoWhileStatement", "ClassDeclaration"

var LOOP_PATTERN = /^(?:DoWhile|For|While)Statement$/;

and so on

Can we move it in one place?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right.

maybe isLoop(node) and isFunction(node) of lib/ast-utils.js.

Copy link
Member

Choose a reason for hiding this comment

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

Could work, but probably more appropriate to do this in the separate pr

@eslintbot
Copy link

LGTM

* @returns {boolean} `true` if the node is a loop node.
*/
isLoopNode: function(node) {
return Boolean(node && anyLoopPattern.test(node.type));
Copy link
Member

Choose a reason for hiding this comment

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

Probably worth to add tests for such methods?

Copy link
Member Author

Choose a reason for hiding this comment

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

oops, I will add tomorrow (JST)

2016年7月11日(月) 22:05 Oleg Gaidarenko notifications@github.com:

In lib/ast-utils.js
#6649 (comment):

  • /**
  • \* Checks whether a given node is a loop node or not.
    
  • \* The following types are loop nodes:
    
  • *
    
  • \* - DoWhileStatement
    
  • \* - ForInStatement
    
  • \* - ForOfStatement
    
  • \* - ForStatement
    
  • \* - WhileStatement
    
  • *
    
  • \* @param {ASTNode|null} node - A node to check.
    
  • \* @returns {boolean} `true` if the node is a loop node.
    
  • */
    
  • isLoopNode: function(node) {
  •    return Boolean(node && anyLoopPattern.test(node.type));
    

Probably worth to add tests for such methods?


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
https://github.com/eslint/eslint/pull/6649/files/534b4a63da91a7ee7bb3bced229e269c1a447558..9df950521809d8b4aa8042852fc10edee155554b#r70252919,
or mute the thread
https://github.com/notifications/unsubscribe/AB2Rz2_t-vQyN44LhCdM7boewfLk09C7ks5qUj-2gaJpZM4JJSFj
.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added it.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just isLoop? (Not sure "node" is necessary)

@eslintbot
Copy link

LGTM

* @param {ASTNode|null} node - A node to check.
* @returns {boolean} `true` if the node is a function node.
*/
isFunctionNode: function(node) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just isFunction?

@eslintbot
Copy link

LGTM

@mysticatea
Copy link
Member Author

I renamed those 📝 :

  • isFunctionNodeisFunction
  • isLoopNodeisLoop

@markelog
Copy link
Member

I would do this in two steps - one for #6646 and other for ast-utils module, but if this is acceptable practise then LGTM

@ilyavolodin
Copy link
Member

@markelog In this case, since those function are used in this rule, I think it's perfectly fine to do both in a single PR.

LGTM.

@ilyavolodin ilyavolodin merged commit dfc20e9 into master Jul 15, 2016
@mysticatea mysticatea deleted the issue6646 branch July 15, 2016 15:48
@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

7 participants