`prefer-const` rule warns when "let" is needed for scoping
See original GitHub issueon eslint v2.7.0.
echo 'let foo; const bar = function bar() { return foo; }; foo = 3; console.log(bar());' | ./node_modules/.bin/eslint --stdin --rule 'prefer-const: 2' --no-eslintrc --parser-options=ecmaVersion:6
gives
<text>
1:54 error 'foo' is never reassigned, use 'const' instead prefer-const
✖ 1 problem (1 error, 0 warnings)
I’d like it not to warn here, since the let
is required to be able to refer to it without violating the no-use-before-define
rule. If it does warn, then must I disable one of the rules since they are in conflict here?
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (10 by maintainers)
Top Results From Across the Web
prefer-const - ESLint - Pluggable JavaScript Linter
This rule is aimed at flagging variables that are declared using let keyword, but never reassigned after the initial assignment. Examples of incorrect...
Read more >prefer-const - Rule
- If any variable in destructuring can be const, this rule warns for those variables. “all” - Only warns if all variables in...
Read more >Linter rules
Since state access is preferred via the widget field, passing data to State objects using custom constructor parameters should also be avoided and...
Read more >Const, let and var, which and when? | by Jhey Tompkins
Variables assigned with the var keyword have functional scope. This is somewhat intuitive. The variable isn't accessible outside of the function. They ...
Read more >JavaScript let const and var | Blog
You should prefer const when declaring variables in JavaScript (ES6+). If you are assigning a value to a variable, and you're not going...
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
@nzakas I think so.
@lukeapage Thank you for the explanation!
@nzakas As I mentioned at https://github.com/eslint/eslint/issues/5692#issuecomment-203690886, I think I can add an option to ignore variables that are read before its first assignment. I can work on this.