Re:JavaScript variables: var and let and const
by _bxg1 on Friday March 06, 2020 @03:38PM
(#22507101)
And in TypeScript you can at least pair it with Readonly<...>, though that unfortunately still isn't recursive
Re:JavaScript variables: var and let and const
by ht85 on Friday March 06, 2020 @04:36PM
(#22507557)
Nice plugin to make sure you never mutate: https://github.com/jonaskello/tslint-immutable/tree/master/t...
You can add a rule based on the name of the variable to allow mutating (e.g. naming it `mutableSomething`)
Re:JavaScript variables: var and let and const
by _bxg1 on Friday March 06, 2020 @05:10PM
(#22507812)
Interesting, but not really tractable if you have to manually add every single variable to the rules config.
Re:JavaScript variables: var and let and const
by chaorace on Friday March 06, 2020 @06:04PM
(#22508205)
The plugin allows pattern-based exceptions.
For example, if your rule excluded variables with a "mutable" prefix, you could name your variable mutableSomething and it will be automatically ignored by the linter
We should use `const` to communicate that we don't intend to reassign or mutate the variable. And we should do that by default unless there's a compelling reason to do otherwise.
I know it can't be fully enforced, because JavaScript is designed for mutability of objects by default. But it is an implementation style that is almost always achievable in plain ES6 without too much trouble, and it makes more reliable software that's easier to reason about.