From a69825e84e7e08a5a05e00fc4d19ec613968c1eb Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Tue, 1 Dec 2015 16:27:19 -0800 Subject: [PATCH] tweak rules --- scripts/tslint/noIncrementDecrementRule.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/tslint/noIncrementDecrementRule.ts b/scripts/tslint/noIncrementDecrementRule.ts index 25b18b61ae9..c8655f0933d 100644 --- a/scripts/tslint/noIncrementDecrementRule.ts +++ b/scripts/tslint/noIncrementDecrementRule.ts @@ -3,7 +3,8 @@ import * as ts from "typescript"; export class Rule extends Lint.Rules.AbstractRule { - public static FAILURE_STRING = "Don't use '++' or '--' operators outside for loops or statements - prefer '+= 1' and '-= 1'."; + public static POSTFIX_FAILURE_STRING = "Don't use '++' or '--' postfix operators outside statements, for loops, or element access expressions."; + public static PREFIX_FAILURE_STRING = "Don't use '++' or '--' prefix operators."; public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { return this.applyWithWalker(new IncrementDecrementWalker(sourceFile, this.getOptions())); @@ -22,14 +23,14 @@ class IncrementDecrementWalker extends Lint.RuleWalker { visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression) { super.visitPrefixUnaryExpression(node); if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) { - this.visitIncrementDecrement(node); + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.PREFIX_FAILURE_STRING)); } } visitIncrementDecrement(node: ts.UnaryExpression) { - if (node.parent && (node.parent.kind === ts.SyntaxKind.ExpressionStatement || node.parent.kind === ts.SyntaxKind.ForStatement)) { + if (node.parent && (node.parent.kind === ts.SyntaxKind.ExpressionStatement || node.parent.kind === ts.SyntaxKind.ForStatement || node.parent.kind === ts.SyntaxKind.ElementAccessExpression)) { return; } - this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING)); + this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.POSTFIX_FAILURE_STRING)); } }