tslint-immutable
Advanced tools
Comparing version 4.5.3 to 4.5.4
@@ -10,2 +10,8 @@ # Change Log | ||
## [v4.5.4] - 2018-04-17 | ||
* `no-object-mutation` rule, allow class member mutation in constructor [#79](https://github.com/jonaskello/tslint-immutable/pull/79). | ||
* `readonly-keyword` rule, check function params and return type [#80](https://github.com/jonaskello/tslint-immutable/pull/80) | ||
## [v4.5.3] - 2018-03-31 | ||
@@ -12,0 +18,0 @@ |
{ | ||
"name": "tslint-immutable", | ||
"version": "4.5.3", | ||
"version": "4.5.4", | ||
"description": "TSLint rules to disable mutation in TypeScript.", | ||
@@ -26,3 +26,3 @@ "main": "tslint-immutable.json", | ||
"nyc": "^11.2.1", | ||
"prettier": "^1.9.2", | ||
"prettier": "^1.12.1", | ||
"rimraf": "^2.6.2", | ||
@@ -39,3 +39,3 @@ "shelljs": "^0.7.5", | ||
"test": "tslint --test test/rules/**/*", | ||
"test:work": "yarn build && tslint --test test/rules/no-expression-statement/ignore-prefix-array/*", | ||
"test:work": "yarn build && tslint --test test/rules/readonly-keyword/ignore-local/*", | ||
"verify": "yarn build && yarn lint && yarn coverage", | ||
@@ -42,0 +42,0 @@ "coverage": "rimraf coverage .nyc_output && nyc yarn test", |
@@ -401,3 +401,3 @@ # tslint-immutable | ||
The quote above is from the [clojure docs](https://clojure.org/reference/transients). In general, it is more important to enforce immutability for state that is passed in and out of functions than for local state used for internal calculations within a function. For example in Redux, the state going in and out of reducers needs to be immutable while the reducer may be allowed to mutate local state in its calculations in order to achieve higher performance. This is what the `ignore-local` option enables. With this option enabled immutability will be enforced everywhere but in local state. Function parameters are not considered local state so they will still be checked. | ||
The quote above is from the [clojure docs](https://clojure.org/reference/transients). In general, it is more important to enforce immutability for state that is passed in and out of functions than for local state used for internal calculations within a function. For example in Redux, the state going in and out of reducers needs to be immutable while the reducer may be allowed to mutate local state in its calculations in order to achieve higher performance. This is what the `ignore-local` option enables. With this option enabled immutability will be enforced everywhere but in local state. Function parameters and return types are not considered local state so they will still be checked. | ||
@@ -404,0 +404,0 @@ Note that using this option can lead to more imperative code in functions so use with care! |
@@ -38,3 +38,4 @@ "use strict"; | ||
forbidObjPropOnLeftSideOf.some(function (k) { return k === binExp_1.operatorToken.kind; }) && | ||
!Ignore.isIgnoredPrefix(binExp_1.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
!Ignore.isIgnoredPrefix(binExp_1.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
!inConstructor(node)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
@@ -71,2 +72,12 @@ } | ||
} | ||
function inConstructor(nodeIn) { | ||
var node = nodeIn.parent; | ||
while (node) { | ||
if (node.kind === ts.SyntaxKind.Constructor) { | ||
return true; | ||
} | ||
node = node.parent; | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=noObjectMutationRule.js.map |
@@ -36,5 +36,18 @@ /** | ||
var myInvalidNodes = []; | ||
var cb = function (node) { | ||
// Check the node | ||
var _a = checkNode(node, ctx), invalidNodes = _a.invalidNodes, skipChildren = _a.skipChildren; | ||
if (invalidNodes) { | ||
myInvalidNodes = myInvalidNodes.concat.apply(myInvalidNodes, invalidNodes); | ||
} | ||
if (skipChildren) { | ||
return; | ||
} | ||
// Use return becuase performance hints docs say it optimizes the function using tail-call recursion | ||
return ts.forEachChild(node, cb); | ||
}; | ||
// Check either the parameter's explicit type if it has one, or itself for implict type | ||
for (var _i = 0, _a = functionNode.parameters.map(function (p) { return (p.type ? p.type : p); }); _i < _a.length; _i++) { | ||
var n = _a[_i]; | ||
// Check the parameter node itself | ||
var invalidCheckNodes = checkNode(n, ctx).invalidNodes; | ||
@@ -44,9 +57,15 @@ if (invalidCheckNodes) { | ||
} | ||
// Check all children for the paramter node | ||
ts.forEachChild(n, cb); | ||
} | ||
// Check the return type | ||
if (functionNode.type) { | ||
var invalidCheckNodes = checkNode(functionNode.type, ctx).invalidNodes; | ||
var nt = functionNode.type; | ||
if (nt) { | ||
// Check the return type node itself | ||
var invalidCheckNodes = checkNode(nt, ctx).invalidNodes; | ||
if (invalidCheckNodes) { | ||
myInvalidNodes = myInvalidNodes.concat.apply(myInvalidNodes, invalidCheckNodes); | ||
} | ||
// Check all children for the return type node | ||
ts.forEachChild(nt, cb); | ||
} | ||
@@ -53,0 +72,0 @@ return myInvalidNodes; |
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
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
491303
1640