UNPKG

2.53 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 NoMultilineStringWalker(sourceFile, this.getOptions()));
23 };
24 Rule.metadata = {
25 ruleName: 'no-multiline-string',
26 type: 'maintainability',
27 description: 'Do not declare multiline strings',
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: 'Clarity',
36 recommendation: 'false,',
37 commonWeaknessEnumeration: '710'
38 };
39 Rule.FAILURE_STRING = 'Forbidden Multiline string: ';
40 return Rule;
41}(Lint.Rules.AbstractRule));
42exports.Rule = Rule;
43var NoMultilineStringWalker = (function (_super) {
44 __extends(NoMultilineStringWalker, _super);
45 function NoMultilineStringWalker() {
46 return _super !== null && _super.apply(this, arguments) || this;
47 }
48 NoMultilineStringWalker.prototype.visitNode = function (node) {
49 if (node.kind === ts.SyntaxKind.NoSubstitutionTemplateLiteral) {
50 var fullText = node.getFullText();
51 var firstLine = fullText.substring(0, fullText.indexOf('\n'));
52 var trimmed = firstLine.substring(0, 40).trim();
53 this.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + trimmed + '...');
54 }
55 _super.prototype.visitNode.call(this, node);
56 };
57 return NoMultilineStringWalker;
58}(ErrorTolerantWalker_1.ErrorTolerantWalker));
59//# sourceMappingURL=noMultilineStringRule.js.map
\No newline at end of file