tslint-immutable
This repo contains a TSLint version of the eslint-plugin-immutable
.
This goal of these TSLint rules are to disable all mutation in TypeScript. Please see the eslint-plugin-immutable version for the rationale beind this.
Installing
npm install tslint-immutable --save-dev
TSLint Rules
There following rules are availavle:
no-let
See eslint version for documentation.
no-this
See eslint version for documentation.
no-mutation
See eslint version for documentation.
no-expression-statement
When you call a function and don’t use it’s return value, chances are high that it is being called for its side effect. e.g.
array.push(1)
alert('Hello world!')
This rule checks that the value of an expression is assigned to a variable. However it will still be possible to perform mutations, eg. this rule will not catch these expressions:
const namesWithBar = names.concat([' bar '])
return namesWithBar
const newSize = names.push('baz')
const newObject = Object.assign(oldObject, { foo: 'bar' })
Supplementary TSLint Rules to Enable
The rules in this package alone can not eliminate mutation in your TypeScript programs. To go the distance I suggest you also enable the following built-in TSLint rules:
- no-var-keyword (self-explanatory)
Sample Configuration File
Here's a sample TSLint configuration file (tslint.json) that activates all the recommended rules:
{
"rulesDirectory": "path/to/tslint-immutable/rules",
"rules": {
"no-let": true,
"no-this": true,
"no-mutation": true,
"no-expression-statement": true,
"no-var-keyword": true
}
}