-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Rule suggestion: prefer-const #523
Comments
This has come up before. See: #159 Right now, adding this rule would make any modules using |
@feross actually this rule only enforces using |
@LinusU Good to know! I still think we should wait a while before putting this into a release. The jury is still out on which ES6 language features are "good parts" and which are not. In 6 months to a year, we should consider doing a release of For example, with |
The effect on the ecosystem is moderate:
|
And that tips me over the line 👍 |
surprisingly |
I always thought |
Be aware that it doesn't work in the same way in 0.x though. See this table for more info: http://node.green/#const |
Looking forward to this! |
Here's a link to the Node.js LTS schedule. TL;DR:
Looking forward to seeing this rule land once the v0.* releases are no longer supported! |
Standard 8 doesn't support Node.js 0.10 or 0.12 though since ESLint decided to drop support for them... Maybe standard 9 could start introducing ES2015 and up rules now that most runtimes are compatible... |
@LinusU I'm not against the idea. |
I think this issue should be reopened for consideration in v9. Feel free to reclose. |
This rule is worth considering, but on top of all the other changes going into standard v9, I think this might be a bit too much in one version.
I'd also like to figure out a solution for all ES6+ rules at one time, instead of merging just this one right now. Moved it to standard v10 milestone. |
How do folks feel about this today? I know opinions have changed around |
Opinions around |
👍 Always use the most strict declaration first, starting with |
Thumbs up for this rule |
It's important. I recently switched my team over to Airbnb's ESLint config. This was a factor. |
Generally in favour now that block scoped @feross maybe when the new node LTS is |
I used to use The only thing That said, I get it if people still want to write |
const x = 2
x = 3 // ERROR
let x = 2
x = 3 // OK Yes, it doesn't help with const x = {}
x.y = 3 // hmph But, it isn't that bad. |
The main thing it guards against is: const foo = 3
const foo = 2 // ERROR But the same thing is picked up by standard: var foo = 3
var foo = 2 // ERROR My main point is that if we could argue for disallowing |
I don't understand, an example of what it does guard against is: const x = 2
x = 3 // ERROR What did I miss? Isn't that the point? Not double declaration. |
This rule just tells to use Nowadays in ES6 it's highly recommended to use only |
I've noticed that the milestone has changed -- does this mean it will be accepted in a future release? I'm not familiar with the development process on this repo but this issue would be a major factor in switching to eslint-config-standard. |
@christianbundy The plan is to merge this in standard 13. I just did a quick standard 12 release to get us on ESLint 5. |
PR is up standard/eslint-config-standard#133, I'm going to start sending pull requests to affected repos... |
Any update on this? |
This will ship in |
Referring to this rule. I think the current trend with ES6+ programming is to always use
const
as much as possible and to uselet
only when you intend on reassignment as it makes the intent of the code a bit clearer. So in a case like this:I think it may be preferable for the linter to tell you to use
const
instead oflet
asname
isn't ever reassigned. Any thoughts?The text was updated successfully, but these errors were encountered: