UNPKG

2.87 kBJavaScriptView Raw
1"use strict";
2var __extends = (this && this.__extends) || (function () {
3 var extendStatics = Object.setPrototypeOf ||
4 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6 return function (d, b) {
7 extendStatics(d, b);
8 function __() { this.constructor = d; }
9 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10 };
11})();
12Object.defineProperty(exports, "__esModule", { value: true });
13var ts = require("typescript");
14var Lint = require("tslint");
15var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
16var Rule = (function (_super) {
17 __extends(Rule, _super);
18 function Rule() {
19 return _super !== null && _super.apply(this, arguments) || this;
20 }
21 Rule.prototype.apply = function (sourceFile) {
22 return this.applyWithWalker(new NoIncrementDecrementWalker(sourceFile, this.getOptions()));
23 };
24 Rule.metadata = {
25 ruleName: 'no-increment-decrement',
26 type: 'maintainability',
27 description: 'Avoid use of increment and decrement operators particularly as part of complicated expressions',
28 options: null,
29 optionsDescription: '',
30 typescriptOnly: true,
31 issueClass: 'Non-SDL',
32 issueType: 'Warning',
33 severity: 'Low',
34 level: 'Opportunity for Excellence',
35 group: 'Correctness',
36 commonWeaknessEnumeration: '398, 710'
37 };
38 return Rule;
39}(Lint.Rules.AbstractRule));
40exports.Rule = Rule;
41var NoIncrementDecrementWalker = (function (_super) {
42 __extends(NoIncrementDecrementWalker, _super);
43 function NoIncrementDecrementWalker() {
44 return _super !== null && _super.apply(this, arguments) || this;
45 }
46 NoIncrementDecrementWalker.prototype.visitPostfixUnaryExpression = function (node) {
47 this.validateUnaryExpression(node);
48 _super.prototype.visitPostfixUnaryExpression.call(this, node);
49 };
50 NoIncrementDecrementWalker.prototype.visitPrefixUnaryExpression = function (node) {
51 this.validateUnaryExpression(node);
52 _super.prototype.visitPrefixUnaryExpression.call(this, node);
53 };
54 NoIncrementDecrementWalker.prototype.validateUnaryExpression = function (node) {
55 if (node.operator === ts.SyntaxKind.PlusPlusToken) {
56 this.addFailureAt(node.getStart(), node.getWidth(), 'Forbidden ++ operator');
57 }
58 else if (node.operator === ts.SyntaxKind.MinusMinusToken) {
59 this.addFailureAt(node.getStart(), node.getWidth(), 'Forbidden -- operator');
60 }
61 };
62 return NoIncrementDecrementWalker;
63}(ErrorTolerantWalker_1.ErrorTolerantWalker));
64//# sourceMappingURL=noIncrementDecrementRule.js.map
\No newline at end of file