-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Conversation
@mysticatea, thanks for your PR! By analyzing the annotation information on this pull request, we identified @vitorbal, @nzakas and @markelog to be potential reviewers |
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@private
is missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, thank you!
LGTM |
@@ -97,6 +97,8 @@ module.exports = { | |||
//-------------------------------------------------------------------------- | |||
|
|||
var STATEMENT_TYPE = /(?:Statement|Declaration)$/; | |||
var LOOP_TYPE = /^(?:DoWhile|For|ForIn|ForOf|While)Statement$/; |
There was a problem hiding this comment.
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 -
Line 616 in b837c92
"IfStatement", "WhileStatement", "ForStatement", "ForInStatement", "ForOfStatement", "DoWhileStatement", "ClassDeclaration" |
var LOOP_PATTERN = /^(?:DoWhile|For|While)Statement$/; |
and so on
Can we move it in one place?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
LGTM |
* @returns {boolean} `true` if the node is a loop node. | ||
*/ | ||
isLoopNode: function(node) { | ||
return Boolean(node && anyLoopPattern.test(node.type)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added it.
There was a problem hiding this comment.
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)
LGTM |
* @param {ASTNode|null} node - A node to check. | ||
* @returns {boolean} `true` if the node is a function node. | ||
*/ | ||
isFunctionNode: function(node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just isFunction
?
LGTM |
I renamed those 📝 :
|
I would do this in two steps - one for #6646 and other for |
@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. |
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.