1 | "use strict";
|
2 | var __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 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var ts = require("typescript");
|
14 | var Lint = require("tslint");
|
15 | var tsutils_1 = require("tsutils");
|
16 | var FAILURE_STRING = 'Suspicious comment found: ';
|
17 | var SUSPICIOUS_WORDS = ['BUG', 'HACK', 'FIXME', 'LATER', 'LATER2', 'TODO'];
|
18 | var Rule = (function (_super) {
|
19 | __extends(Rule, _super);
|
20 | function Rule() {
|
21 | return _super !== null && _super.apply(this, arguments) || this;
|
22 | }
|
23 | Rule.prototype.apply = function (sourceFile) {
|
24 | return this.applyWithWalker(new NoSuspiciousCommentRuleWalker(sourceFile, this.getOptions()));
|
25 | };
|
26 | Rule.metadata = {
|
27 | ruleName: 'no-suspicious-comment',
|
28 | type: 'maintainability',
|
29 | description: "Do not use suspicious comments, such as " + SUSPICIOUS_WORDS.join(', '),
|
30 | options: null,
|
31 | optionsDescription: '',
|
32 | typescriptOnly: true,
|
33 | issueClass: 'Non-SDL',
|
34 | issueType: 'Warning',
|
35 | severity: 'Low',
|
36 | level: 'Opportunity for Excellence',
|
37 | group: 'Clarity',
|
38 | commonWeaknessEnumeration: '546'
|
39 | };
|
40 | return Rule;
|
41 | }(Lint.Rules.AbstractRule));
|
42 | exports.Rule = Rule;
|
43 | var NoSuspiciousCommentRuleWalker = (function (_super) {
|
44 | __extends(NoSuspiciousCommentRuleWalker, _super);
|
45 | function NoSuspiciousCommentRuleWalker() {
|
46 | return _super !== null && _super.apply(this, arguments) || this;
|
47 | }
|
48 | NoSuspiciousCommentRuleWalker.prototype.visitSourceFile = function (node) {
|
49 | var _this = this;
|
50 | tsutils_1.forEachTokenWithTrivia(node, function (text, tokenSyntaxKind, range) {
|
51 | if (tokenSyntaxKind === ts.SyntaxKind.SingleLineCommentTrivia ||
|
52 | tokenSyntaxKind === ts.SyntaxKind.MultiLineCommentTrivia) {
|
53 | _this.scanCommentForSuspiciousWords(range.pos, text.substring(range.pos, range.end));
|
54 | }
|
55 | });
|
56 | };
|
57 | NoSuspiciousCommentRuleWalker.prototype.scanCommentForSuspiciousWords = function (startPosition, commentText) {
|
58 | var _this = this;
|
59 | SUSPICIOUS_WORDS.forEach(function (suspiciousWord) {
|
60 | _this.scanCommentForSuspiciousWord(suspiciousWord, commentText, startPosition);
|
61 | });
|
62 | };
|
63 | NoSuspiciousCommentRuleWalker.prototype.scanCommentForSuspiciousWord = function (suspiciousWord, commentText, startPosition) {
|
64 | var regexExactCaseNoColon = new RegExp('\\b' + suspiciousWord + '\\b');
|
65 | var regexCaseInsensistiveWithColon = new RegExp('\\b' + suspiciousWord + '\\b\:', 'i');
|
66 | if (regexExactCaseNoColon.test(commentText) || regexCaseInsensistiveWithColon.test(commentText)) {
|
67 | this.foundSuspiciousComment(startPosition, commentText, suspiciousWord);
|
68 | }
|
69 | };
|
70 | NoSuspiciousCommentRuleWalker.prototype.foundSuspiciousComment = function (startPosition, commentText, suspiciousWord) {
|
71 | var errorMessage = FAILURE_STRING + suspiciousWord;
|
72 | this.addFailureAt(startPosition, commentText.length, errorMessage);
|
73 | };
|
74 | return NoSuspiciousCommentRuleWalker;
|
75 | }(Lint.RuleWalker));
|
76 |
|
\ | No newline at end of file |