tslint-immutable
Advanced tools
Comparing version 4.9.1 to 5.0.0
@@ -10,2 +10,8 @@ # Change Log | ||
## [v5.0.0] - 2018-11-24 | ||
### Changed | ||
* Internal refactoring to use the [tsutils](https://www.npmjs.com/package/tsutils) library, see PR [100](https://github.com/jonaskello/tslint-immutable/pull/100). This cleans up a lot of code and makes it easier to do further development. Becasue the tsutils library requires typescript version >=2.8 and node >=6 this refactoring required a major version bump. Big thanks to [RebeccaStevens](https://github.com/RebeccaStevens) for the amazing work on this refactoring :-). | ||
## [v4.9.1] - 2018-11-04 | ||
@@ -292,3 +298,4 @@ | ||
[unreleased]: https://github.com/jonaskello/tslint-immutable/compare/v4.9.1...master | ||
[unreleased]: https://github.com/jonaskello/tslint-immutable/compare/v5.0.0...master | ||
[v5.0.0]: https://github.com/jonaskello/tslint-immutable/compare/v4.9.1...v5.0.0 | ||
[v4.9.1]: https://github.com/jonaskello/tslint-immutable/compare/v4.9.0...v4.9.1 | ||
@@ -295,0 +302,0 @@ [v4.9.0]: https://github.com/jonaskello/tslint-immutable/compare/v4.8.0...v4.9.0 |
{ | ||
"name": "tslint-immutable", | ||
"version": "4.9.1", | ||
"version": "5.0.0", | ||
"description": "TSLint rules to disable mutation in TypeScript.", | ||
@@ -20,2 +20,5 @@ "main": "tslint-immutable.json", | ||
"homepage": "https://github.com/jonaskello/tslint-immutable#readme", | ||
"dependencies": { | ||
"tsutils": "^2.28.0 || ^3.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -30,6 +33,10 @@ "@types/node": "^8.0.53", | ||
"shelljs": "^0.7.5", | ||
"tslint": "^5.1.0", | ||
"tslint": "^5.8.0", | ||
"tslint-plugin-prettier": "^1.3.0", | ||
"typescript": "^2.2.2" | ||
"typescript": "^3.0.0" | ||
}, | ||
"peerDependencies": { | ||
"tslint": "^5.8.0", | ||
"typescript": "^2.8.0 || ^3.0.0" | ||
}, | ||
"scripts": { | ||
@@ -36,0 +43,0 @@ "compile": "tsc", |
@@ -29,5 +29,6 @@ # tslint-immutable | ||
* tslint-immutable 3.x.x is compatible with tslint 5.x.x. | ||
* tslint-immutable 2.x.x is compatible with tslint 4.x.x. | ||
* tslint-immutable 1.x.x is compatible with tslint 3.x.x. | ||
* tslint-immutable 5.x.x requires typescript >=2.8, node >=6, and tslint 5.x.x. | ||
* tslint-immutable 3.x.x requires tslint 5.x.x. | ||
* tslint-immutable 2.x.x requires tslint 4.x.x. | ||
* tslint-immutable 1.x.x requires tslint 3.x.x. | ||
@@ -170,6 +171,6 @@ ## TSLint Rules | ||
- [ignore-local](#using-the-ignore-local-option) | ||
- [ignore-prefix](#using-the-ignore-prefix-option) | ||
- [ignore-return-type](#using-the-ignore-return-type-option) | ||
- [ignore-rest-parameters](#using-the-ignore-rest-parameters-option) | ||
* [ignore-local](#using-the-ignore-local-option) | ||
* [ignore-prefix](#using-the-ignore-prefix-option) | ||
* [ignore-return-type](#using-the-ignore-return-type-option) | ||
* [ignore-rest-parameters](#using-the-ignore-rest-parameters-option) | ||
@@ -176,0 +177,0 @@ #### Example config |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var util_1 = require("tsutils/util"); | ||
var check_node_1 = require("./shared/check-node"); | ||
var Ignore = require("./shared/ignore"); | ||
var typeguard_1 = require("./shared/typeguard"); | ||
// tslint:disable-next-line:variable-name | ||
exports.Rule = check_node_1.createCheckNodeTypedRule(checkTypedNode, "Mutating an array is not allowed."); | ||
var arrPropAccessors = [ | ||
ts.SyntaxKind.ElementAccessExpression, | ||
ts.SyntaxKind.PropertyAccessExpression | ||
]; | ||
var forbidArrPropOnLeftSideOf = [ | ||
ts.SyntaxKind.EqualsToken, | ||
ts.SyntaxKind.PlusEqualsToken, | ||
ts.SyntaxKind.MinusEqualsToken, | ||
ts.SyntaxKind.AsteriskEqualsToken, | ||
ts.SyntaxKind.AsteriskAsteriskEqualsToken, | ||
ts.SyntaxKind.SlashEqualsToken, | ||
ts.SyntaxKind.PercentEqualsToken, | ||
ts.SyntaxKind.LessThanLessThanEqualsToken, | ||
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken, | ||
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, | ||
ts.SyntaxKind.AmpersandEqualsToken, | ||
ts.SyntaxKind.BarEqualsToken, | ||
ts.SyntaxKind.CaretEqualsToken | ||
]; | ||
function isArrayType(type) { | ||
return Boolean(type.symbol && type.symbol.name === "Array"); | ||
} | ||
exports.isArrayType = isArrayType; | ||
var forbidUnaryOps = [ | ||
@@ -52,10 +40,3 @@ ts.SyntaxKind.PlusPlusToken, | ||
*/ | ||
var accessorMethods = [ | ||
"concat", | ||
"slice", | ||
"toSource" // TODO: This is a non standardized method, should it me including? | ||
]; | ||
function isArrayType(type) { | ||
return type.symbol !== undefined && type.symbol.name === "Array"; | ||
} | ||
var accessorMethods = ["concat", "slice"]; | ||
function checkTypedNode(node, ctx, checker) { | ||
@@ -65,16 +46,18 @@ return { invalidNodes: getInvalidNodes(node, ctx, checker) }; | ||
function getInvalidNodes(node, ctx, checker) { | ||
switch (node.kind) { | ||
case ts.SyntaxKind.BinaryExpression: | ||
return checkBinaryExpression(node, ctx, checker); | ||
case ts.SyntaxKind.DeleteExpression: | ||
return checkDeleteExpression(node, ctx, checker); | ||
case ts.SyntaxKind.PrefixUnaryExpression: | ||
return checkPrefixUnaryExpression(node, ctx, checker); | ||
case ts.SyntaxKind.PostfixUnaryExpression: | ||
return checkPostfixUnaryExpression(node, ctx, checker); | ||
case ts.SyntaxKind.CallExpression: | ||
return checkCallExpression(node, ctx, checker); | ||
default: | ||
return []; | ||
if (utils.isBinaryExpression(node)) { | ||
return checkBinaryExpression(node, ctx, checker); | ||
} | ||
if (utils.isDeleteExpression(node)) { | ||
return checkDeleteExpression(node, ctx, checker); | ||
} | ||
if (utils.isPrefixUnaryExpression(node)) { | ||
return checkPrefixUnaryExpression(node, ctx, checker); | ||
} | ||
if (utils.isPostfixUnaryExpression(node)) { | ||
return checkPostfixUnaryExpression(node, ctx, checker); | ||
} | ||
if (utils.isCallExpression(node)) { | ||
return checkCallExpression(node, ctx, checker); | ||
} | ||
return []; | ||
} | ||
@@ -86,7 +69,7 @@ /** | ||
function checkBinaryExpression(node, ctx, checker) { | ||
if (arrPropAccessors.some(function (k) { return k === node.left.kind; }) && | ||
forbidArrPropOnLeftSideOf.some(function (k) { return k === node.operatorToken.kind; }) && | ||
!Ignore.isIgnoredPrefix(node.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
var left = node.left; | ||
var leftExpressionType = checker.getTypeAtLocation(left.expression); | ||
if (!Ignore.isIgnoredPrefix(node.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
utils.isBinaryExpression(node) && | ||
util_1.isAssignmentKind(node.operatorToken.kind) && | ||
typeguard_1.isAccessExpression(node.left)) { | ||
var leftExpressionType = checker.getTypeAtLocation(node.left.expression); | ||
if (isArrayType(leftExpressionType)) { | ||
@@ -102,7 +85,5 @@ return [check_node_1.createInvalidNode(node, [])]; | ||
function checkDeleteExpression(node, ctx, checker) { | ||
var delExp = node; | ||
if (arrPropAccessors.some(function (k) { return k === delExp.expression.kind; }) && | ||
!Ignore.isIgnoredPrefix(delExp.expression.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
var delExpExp = delExp.expression; | ||
var expressionType = checker.getTypeAtLocation(delExpExp.expression); | ||
if (!Ignore.isIgnoredPrefix(node.expression.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
typeguard_1.isAccessExpression(node.expression)) { | ||
var expressionType = checker.getTypeAtLocation(node.expression.expression); | ||
if (isArrayType(expressionType)) { | ||
@@ -118,8 +99,6 @@ return [check_node_1.createInvalidNode(node, [])]; | ||
function checkPrefixUnaryExpression(node, ctx, checker) { | ||
var preExp = node; | ||
if (arrPropAccessors.some(function (k) { return k === preExp.operand.kind; }) && | ||
forbidUnaryOps.some(function (o) { return o === preExp.operator; }) && | ||
!Ignore.isIgnoredPrefix(preExp.operand.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
var operand = preExp.operand; | ||
var operandExpressionType = checker.getTypeAtLocation(operand.expression); | ||
if (!Ignore.isIgnoredPrefix(node.operand.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
typeguard_1.isAccessExpression(node.operand) && | ||
forbidUnaryOps.some(function (o) { return o === node.operator; })) { | ||
var operandExpressionType = checker.getTypeAtLocation(node.operand.expression); | ||
if (isArrayType(operandExpressionType)) { | ||
@@ -135,8 +114,6 @@ return [check_node_1.createInvalidNode(node, [])]; | ||
function checkPostfixUnaryExpression(node, ctx, checker) { | ||
var postExp = node; | ||
if (arrPropAccessors.some(function (k) { return k === postExp.operand.kind; }) && | ||
forbidUnaryOps.some(function (o) { return o === postExp.operator; }) && | ||
!Ignore.isIgnoredPrefix(postExp.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
var operand = postExp.operand; | ||
var operandExpressionType = checker.getTypeAtLocation(operand.expression); | ||
if (!Ignore.isIgnoredPrefix(node.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
typeguard_1.isAccessExpression(node.operand) && | ||
forbidUnaryOps.some(function (o) { return o === node.operator; })) { | ||
var operandExpressionType = checker.getTypeAtLocation(node.operand.expression); | ||
if (isArrayType(operandExpressionType)) { | ||
@@ -152,14 +129,11 @@ return [check_node_1.createInvalidNode(node, [])]; | ||
function checkCallExpression(node, ctx, checker) { | ||
var callExp = node; | ||
if (ts.SyntaxKind.PropertyAccessExpression === callExp.expression.kind) { | ||
var propAccExp_1 = callExp.expression; | ||
if (mutatorMethods.some(function (m) { return m === propAccExp_1.name.text; }) && | ||
!Ignore.isIgnoredPrefix(callExp.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
(!ctx.options.ignoreMutationFollowingAccessor || | ||
!isInChainCallAndFollowsAccessor(propAccExp_1))) { | ||
// Do the type checking as late as possible (as it is expensive). | ||
var expressionType = checker.getTypeAtLocation(propAccExp_1.expression); | ||
if (isArrayType(expressionType)) { | ||
return [check_node_1.createInvalidNode(node, [])]; | ||
} | ||
if (!Ignore.isIgnoredPrefix(node.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
utils.isPropertyAccessExpression(node.expression) && | ||
(!ctx.options.ignoreMutationFollowingAccessor || | ||
!isInChainCallAndFollowsAccessor(node.expression)) && | ||
mutatorMethods.some(function (m) { return m === node.expression.name.text; })) { | ||
// Do the type checking as late as possible (as it is expensive). | ||
var expressionType = checker.getTypeAtLocation(node.expression.expression); | ||
if (isArrayType(expressionType)) { | ||
return [check_node_1.createInvalidNode(node, [])]; | ||
} | ||
@@ -175,14 +149,11 @@ } | ||
*/ | ||
function isInChainCallAndFollowsAccessor(propAccExp) { | ||
if (ts.SyntaxKind.CallExpression === propAccExp.expression.kind) { | ||
var subCallExp = propAccExp.expression; | ||
if (ts.SyntaxKind.PropertyAccessExpression === subCallExp.expression.kind) { | ||
var subPropAccExp_1 = subCallExp.expression; | ||
if (accessorMethods.some(function (m) { return m === subPropAccExp_1.name.text; })) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
function isInChainCallAndFollowsAccessor(node) { | ||
return (utils.isCallExpression(node.expression) && | ||
utils.isPropertyAccessExpression(node.expression.expression) && | ||
accessorMethods.some(function (m) { | ||
return m === | ||
node.expression | ||
.expression.name.text; | ||
})); | ||
} | ||
//# sourceMappingURL=noArrayMutationRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -8,10 +8,6 @@ // tslint:disable-next-line:variable-name | ||
function checkNode(node, _ctx) { | ||
return node && | ||
(node.kind === ts.SyntaxKind.ClassExpression || | ||
node.kind === ts.SyntaxKind.ClassDeclaration) | ||
return utils.isClassLikeDeclaration(node) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noClassRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -8,8 +8,6 @@ // tslint:disable-next-line:variable-name | ||
function checkNode(node, _ctx) { | ||
return node && node.kind === ts.SyntaxKind.DeleteExpression | ||
return utils.isDeleteExpression(node) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noDeleteRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -9,14 +10,12 @@ var Ignore = require("./shared/ignore"); | ||
function checkNode(node, ctx) { | ||
if (node && node.kind === ts.SyntaxKind.ExpressionStatement) { | ||
var esNode = node; | ||
var children = esNode.getChildren(); | ||
if (utils.isExpressionStatement(node)) { | ||
var children = node.getChildren(); | ||
var isYield = children.every(function (n) { return n.kind === ts.SyntaxKind.YieldExpression; }); | ||
var text = esNode.getText(esNode.getSourceFile()); | ||
if (esNode.expression.kind === ts.SyntaxKind.AwaitExpression) { | ||
var awaitNode = esNode.expression; | ||
text = awaitNode.expression.getText(awaitNode.getSourceFile()); | ||
var text = node.getText(node.getSourceFile()); | ||
if (utils.isAwaitExpression(node.expression)) { | ||
text = node.expression.expression.getText(node.expression.getSourceFile()); | ||
} | ||
var isIgnored2 = Ignore.isIgnoredPrefix(text, ctx.options.ignorePrefix); | ||
if (!isYield && !isIgnored2) { | ||
return { invalidNodes: [check_node_1.createInvalidNode(esNode, [])] }; | ||
return { invalidNodes: [check_node_1.createInvalidNode(node, [])] }; | ||
} | ||
@@ -23,0 +22,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -8,8 +8,6 @@ // tslint:disable-next-line:variable-name | ||
function checkNode(node, _ctx) { | ||
return node && node.kind === ts.SyntaxKind.IfStatement | ||
return utils.isIfStatement(node) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noIfStatementRule.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
var Lint = require("tslint"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var Ignore = require("./shared/ignore"); | ||
@@ -18,5 +19,4 @@ var check_node_1 = require("./shared/check-node"); | ||
function checkVariableStatement(node, ctx) { | ||
if (node.kind === ts.SyntaxKind.VariableStatement) { | ||
var variableStatementNode = node; | ||
return checkDeclarationList(variableStatementNode.declarationList, ctx); | ||
if (utils.isVariableStatement(node)) { | ||
return checkDeclarationList(node.declarationList, ctx); | ||
} | ||
@@ -26,13 +26,9 @@ return []; | ||
function checkForStatements(node, ctx) { | ||
if (node.kind === ts.SyntaxKind.ForStatement || | ||
node.kind === ts.SyntaxKind.ForInStatement || | ||
node.kind === ts.SyntaxKind.ForOfStatement) { | ||
var forStatementNode = node; | ||
if (forStatementNode.initializer && | ||
forStatementNode.initializer.kind === | ||
ts.SyntaxKind.VariableDeclarationList && | ||
Lint.isNodeFlagSet(forStatementNode.initializer, ts.NodeFlags.Let)) { | ||
var declarationList = forStatementNode.initializer; | ||
return checkDeclarationList(declarationList, ctx); | ||
} | ||
if ((utils.isForStatement(node) || | ||
utils.isForInStatement(node) || | ||
utils.isForOfStatement(node)) && | ||
node.initializer && | ||
utils.isVariableDeclarationList(node.initializer) && | ||
Lint.isNodeFlagSet(node.initializer, ts.NodeFlags.Let)) { | ||
return checkDeclarationList(node.initializer, ctx); | ||
} | ||
@@ -39,0 +35,0 @@ return []; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -9,12 +9,10 @@ // tslint:disable-next-line:variable-name | ||
return node && | ||
(node.kind === ts.SyntaxKind.ForStatement || | ||
node.kind === ts.SyntaxKind.ForInStatement || | ||
node.kind === ts.SyntaxKind.ForOfStatement || | ||
node.kind === ts.SyntaxKind.WhileStatement || | ||
node.kind === ts.SyntaxKind.DoStatement) | ||
(utils.isForStatement(node) || | ||
utils.isForInStatement(node) || | ||
utils.isForOfStatement(node) || | ||
utils.isWhileStatement(node) || | ||
utils.isDoStatement(node)) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noLoopStatementRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -8,8 +8,6 @@ // tslint:disable-next-line:variable-name | ||
function checkNode(node, _ctx) { | ||
return node && node.kind === ts.SyntaxKind.MethodSignature | ||
return utils.isMethodSignature(node) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noMethodSignatureRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -9,7 +9,6 @@ // tslint:disable-next-line:variable-name | ||
var invalidNodes = []; | ||
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) { | ||
var interfaceDeclaration = node; | ||
if (utils.isInterfaceDeclaration(node)) { | ||
var prevMemberKind = undefined; | ||
var prevMemberType = undefined; | ||
for (var _i = 0, _a = interfaceDeclaration.members; _i < _a.length; _i++) { | ||
for (var _i = 0, _a = node.members; _i < _a.length; _i++) { | ||
var member = _a[_i]; | ||
@@ -19,10 +18,7 @@ var memberKind = member.kind; | ||
// If it is a property declaration we need to check the type too | ||
if (member.kind === ts.SyntaxKind.PropertySignature) { | ||
var propertySignature = member; | ||
// Special care for function type | ||
if (propertySignature.type && | ||
propertySignature.type.kind === ts.SyntaxKind.FunctionType) { | ||
// We only set memberType for Functions | ||
memberType = propertySignature.type.kind; | ||
} | ||
if (utils.isPropertySignature(member) && | ||
member.type && | ||
utils.isFunctionTypeNode(member.type)) { | ||
// We only set memberType for Functions | ||
memberType = member.type.kind; | ||
} | ||
@@ -29,0 +25,0 @@ if (prevMemberKind !== undefined && |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var util_1 = require("tsutils/util"); | ||
var check_node_1 = require("./shared/check-node"); | ||
var Ignore = require("./shared/ignore"); | ||
var typeguard_1 = require("./shared/typeguard"); | ||
// tslint:disable-next-line:variable-name | ||
exports.Rule = check_node_1.createCheckNodeRule(checkNode, "Modifying properties of existing object not allowed."); | ||
var objPropAccessors = [ | ||
ts.SyntaxKind.ElementAccessExpression, | ||
ts.SyntaxKind.PropertyAccessExpression | ||
]; | ||
var forbidObjPropOnLeftSideOf = [ | ||
ts.SyntaxKind.EqualsToken, | ||
ts.SyntaxKind.PlusEqualsToken, | ||
ts.SyntaxKind.MinusEqualsToken, | ||
ts.SyntaxKind.AsteriskEqualsToken, | ||
ts.SyntaxKind.AsteriskAsteriskEqualsToken, | ||
ts.SyntaxKind.SlashEqualsToken, | ||
ts.SyntaxKind.PercentEqualsToken, | ||
ts.SyntaxKind.LessThanLessThanEqualsToken, | ||
ts.SyntaxKind.GreaterThanGreaterThanEqualsToken, | ||
ts.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken, | ||
ts.SyntaxKind.AmpersandEqualsToken, | ||
ts.SyntaxKind.BarEqualsToken, | ||
ts.SyntaxKind.CaretEqualsToken | ||
]; | ||
var forbidUnaryOps = [ | ||
@@ -34,36 +18,29 @@ ts.SyntaxKind.PlusPlusToken, | ||
// No assignment with object.property on the left | ||
if (node && node.kind === ts.SyntaxKind.BinaryExpression) { | ||
var binExp_1 = node; | ||
if (objPropAccessors.some(function (k) { return k === binExp_1.left.kind; }) && | ||
forbidObjPropOnLeftSideOf.some(function (k) { return k === binExp_1.operatorToken.kind; }) && | ||
!Ignore.isIgnoredPrefix(binExp_1.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
!inConstructor(node)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
if (utils.isBinaryExpression(node) && | ||
typeguard_1.isAccessExpression(node.left) && | ||
utils.isBinaryExpression(node) && | ||
util_1.isAssignmentKind(node.operatorToken.kind) && | ||
!Ignore.isIgnoredPrefix(node.getText(node.getSourceFile()), ctx.options.ignorePrefix) && | ||
!inConstructor(node)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
// No deleting object properties | ||
if (node && node.kind === ts.SyntaxKind.DeleteExpression) { | ||
var delExp_1 = node; | ||
if (objPropAccessors.some(function (k) { return k === delExp_1.expression.kind; }) && | ||
!Ignore.isIgnoredPrefix(delExp_1.expression.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
if (utils.isDeleteExpression(node) && | ||
typeguard_1.isAccessExpression(node.expression) && | ||
!Ignore.isIgnoredPrefix(node.expression.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
// No prefix inc/dec | ||
if (node && node.kind === ts.SyntaxKind.PrefixUnaryExpression) { | ||
var preExp_1 = node; | ||
if (objPropAccessors.some(function (k) { return k === preExp_1.operand.kind; }) && | ||
forbidUnaryOps.some(function (o) { return o === preExp_1.operator; }) && | ||
!Ignore.isIgnoredPrefix(preExp_1.operand.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
if (utils.isPrefixUnaryExpression(node) && | ||
typeguard_1.isAccessExpression(node.operand) && | ||
forbidUnaryOps.some(function (o) { return o === node.operator; }) && | ||
!Ignore.isIgnoredPrefix(node.operand.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
// No postfix inc/dec | ||
if (node && node.kind === ts.SyntaxKind.PostfixUnaryExpression) { | ||
var postExp_1 = node; | ||
if (objPropAccessors.some(function (k) { return k === postExp_1.operand.kind; }) && | ||
forbidUnaryOps.some(function (o) { return o === postExp_1.operator; }) && | ||
!Ignore.isIgnoredPrefix(postExp_1.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
if (utils.isPostfixUnaryExpression(node) && | ||
typeguard_1.isAccessExpression(node.operand) && | ||
forbidUnaryOps.some(function (o) { return o === node.operator; }) && | ||
!Ignore.isIgnoredPrefix(node.getText(node.getSourceFile()), ctx.options.ignorePrefix)) { | ||
invalidNodes = invalidNodes.concat([check_node_1.createInvalidNode(node, [])]); | ||
} | ||
@@ -75,3 +52,3 @@ return { invalidNodes: invalidNodes }; | ||
while (node) { | ||
if (node.kind === ts.SyntaxKind.Constructor) { | ||
if (utils.isConstructorDeclaration(node)) { | ||
return true; | ||
@@ -78,0 +55,0 @@ } |
@@ -8,8 +8,6 @@ "use strict"; | ||
function checkNode(node, _ctx) { | ||
return node && node.kind === ts.SyntaxKind.ThisKeyword | ||
return node.kind === ts.SyntaxKind.ThisKeyword | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noThisRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -8,8 +8,6 @@ // tslint:disable-next-line:variable-name | ||
function checkNode(node, _ctx) { | ||
return node && node.kind === ts.SyntaxKind.ThrowStatement | ||
return utils.isThrowStatement(node) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noThrowRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var check_node_1 = require("./shared/check-node"); | ||
@@ -8,8 +8,6 @@ // tslint:disable-next-line:variable-name | ||
function checkNode(node, _ctx) { | ||
return node && node.kind === ts.SyntaxKind.TryStatement | ||
return utils.isTryStatement(node) | ||
? { invalidNodes: [check_node_1.createInvalidNode(node, [])] } | ||
: { | ||
invalidNodes: [] | ||
}; | ||
: { invalidNodes: [] }; | ||
} | ||
//# sourceMappingURL=noTryRule.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var Lint = require("tslint"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var Ignore = require("./shared/ignore"); | ||
var check_node_1 = require("./shared/check-node"); | ||
var typeguard_1 = require("./shared/typeguard"); | ||
// tslint:disable-next-line:variable-name | ||
@@ -11,3 +12,3 @@ exports.Rule = check_node_1.createCheckNodeRule(Ignore.checkNodeWithIgnore(checkNode), "Only ReadonlyArray allowed."); | ||
return { | ||
invalidNodes: checkArrayType(node, ctx).concat(checkTypeReference(node, ctx), checkVariableOrParameterImplicitType(node, ctx)) | ||
invalidNodes: checkArrayType(node, ctx).concat(checkTypeReference(node, ctx), checkVariableLikeImplicitType(node, ctx)) | ||
}; | ||
@@ -17,3 +18,3 @@ } | ||
// We need to check both shorthand syntax "number[]"... | ||
if (node.kind === ts.SyntaxKind.ArrayType) { | ||
if (utils.isArrayTypeNode(node)) { | ||
if (node.parent && | ||
@@ -25,3 +26,3 @@ Ignore.shouldIgnorePrefix(node.parent, ctx.options, ctx.sourceFile)) { | ||
node.parent && | ||
node.parent.kind === ts.SyntaxKind.Parameter && | ||
utils.isParameterDeclaration(node.parent) && | ||
node.parent.dotDotDotToken) { | ||
@@ -44,3 +45,3 @@ return []; | ||
// ...and type reference "Array<number>" | ||
if (node.kind === ts.SyntaxKind.TypeReference && | ||
if (utils.isTypeReferenceNode(node) && | ||
node.typeName.getText(ctx.sourceFile) === "Array") { | ||
@@ -62,48 +63,46 @@ if (node.parent && | ||
} | ||
function checkVariableOrParameterImplicitType(node, ctx) { | ||
if (node.kind === ts.SyntaxKind.VariableDeclaration || | ||
node.kind === ts.SyntaxKind.Parameter || | ||
node.kind === ts.SyntaxKind.PropertyDeclaration) { | ||
// The initializer is used to set and implicit type | ||
var varOrParamNode = node; | ||
if (Ignore.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) { | ||
return []; | ||
} | ||
if (!varOrParamNode.type) { | ||
if (varOrParamNode.initializer && | ||
varOrParamNode.initializer.kind === ts.SyntaxKind.ArrayLiteralExpression) { | ||
var length_1 = varOrParamNode.name.getWidth(ctx.sourceFile); | ||
var nameText = varOrParamNode.name.getText(ctx.sourceFile); | ||
var typeArgument = "any"; | ||
// Not sure it is a good idea to guess what the element types are... | ||
// const arrayLiteralNode = varOrParamNode.initializer as ts.ArrayLiteralExpression; | ||
// if (arrayLiteralNode.elements.length > 0) { | ||
// const element = arrayLiteralNode.elements[0]; | ||
// if (element.kind === ts.SyntaxKind.NumericLiteral) { | ||
// typeArgument = "number"; | ||
// } else if (element.kind === ts.SyntaxKind.StringLiteral) { | ||
// typeArgument = "string"; | ||
// } else if (element.kind === ts.SyntaxKind.TrueKeyword || element.kind === ts.SyntaxKind.FalseKeyword) { | ||
// typeArgument = "boolean"; | ||
// } | ||
// } | ||
return [ | ||
check_node_1.createInvalidNode(varOrParamNode.name, [ | ||
new Lint.Replacement(varOrParamNode.name.end - length_1, length_1, nameText + ": ReadonlyArray<" + typeArgument + ">") | ||
]) | ||
]; | ||
} | ||
} | ||
function checkVariableLikeImplicitType(node, ctx) { | ||
// The initializer is used to set and implicit type | ||
if (Ignore.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) { | ||
return []; | ||
} | ||
if (typeguard_1.isVariableLikeDeclaration(node) && | ||
isUntypedAndHasArrayLiteralExpressionInitializer(node)) { | ||
var length_1 = node.name.getWidth(ctx.sourceFile); | ||
var nameText = node.name.getText(ctx.sourceFile); | ||
var typeArgument = "any"; | ||
// Not sure it is a good idea to guess what the element types are... | ||
// if (node.initializer.elements.length > 0) { | ||
// const element = node.initializer.elements[0]; | ||
// if (utils.isNumericLiteral(element)) { | ||
// typeArgument = "number"; | ||
// } else if (utils.isStringLiteral(element)) { | ||
// typeArgument = "string"; | ||
// } else if ( | ||
// element.kind === ts.SyntaxKind.TrueKeyword || | ||
// element.kind === ts.SyntaxKind.FalseKeyword | ||
// ) { | ||
// typeArgument = "boolean"; | ||
// } | ||
// } | ||
return [ | ||
check_node_1.createInvalidNode(node.name, [ | ||
new Lint.Replacement(node.name.end - length_1, length_1, nameText + ": ReadonlyArray<" + typeArgument + ">") | ||
]) | ||
]; | ||
} | ||
return []; | ||
} | ||
function checkIsReturnType(node) { | ||
return Boolean(node.parent !== undefined && | ||
(node.parent.kind === ts.SyntaxKind.FunctionDeclaration || | ||
node.parent.kind === ts.SyntaxKind.FunctionExpression || | ||
node.parent.kind === ts.SyntaxKind.ArrowFunction || | ||
node.parent.kind === ts.SyntaxKind.MethodDeclaration) && | ||
node === | ||
node.parent.type); | ||
return Boolean(node.parent && | ||
typeguard_1.isFunctionLikeDeclaration(node.parent) && | ||
node === node.parent.type); | ||
} | ||
function isUntypedAndHasArrayLiteralExpressionInitializer(node) { | ||
// tslint:disable:no-any | ||
return Boolean(!node.type && | ||
node.initializer && | ||
utils.isArrayLiteralExpression(node.initializer)); | ||
// tslint:enable:no-any | ||
} | ||
//# sourceMappingURL=readonlyArrayRule.js.map |
@@ -5,2 +5,3 @@ "use strict"; | ||
var Lint = require("tslint"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var Ignore = require("./shared/ignore"); | ||
@@ -18,18 +19,17 @@ var check_node_1 = require("./shared/check-node"); | ||
function checkPropertySignatureAndIndexSignature(node, ctx) { | ||
if (node.kind === ts.SyntaxKind.PropertySignature || | ||
node.kind === ts.SyntaxKind.IndexSignature || | ||
node.kind === ts.SyntaxKind.PropertyDeclaration) { | ||
if (!(node.modifiers && | ||
if ((utils.isPropertySignature(node) || | ||
utils.isIndexSignatureDeclaration(node) || | ||
utils.isPropertyDeclaration(node)) && | ||
!(node.modifiers && | ||
node.modifiers.filter(function (m) { return m.kind === ts.SyntaxKind.ReadonlyKeyword; }) | ||
.length > 0)) { | ||
// Check if ignore-prefix applies | ||
if (Ignore.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) { | ||
return []; | ||
} | ||
return [ | ||
check_node_1.createInvalidNode(node, [ | ||
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "readonly ") | ||
]) | ||
]; | ||
// Check if ignore-prefix applies | ||
if (Ignore.shouldIgnorePrefix(node, ctx.options, ctx.sourceFile)) { | ||
return []; | ||
} | ||
return [ | ||
check_node_1.createInvalidNode(node, [ | ||
new Lint.Replacement(node.getStart(ctx.sourceFile), 0, "readonly ") | ||
]) | ||
]; | ||
} | ||
@@ -36,0 +36,0 @@ return []; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/** | ||
@@ -7,7 +8,9 @@ * This file has functions that enable walking the nodes | ||
*/ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
} | ||
return function (d, b) { | ||
@@ -56,9 +59,8 @@ extendStatics(d, b); | ||
function createCheckNodeRule(checkNode, failureString, | ||
// tslint:disable-next-line:no-any | ||
parseOptions | ||
// tslint:disable-next-line:no-any | ||
// 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) { | ||
return /** @class */ (function (_super) { | ||
__extends(Rule, _super); | ||
@@ -78,9 +80,8 @@ function Rule() { | ||
function createCheckNodeTypedRule(checkTypedNode, failureString, | ||
// tslint:disable-next-line:no-any | ||
parseOptions | ||
// tslint:disable-next-line:no-any | ||
// 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) { | ||
return /** @class */ (function (_super) { | ||
__extends(Rule, _super); | ||
@@ -87,0 +88,0 @@ function Rule() { |
@@ -0,18 +1,15 @@ | ||
"use strict"; | ||
/** | ||
* This file has code that is shared for all the ignore options. | ||
*/ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ts = require("typescript"); | ||
var utils = require("tsutils/typeguard/2.8"); | ||
var typeguard_1 = require("./typeguard"); | ||
function checkNodeWithIgnore(checkNode) { | ||
return function (node, ctx) { | ||
// Skip checking in functions if ignore-local is set | ||
if (ctx.options.ignoreLocal && | ||
(node.kind === ts.SyntaxKind.FunctionDeclaration || | ||
node.kind === ts.SyntaxKind.ArrowFunction || | ||
node.kind === ts.SyntaxKind.FunctionExpression || | ||
node.kind === ts.SyntaxKind.MethodDeclaration)) { | ||
if (ctx.options.ignoreLocal && typeguard_1.isFunctionLikeDeclaration(node)) { | ||
// We still need to check the parameters and return type | ||
var functionNode = node; //tslint:disable-line | ||
var invalidNodes = checkIgnoreLocalFunctionNode(functionNode, ctx, checkNode); | ||
var invalidNodes = checkIgnoreLocalFunctionNode(node, ctx, checkNode); | ||
// Now skip this whole branch | ||
@@ -22,6 +19,4 @@ return { invalidNodes: invalidNodes, skipChildren: true }; | ||
// Skip checking in classes/interfaces if ignore-class/ignore-interface is set | ||
if ((ctx.options.ignoreClass && | ||
node.kind === ts.SyntaxKind.PropertyDeclaration) || | ||
(ctx.options.ignoreInterface && | ||
node.kind === ts.SyntaxKind.PropertySignature)) { | ||
if ((ctx.options.ignoreClass && utils.isPropertyDeclaration(node)) || | ||
(ctx.options.ignoreInterface && utils.isPropertySignature(node))) { | ||
// Now skip this whole branch | ||
@@ -74,12 +69,7 @@ return { invalidNodes: [], skipChildren: true }; | ||
function shouldIgnorePrefix(node, options, sourceFile) { | ||
// Check ignore-prefix for VariableDeclaration, PropertySignature, TypeAliasDeclaration, Parameter | ||
// Check ignore-prefix for VariableLikeDeclaration, TypeAliasDeclaration | ||
if (options.ignorePrefix) { | ||
if (node && | ||
(node.kind === ts.SyntaxKind.VariableDeclaration || | ||
node.kind === ts.SyntaxKind.Parameter || | ||
node.kind === ts.SyntaxKind.PropertySignature || | ||
node.kind === ts.SyntaxKind.PropertyDeclaration || | ||
node.kind === ts.SyntaxKind.TypeAliasDeclaration)) { | ||
var variableDeclarationNode = node; | ||
var variableText = variableDeclarationNode.name.getText(sourceFile); | ||
(typeguard_1.isVariableLikeDeclaration(node) || utils.isTypeAliasDeclaration(node))) { | ||
var variableText = node.name.getText(sourceFile); | ||
// if ( | ||
@@ -86,0 +76,0 @@ // variableText.substr(0, options.ignorePrefix.length) === |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
@@ -17,3 +20,3 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
*/ | ||
//tslint:disable-next-line | ||
// tslint:disable-next-line:no-any | ||
function parseOptions(ruleArguments) { | ||
@@ -20,0 +23,0 @@ var options = {}; |
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
644
525797
3
1870
+ Addedtsutils@^2.28.0 || ^3.0.0
+ Added@babel/code-frame@7.26.2(transitive)
+ Added@babel/helper-validator-identifier@7.25.9(transitive)
+ Addedansi-styles@3.2.1(transitive)
+ Addedargparse@1.0.10(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuiltin-modules@1.1.1(transitive)
+ Addedchalk@2.4.2(transitive)
+ Addedcolor-convert@1.9.3(transitive)
+ Addedcolor-name@1.1.3(transitive)
+ Addedcommander@2.20.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedesprima@4.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-flag@3.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-core-module@2.15.1(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedjs-yaml@3.14.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedsprintf-js@1.0.3(transitive)
+ Addedsupports-color@5.5.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtslib@1.14.1(transitive)
+ Addedtslint@5.20.1(transitive)
+ Addedtsutils@2.29.03.21.0(transitive)
+ Addedtypescript@3.9.10(transitive)
+ Addedwrappy@1.0.2(transitive)