tslint-immutable
Advanced tools
Comparing version 4.5.4 to 4.6.0
@@ -10,7 +10,7 @@ # Change Log | ||
## [v4.5.4] - 2018-04-17 | ||
## [v4.6.0] - 2018-06-12 | ||
* `no-object-mutation` rule, allow class member mutation in constructor [#79](https://github.com/jonaskello/tslint-immutable/pull/79). | ||
### Added | ||
* `readonly-keyword` rule, check function params and return type [#80](https://github.com/jonaskello/tslint-immutable/pull/80) | ||
* New rule `no-array-mutation`. See [#74](https://github.com/jonaskello/tslint-immutable/issues/74). Thanks to [@RebeccaStevens](https://github.com/RebeccaStevens) for adding this rule! (See PR [#84](https://github.com/jonaskello/tslint-immutable/pull/84)) | ||
@@ -256,3 +256,4 @@ ## [v4.5.3] - 2018-03-31 | ||
[unreleased]: https://github.com/jonaskello/tslint-immutable/compare/v4.5.3...master | ||
[unreleased]: https://github.com/jonaskello/tslint-immutable/compare/v4.6.0...master | ||
[v4.6.0]: https://github.com/jonaskello/tslint-immutable/compare/v4.5.3...v4.6.0 | ||
[v4.5.3]: https://github.com/jonaskello/tslint-immutable/compare/v4.5.2...v4.5.3 | ||
@@ -259,0 +260,0 @@ [v4.5.2]: https://github.com/jonaskello/tslint-immutable/compare/v4.5.1...v4.5.2 |
{ | ||
"name": "tslint-immutable", | ||
"version": "4.5.4", | ||
"version": "4.6.0", | ||
"description": "TSLint rules to disable mutation in TypeScript.", | ||
@@ -38,3 +38,3 @@ "main": "tslint-immutable.json", | ||
"test": "tslint --test test/rules/**/*", | ||
"test:work": "yarn build && tslint --test test/rules/readonly-keyword/ignore-local/*", | ||
"test:work": "yarn build && tslint --test test/rules/no-array-mutation/**/*", | ||
"verify": "yarn build && yarn lint && yarn coverage", | ||
@@ -41,0 +41,0 @@ "coverage": "rimraf coverage .nyc_output && nyc yarn test", |
@@ -41,2 +41,3 @@ # tslint-immutable | ||
* [no-let](#no-let) | ||
* [no-array-mutation](#no-array-mutation) | ||
* [no-object-mutation](#no-object-mutation) | ||
@@ -228,2 +229,34 @@ * [no-method-signature](#no-method-signature) | ||
### no-array-mutation | ||
[![Type Info Required][type-info-badge]][type-info-url] | ||
This rule prohibits mutating an array via assignment to or deletion of their elements/properties. This rule enforces array immutability without the use of `ReadonlyArray<T>` (as apposed to [readonly-array](#readonly-array)). | ||
```typescript | ||
const x = [0, 1, 2]; | ||
x[0] = 4; // <- Mutating an array is not allowed. | ||
x.length = 1; // <- Mutating an array is not allowed. | ||
x.push(3); // <- Mutating an array is not allowed. | ||
``` | ||
#### Has Fixer | ||
No | ||
#### Options | ||
* [ignore-prefix](#using-the-ignore-prefix-option) | ||
#### Example config | ||
```javascript | ||
"no-array-mutation": true | ||
``` | ||
```javascript | ||
"no-array-mutation": [true, {"ignore-prefix": "mutable"}] | ||
``` | ||
### no-object-mutation | ||
@@ -545,1 +578,3 @@ | ||
[prettier-url]: https://github.com/prettier/prettier | ||
[type-info-badge]: https://img.shields.io/badge/type_info-requried-d51313.svg?style=flat | ||
[type-info-url]: https://palantir.github.io/tslint/usage/type-checking |
@@ -35,3 +35,3 @@ /** | ||
} | ||
// Use return becuase performance hints docs say it optimizes the function using tail-call recursion | ||
// Use return because performance hints docs say it optimizes the function using tail-call recursion | ||
return ts.forEachChild(node, cb); | ||
@@ -41,2 +41,16 @@ } | ||
exports.walk = walk; | ||
function walkTyped(ctx, checkTypedNode, checker, failureString) { | ||
return ts.forEachChild(ctx.sourceFile, cb); | ||
function cb(node) { | ||
// Check the node | ||
var _a = checkTypedNode(node, ctx, checker), invalidNodes = _a.invalidNodes, skipChildren = _a.skipChildren; | ||
reportInvalidNodes(invalidNodes, ctx, failureString); | ||
if (skipChildren) { | ||
return; | ||
} | ||
// Use return because performance hints docs say it optimizes the function using tail-call recursion | ||
return ts.forEachChild(node, cb); | ||
} | ||
} | ||
exports.walkTyped = walkTyped; | ||
function createCheckNodeRule(checkNode, failureString, | ||
@@ -63,2 +77,23 @@ // tslint:disable-next-line:no-any | ||
exports.createCheckNodeRule = createCheckNodeRule; | ||
function createCheckNodeTypedRule(checkTypedNode, failureString, | ||
// tslint:disable-next-line:no-any | ||
parseOptions | ||
// tslint:disable-next-line:no-any | ||
) { | ||
// tslint:disable-next-line:no-any | ||
if (parseOptions === void 0) { parseOptions = options_1.parseOptions; } | ||
return (function (_super) { | ||
__extends(Rule, _super); | ||
function Rule() { | ||
return _super !== null && _super.apply(this, arguments) || this; | ||
} | ||
Rule.prototype.applyWithProgram = function (sourceFile, program) { | ||
return this.applyWithFunction(sourceFile, function (ctx, checker) { | ||
return walkTyped(ctx, checkTypedNode, checker, failureString); | ||
}, parseOptions(this.ruleArguments), program.getTypeChecker()); | ||
}; | ||
return Rule; | ||
}(Lint.Rules.TypedRule)); | ||
} | ||
exports.createCheckNodeTypedRule = createCheckNodeTypedRule; | ||
function reportInvalidNodes(invalidNodes, ctx, failureString) { | ||
@@ -65,0 +100,0 @@ invalidNodes.forEach(function (invalidNode) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
578857
17502
86
1818
578