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 upnew rule: force a variable to be a constant if not used with assignment operator anywhere #396
Comments
This comment has been minimized.
This comment has been minimized.
Can you please elaborate on why this is? I don't mean to put down your suggestion, I'm just not familiar with why this is |
This comment has been minimized.
This comment has been minimized.
|
@watson http://ideasintosoftware.com/const-is-the-new-var/ |
This comment has been minimized.
This comment has been minimized.
|
NACK We're better off just enforcing |
This comment has been minimized.
This comment has been minimized.
|
agree with @dcousens' reasoning |
This comment has been minimized.
This comment has been minimized.
|
Personally I've yet to see a situation where a bug was introduced because someone used Also, this will make standard unusable when creating code that need to work with versions of Node or browsers that doesn't support |
This comment has been minimized.
This comment has been minimized.
Oh yeah, I definitely have haha |
This comment has been minimized.
This comment has been minimized.
True, that is why this rule should be released in a breaking version like 6.0.0 or 7.0.0 and support for node.js < 0.12 dropped from standard all together. Users on node.js 0.10 and less can still use 5.x.x Now that I think about it, it would be better if we had a rule which could check whether you're assigning into a var/let. If you're not, then it should be a style error of something like: That would cover much more potential issues. |
This comment has been minimized.
This comment has been minimized.
|
standard supports es5 code, and this would be a breaking change. perhaps this is better suited for something like |
This comment has been minimized.
This comment has been minimized.
|
@rstacruz I think standard is already supporting features outside of es5, so why start another "standard" now? |
capaj
changed the title
new rule: forbid var module = require('mymodule')
new rule: force a variable to be a constant if not used with assignment operator anywhere
Feb 2, 2016
This comment has been minimized.
This comment has been minimized.
|
because adding a rule like this will make standard unusable for any code that's targeting legacy node.js versions or browsers (without babel pre-compilation). |
This comment has been minimized.
This comment has been minimized.
|
@rstacruz yeah browsers would be a problem. Hmm ok then. |

capaj commentedJan 31, 2016
This rule should only be enforced for node.js > 0.10
There is no point in declaring a module as var in newer versions of node. Module should always be a const if assigned on the same line as the require statement is. If you want to require module "A" or module "B" into a single variable, it should be done like this:
if you would have do it like this:
That would be bad, because that way you are forcing node to load module "A" even if cond is true.
Thanks for you consideration and please let me know if I forgot some usecase where it might be valid to use
var.