eslint-plugin-keywords-immutable

1.3.12 • Public • Published

eslint-plugin-keywords-immutable

Immutable objects with promised keywords do not allow mutation.

Getting started

Installation

npm i --save-dev eslint-plugin-keywords-immutable

Usage

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_/]]
  }

Second Option

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]
  }

By default, "event" are disallowed to be mutated.

When used without options, the default option is ['event'].

  plugins: [
    "keywords-immutable"
  ],
  rules: {
    "keywords-immutable/no-mutation": 2
  }

Example

invalid

  • Not allowed because it is part of a keyword.
// "keywords-immutable/no-mutation": [2, ['point', /^FINAL/]]
FINAL_POINT.x = 3;
point.x = 3;
pointParent.point.x = 3;
[point.x, point.y] = [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;

valid

  • Allowed because it is not part of a keyword.
// "keywords-immutable/no-mutation": [2, ['point', /^FINAL/]]
FINE_POINT.x = 3;
obj.a = 3;
objParent.obj.x = 3;
[obj.x, obj.b] = [1, 3];
({ a: obj.s } = { a: 3 });

Contributing

Please submit a PR.

Package Sidebar

Install

npm i eslint-plugin-keywords-immutable

Weekly Downloads

0

Version

1.3.12

License

MIT

Unpacked Size

9.73 kB

Total Files

5

Last publish

Collaborators

  • kimjinwoo