eslint-plugin-keywords-immutable
Version:
ESLint plugin to disable targeting keyword mutation in JavaScript.
84 lines (63 loc) • 1.66 kB
Markdown
Immutable objects with promised keywords do not allow mutation.
`npm i --save-dev eslint-plugin-keywords-immutable`
Add the following to your `.eslintrc`
Can customize keywords, including regular expressions.
```
plugins: [
"keywords-immutable"
],
rules: {
"keywords-immutable/no-mutation": [2, ['window', 'event', 'global', /^FINAL_/]]
}
```
The second option is the check depth option. If true, depths greater than 2 are also considered unchangeable. The default value is false.
```
plugins: [
"keywords-immutable"
],
rules: {
"keywords-immutable/no-mutation": [2, ['window', 'event', 'global', /^FINAL_/], true]
}
```
When used without options, the default option is ['event'].
```
plugins: [
"keywords-immutable"
],
rules: {
"keywords-immutable/no-mutation": 2
}
```
* Not allowed because it is part of a keyword.
```js
// "keywords-immutable/no-mutation": [2, ['point', /^FINAL/]]
FINAL_POINT.x = 3;
point.x = 3;
pointParent.point.x = 3;
[] = [1, 3];
({ a: point.s } = { a: 3 });
Object.assign(point, { v: 3 });
// "keywords-immutable/no-mutation": [2, ['point', /^FINAL/], true]
point.x.y = 3;
pointParent.point.x.y = 3;
```
* Allowed because it is not part of a keyword.
```js
// "keywords-immutable/no-mutation": [2, ['point', /^FINAL/]]
FINE_POINT.x = 3;
obj.a = 3;
objParent.obj.x = 3;
[] = [1, 3];
({ a: obj.s } = { a: 3 });
```
Please submit a PR.