UNPKG

3.21 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 NoUnnecessarySemicolonsWalker(sourceFile, this.getOptions()));
23 };
24 Rule.FAILURE_STRING = 'unnecessary semi-colon';
25 Rule.metadata = {
26 ruleName: 'no-unnecessary-semicolons',
27 type: 'maintainability',
28 description: 'Remove unnecessary semicolons',
29 options: null,
30 optionsDescription: '',
31 typescriptOnly: true,
32 issueClass: 'Non-SDL',
33 issueType: 'Warning',
34 severity: 'Moderate',
35 level: 'Opportunity for Excellence',
36 group: 'Whitespace',
37 commonWeaknessEnumeration: '398, 710'
38 };
39 return Rule;
40}(Lint.Rules.AbstractRule));
41exports.Rule = Rule;
42var NoUnnecessarySemicolonsWalker = (function (_super) {
43 __extends(NoUnnecessarySemicolonsWalker, _super);
44 function NoUnnecessarySemicolonsWalker() {
45 return _super !== null && _super.apply(this, arguments) || this;
46 }
47 NoUnnecessarySemicolonsWalker.prototype.visitNode = function (node) {
48 if (node.kind === ts.SyntaxKind.EmptyStatement) {
49 this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
50 }
51 _super.prototype.visitNode.call(this, node);
52 };
53 NoUnnecessarySemicolonsWalker.prototype.visitForStatement = function (node) {
54 if (node.statement.kind === ts.SyntaxKind.EmptyStatement) {
55 if (node.initializer) {
56 this.visitNode(node.initializer);
57 }
58 if (node.condition) {
59 this.visitNode(node.condition);
60 }
61 if (node.incrementor) {
62 this.visitNode(node.incrementor);
63 }
64 }
65 else {
66 _super.prototype.visitForStatement.call(this, node);
67 }
68 };
69 NoUnnecessarySemicolonsWalker.prototype.visitWhileStatement = function (node) {
70 if (node.statement.kind === ts.SyntaxKind.EmptyStatement) {
71 this.visitNode(node.expression);
72 }
73 else {
74 _super.prototype.visitWhileStatement.call(this, node);
75 }
76 };
77 return NoUnnecessarySemicolonsWalker;
78}(ErrorTolerantWalker_1.ErrorTolerantWalker));
79//# sourceMappingURL=noUnnecessarySemicolonsRule.js.map
\No newline at end of file