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 SyntaxKind = require('./utils/SyntaxKind');
|
8 | var ErrorTolerantWalker = require('./utils/ErrorTolerantWalker');
|
9 | var Utils = require('./utils/Utils');
|
10 | var Rule = (function (_super) {
|
11 | __extends(Rule, _super);
|
12 | function Rule() {
|
13 | _super.apply(this, arguments);
|
14 | }
|
15 | Rule.prototype.apply = function (sourceFile) {
|
16 | return this.applyWithWalker(new NoHttpStringWalker(sourceFile, this.getOptions()));
|
17 | };
|
18 | Rule.FAILURE_STRING = 'Forbidden http url in string: ';
|
19 | return Rule;
|
20 | })(Lint.Rules.AbstractRule);
|
21 | exports.Rule = Rule;
|
22 | var NoHttpStringWalker = (function (_super) {
|
23 | __extends(NoHttpStringWalker, _super);
|
24 | function NoHttpStringWalker() {
|
25 | _super.apply(this, arguments);
|
26 | }
|
27 | NoHttpStringWalker.prototype.visitNode = function (node) {
|
28 | if (node.kind === SyntaxKind.current().StringLiteral) {
|
29 | var stringText = node.text;
|
30 | if (/.*http:.*/.test(stringText)) {
|
31 | if (!this.isSuppressed(stringText)) {
|
32 | var failureString = Rule.FAILURE_STRING + '\'' + stringText + '\'';
|
33 | var failure = this.createFailure(node.getStart(), node.getWidth(), failureString);
|
34 | this.addFailure(failure);
|
35 | }
|
36 | }
|
37 | }
|
38 | _super.prototype.visitNode.call(this, node);
|
39 | };
|
40 | NoHttpStringWalker.prototype.isSuppressed = function (stringText) {
|
41 | var allExceptions = NoHttpStringWalker.getExceptions(this.getOptions());
|
42 | return Utils.exists(allExceptions, function (exception) {
|
43 | return new RegExp(exception).test(stringText);
|
44 | });
|
45 | };
|
46 | NoHttpStringWalker.getExceptions = function (options) {
|
47 | if (options.ruleArguments instanceof Array) {
|
48 | return options.ruleArguments[0];
|
49 | }
|
50 | if (options instanceof Array) {
|
51 | return options;
|
52 | }
|
53 | return null;
|
54 | };
|
55 | return NoHttpStringWalker;
|
56 | })(ErrorTolerantWalker);
|
57 |
|
\ | No newline at end of file |