Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upRule suggestion: prefer-const #523
Comments
This comment has been minimized.
This comment has been minimized.
|
This has come up before. See: #159 Right now, adding this rule would make any modules using |
feross
closed this
May 16, 2016
This comment has been minimized.
This comment has been minimized.
|
@feross actually this rule only enforces using |
This comment has been minimized.
This comment has been minimized.
|
@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 |
This comment has been minimized.
This comment has been minimized.
|
The effect on the ecosystem is moderate:
|
This comment has been minimized.
This comment has been minimized.
And that tips me over the line |
This comment has been minimized.
This comment has been minimized.
surprisingly |
This comment has been minimized.
This comment has been minimized.
I always thought |
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
Looking forward to this! |
This comment has been minimized.
This comment has been minimized.
mmwtsn
commented
Aug 16, 2016
|
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! |
This comment has been minimized.
This comment has been minimized.
|
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... |
This comment has been minimized.
This comment has been minimized.
|
@LinusU I'm not against the idea. |
This comment has been minimized.
This comment has been minimized.
I think this issue should be reopened for consideration in v9. Feel free to reclose. |
timoxley
reopened this
Sep 18, 2016
timoxley
added
the
enhancement
label
Sep 18, 2016
feross
added this to the
standard v9 milestone
Sep 18, 2016
This comment has been minimized.
This comment has been minimized.
|
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. |
feross
modified the milestones:
standard v10,
standard v9
Feb 9, 2017
feross
added
the
ecosystem impact
label
Feb 9, 2017
feross
modified the milestones:
standard v10,
standard v11
Mar 2, 2017
This comment has been minimized.
This comment has been minimized.
|
How do folks feel about this today? I know opinions have changed around |
This comment has been minimized.
This comment has been minimized.
Janpot
commented
Nov 7, 2017
|
Opinions around |
This comment has been minimized.
This comment has been minimized.
freewil
commented
Nov 7, 2017
|
|
This comment has been minimized.
This comment has been minimized.
|
Thumbs up for this rule |
This comment has been minimized.
This comment has been minimized.
mmwtsn
commented
Nov 8, 2017
It's important. I recently switched my team over to Airbnb's ESLint config. This was a factor. |
This comment has been minimized.
This comment has been minimized.
|
Generally in favour now that block scoped @feross maybe when the new node LTS is |
This comment has been minimized.
This comment has been minimized.
|
I used to use The only thing That said, I get it if people still want to write |
This comment has been minimized.
This comment has been minimized.
const x = 2
x = 3 // ERROR
let x = 2
x = 3 // OKYes, it doesn't help with const x = {}
x.y = 3 // hmphBut, it isn't that bad. |
This comment has been minimized.
This comment has been minimized.
|
The main thing it guards against is: const foo = 3
const foo = 2 // ERRORBut the same thing is picked up by standard: var foo = 3
var foo = 2 // ERRORMy main point is that if we could argue for disallowing |
This comment has been minimized.
This comment has been minimized.
|
I don't understand, an example of what it does guard against is: const x = 2
x = 3 // ERRORWhat did I miss? Isn't that the point? Not double declaration. |
This comment has been minimized.
This comment has been minimized.
|
This rule just tells to use Nowadays in ES6 it's highly recommended to use only |
feross
modified the milestones:
standard v12,
standard v13
Aug 28, 2018
This comment has been minimized.
This comment has been minimized.
christianbundy
commented
Aug 29, 2018
|
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. |
This comment has been minimized.
This comment has been minimized.
|
@christianbundy The plan is to merge this in standard 13. I just did a quick standard 12 release to get us on ESLint 5. |
This comment has been minimized.
This comment has been minimized.
|
PR is up standard/eslint-config-standard#133, I'm going to start sending pull requests to affected repos... |
This comment has been minimized.
This comment has been minimized.
DiegoRBaquero
commented
Jan 21, 2019
|
Any update on this? |
feross
added
the
accepted
label
Jul 5, 2019
This comment has been minimized.
This comment has been minimized.
|
This will ship in |
zaynv commentedMay 16, 2016
Referring to this rule. I think the current trend with ES6+ programming is to always use
constas much as possible and to useletonly 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
constinstead ofletasnameisn't ever reassigned. Any thoughts?