0.1.0 • Published 8 years ago
jscs-moment-immutability v0.1.0
jscs-moment-immutability
JSCS rule to enforce immutability of moment.js objects
Description
Moment.js objects are not immutable, and it is easy to forget this when performing operations with them, leading to subtle bugs. This JSCS rule checks that mutation operations on moment objects are "safe" by enforcing a clone or a new object construction before the mutation.
Usage
$ npm install --save-dev jscs-moment-immutability
In .jscsrc:
{
...
"additionalRules": ["jscs-moment-immutability"],
"momentImmutability": true,
...
}
Rules
m.year(2016) // invalid
m.clone().year(2016) // valid
moment(m).year(2016) // valid
m.add(1, 'day') // invalid
m.clone().add(1, 'day') // valid
moment(m).add(1, 'day') // valid
m.set('year', 2016) // invalid
m.clone().set('year', 2016) // valid
moment(m).set('year', 2016) // valid
License
MIT
0.1.0
8 years ago