jscs-moment-immutability
v0.1.0
Published
JSCS rule to enforce immutability of moment.js objects
Maintainers
Readme
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-immutabilityIn .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) // validLicense
MIT
