Allow variable declarations with guard-for-in
See original GitHub issueWhat rule do you want to change? guard-for-in
Does this change cause the rule to produce more or fewer warnings? Fewer.
How will the change be implemented? (New option, new default behavior, etc.)? New default behavior.
Please provide some example code that this change will affect:
for (key in foo) {
const val = checkSomething(key)
if (val > 0) {
doSomething(key, val);
}
}
What does the rule currently do for this code? Warns.
What will the rule do after it’s changed? Not warn.
The point is that the condition(s) that you check to filter properties may involve values that are also needed inside the loop body. It would be good to allow this without having to disable or work around the warning. I.e. allow let
and const
statements before the if
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Rules - ESLint - Pluggable JavaScript Linter
Disallow variable or `function` declarations in nested blocks ... guard-for-in ... Enforce a maximum number of statements allowed in function blocks.
Read more >How to fix Definition for rule typescript-eslint no-use-before ...
I am new to eslint and I cannot figure out how to solve this issue. The beginning of my imports is always underlined...
Read more >Function throwing eslint.org guard-for-in error - Stack Overflow
Using this for loop to build a querystring with no issues. for (const key in parameters) { const value = parameters[key]; qs += ......
Read more >List of available rules - ESLint - Pluggable JavaScript linter
disallow variable or function declarations in nested blocks ... enforce a maximum cyclomatic complexity allowed in a program ... guard-for-in.
Read more >Integration with ESLint JavaScript Linter - Codacy | Blog
Enable them on your projects and share your feedback with us! ... Variables. These rules have to do with variable declarations.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the suggestion.
I’m not sure about this change; I think the point of the
guard-for-in
rule is to enforce the following pattern:Feel free to make a new issue with a proposal!