The npm community forum has been discontinued.
To discuss usage of npm, visit the GitHub Support Community.
Replace var with let/const
Since the code base is using
const/let already, it is a good time to start replacing
const/let. Here is the list:
- lib/fetch-package-metadata.md https://github.com/npm/cli/pull/120
- lib/repo.js https://github.com/npm/cli/pull/119
We don’t generally accept PRs for stuff like this because they’re relatively low value for the potential impact (for example, merge conflicts with existing PRs, or accidentally making something
const when it was modified sometime later).
That said, @iarna and I think we would accept changes like this if it were done one PR per file, and any files modified also happen to have good coverage. We don’t think consistency is high value enough to warrant this kind of impact in one fell swoop or for higher-risk files.
Thank you for your comment.
That is right, doing these all by one PR is not acceptable. I remember the moment when we integrated a lint tool into npm for the first time…
From my point of view, I believe consistency has a small, good thing in term of communication. Using one way helps new contributors to get an idea of how to write a patch and they can focus on value. Apparently, it may be acceptable for two of you if the patches have been kept very small according to your comment. Then I keep working on it little by little, and hope the other people will also take some.
I don’t mind helping out with this (and it also inflates my 24 Pull Requests score ).
@watilde for the consistency, do you think objects/arrays that should be modified but not replaced be
Yes, I think so.
let/const is to prevent reassignment, and using
Object.freeze would take a little bit more time to review if it’s correct at this moment.
I know about the reassignment, but I’ve heard people saying that using
const for objects that should be modified is communicating the wrong message. Whether that’s the case or not, I just wanted to make sure we were on the same page about that.
For my two cents, “use const unless your code requires a let” is the most widely accepted rule. “const” does not message any kind of freezing of an array or object, not to me or the folks I code with it doesn’t at least.