UNPKG

2.92 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 var noOctalLiteral = new NoOctalLiteral(sourceFile, this.getOptions());
23 return this.applyWithWalker(noOctalLiteral);
24 };
25 Rule.metadata = {
26 ruleName: 'no-octal-literal',
27 type: 'maintainability',
28 description: 'Do not use octal literals or escaped octal sequences',
29 options: null,
30 optionsDescription: '',
31 typescriptOnly: true,
32 issueClass: 'SDL',
33 issueType: 'Error',
34 severity: 'Critical',
35 level: 'Mandatory',
36 group: 'Security'
37 };
38 Rule.FAILURE_STRING = 'Octal literals should not be used: ';
39 return Rule;
40}(Lint.Rules.AbstractRule));
41exports.Rule = Rule;
42var NoOctalLiteral = (function (_super) {
43 __extends(NoOctalLiteral, _super);
44 function NoOctalLiteral() {
45 return _super !== null && _super.apply(this, arguments) || this;
46 }
47 NoOctalLiteral.prototype.visitNode = function (node) {
48 if (node.kind === ts.SyntaxKind.StringLiteral || node.kind === ts.SyntaxKind.FirstTemplateToken) {
49 this.failOnOctalString(node);
50 }
51 _super.prototype.visitNode.call(this, node);
52 };
53 NoOctalLiteral.prototype.failOnOctalString = function (node) {
54 var match = /("|'|`)[^\\]*(\\+-?[0-7]{1,3}(?![0-9]))(?:.|\n|\t|\u2028|\u2029)*(?:\1)/g.exec(node.getText());
55 if (match) {
56 var octalValue = match[2];
57 var backslashCount = octalValue.lastIndexOf('\\') + 1;
58 if (backslashCount % 2 === 1) {
59 octalValue = octalValue.substr(backslashCount - 1);
60 var startOfMatch = node.getStart() + node.getText().indexOf(octalValue);
61 var width = octalValue.length;
62 this.addFailureAt(startOfMatch, width, Rule.FAILURE_STRING + octalValue);
63 }
64 }
65 };
66 return NoOctalLiteral;
67}(ErrorTolerantWalker_1.ErrorTolerantWalker));
68//# sourceMappingURL=noOctalLiteralRule.js.map
\No newline at end of file