This repository has been archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
/
noOctalLiteralRule.js
68 lines (68 loc) · 2.79 KB
/
noOctalLiteralRule.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var ts = require("typescript");
var Lint = require("tslint");
var ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
var Rule = (function (_super) {
__extends(Rule, _super);
function Rule() {
return _super !== null && _super.apply(this, arguments) || this;
}
Rule.prototype.apply = function (sourceFile) {
var noOctalLiteral = new NoOctalLiteral(sourceFile, this.getOptions());
return this.applyWithWalker(noOctalLiteral);
};
Rule.metadata = {
ruleName: 'no-octal-literal',
type: 'maintainability',
description: 'Do not use octal literals or escaped octal sequences',
options: null,
optionsDescription: '',
typescriptOnly: true,
issueClass: 'SDL',
issueType: 'Error',
severity: 'Critical',
level: 'Mandatory',
group: 'Security'
};
Rule.FAILURE_STRING = 'Octal literals should not be used: ';
return Rule;
}(Lint.Rules.AbstractRule));
exports.Rule = Rule;
var NoOctalLiteral = (function (_super) {
__extends(NoOctalLiteral, _super);
function NoOctalLiteral() {
return _super !== null && _super.apply(this, arguments) || this;
}
NoOctalLiteral.prototype.visitNode = function (node) {
if (node.kind === ts.SyntaxKind.StringLiteral || node.kind === ts.SyntaxKind.FirstTemplateToken) {
this.failOnOctalString(node);
}
_super.prototype.visitNode.call(this, node);
};
NoOctalLiteral.prototype.failOnOctalString = function (node) {
var match = /("|'|`)[^\\]*(\\+-?[0-7]{1,3}(?![0-9]))(?:.|\n|\t|\u2028|\u2029)*(?:\1)/g.exec(node.getText());
if (match) {
var octalValue = match[2];
var backslashCount = octalValue.lastIndexOf('\\') + 1;
if (backslashCount % 2 === 1) {
octalValue = octalValue.substr(backslashCount - 1);
var startOfMatch = node.getStart() + node.getText().indexOf(octalValue);
var width = octalValue.length;
this.addFailureAt(startOfMatch, width, Rule.FAILURE_STRING + octalValue);
}
}
};
return NoOctalLiteral;
}(ErrorTolerantWalker_1.ErrorTolerantWalker));
//# sourceMappingURL=noOctalLiteralRule.js.map