prefer-destructuring false-positive if already declared in upper scope
See original GitHub issueTell us about your environment
- ESLint Version: 4.13.1
- Node Version: 8.9.1
- npm Version: 5.6.0
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
airbnb-styleguide
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
const foo = { bar: 1 };
let bar;
try {
// throws an error here
bar = foo.bar
} catch(e) {
}
// rule setting, as of the airbnb styleguide
'prefer-destructuring': ['error', {
VariableDeclarator: {
array: false,
object: true,
},
AssignmentExpression: {
array: true,
object: true,
},
}, {
enforceForRenamedProperties: false,
}],
What did you expect to happen?
I expect that the destructing error won’t show up. As the variable bar
is already declared in an upper scope not in the same.
What actually happened? Please include the actual, raw output from ESLint. The rule suggested to prefer destructing although it won’t work with destructing here, as I have to declare a new variable.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
'err' is already declared in the upper scope - Stack Overflow
My code is giving no errors just i have to meet the eslint as it is giving the error 'err' is already declared...
Read more >@teppeis/tslint-eslint-rules | Yarn - Package Manager
You want to code in TypeScript but miss all the rules available in ESLint? Now you can combine both worlds by using this...
Read more >Code Issues - Embold Help Center
BigIntegerInstantiation, Don't create instances of already existing BigInteger ... Fields should be declared at the top of the class, before any method ...
Read more >Eslint Already Declared In The Upper Scope | Steel King
Declare all the upper scopes are in. They return the scope in this declared later on your business, a function scopes are already...
Read more >demo-outil-edition - node_modules - eslint - CHANGELOG.md
8f86cca Upgrade: eslint-scope@^5.0.0 (#12011) (Kevin Partington) ... a015234 Fix: prefer-destructuring false positive on "super" (fixes ...
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 FreeTop 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
Top GitHub Comments
You can destructure without a declaration:
Unfortunately, you need parentheses for object destructuring due to the language grammar, but otherwise destructuring does work without a declaration.
I also want to point out that I’m aware of
AssignmentExpression
andVariableDeclarator
options. What I meant with “another option” is something like this:should not warn for cases like these
should warn for cases like these
because above can be potentially refactored to use destructuring.
Not a great example but I hope you understand. And probably I’m asking for a lot! 😃