1 | var __extends = (this && this.__extends) || function (d, b) {
|
2 | for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
3 | function __() { this.constructor = d; }
|
4 | __.prototype = b.prototype;
|
5 | d.prototype = new __();
|
6 | };
|
7 | var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
|
8 | var SyntaxKind = require('./utils/SyntaxKind');
|
9 | var Rule = (function (_super) {
|
10 | __extends(Rule, _super);
|
11 | function Rule() {
|
12 | _super.apply(this, arguments);
|
13 | }
|
14 | Rule.prototype.apply = function (sourceFile) {
|
15 | return this.applyWithWalker(new NoControlRegexRuleWalker(sourceFile, this.getOptions()));
|
16 | };
|
17 | Rule.FAILURE_STRING = 'Unexpected control character in regular expression';
|
18 | return Rule;
|
19 | })(Lint.Rules.AbstractRule);
|
20 | exports.Rule = Rule;
|
21 | var NoControlRegexRuleWalker = (function (_super) {
|
22 | __extends(NoControlRegexRuleWalker, _super);
|
23 | function NoControlRegexRuleWalker() {
|
24 | _super.apply(this, arguments);
|
25 | }
|
26 | NoControlRegexRuleWalker.prototype.visitNewExpression = function (node) {
|
27 | this.validateCall(node);
|
28 | _super.prototype.visitNewExpression.call(this, node);
|
29 | };
|
30 | NoControlRegexRuleWalker.prototype.visitCallExpression = function (node) {
|
31 | this.validateCall(node);
|
32 | _super.prototype.visitCallExpression.call(this, node);
|
33 | };
|
34 | NoControlRegexRuleWalker.prototype.visitRegularExpressionLiteral = function (node) {
|
35 | if (/(\\x[0-1][0-9a-f])/.test(node.getText())) {
|
36 | this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
|
37 | }
|
38 | _super.prototype.visitRegularExpressionLiteral.call(this, node);
|
39 | };
|
40 | NoControlRegexRuleWalker.prototype.validateCall = function (expression) {
|
41 | if (expression.expression.getText() === 'RegExp') {
|
42 | if (expression.arguments.length > 0) {
|
43 | var arg1 = expression.arguments[0];
|
44 | if (arg1.kind === SyntaxKind.current().StringLiteral) {
|
45 | var regexpText = arg1.text;
|
46 | if (/[\x00-\x1f]/.test(regexpText)) {
|
47 | this.addFailure(this.createFailure(arg1.getStart(), arg1.getWidth(), Rule.FAILURE_STRING));
|
48 | }
|
49 | }
|
50 | }
|
51 | }
|
52 | };
|
53 | return NoControlRegexRuleWalker;
|
54 | })(ErrorTolerantWalker);
|
55 |
|
\ | No newline at end of file |