1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = function (d, b) {
|
4 | extendStatics = Object.setPrototypeOf ||
|
5 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
6 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
7 | return extendStatics(d, b);
|
8 | }
|
9 | return function (d, b) {
|
10 | extendStatics(d, b);
|
11 | function __() { this.constructor = d; }
|
12 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
13 | };
|
14 | })();
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | var ts = require("typescript");
|
17 | var Lint = require("tslint");
|
18 | var tsutils = require("tsutils");
|
19 | var AstUtils_1 = require("./utils/AstUtils");
|
20 | var Rule = (function (_super) {
|
21 | __extends(Rule, _super);
|
22 | function Rule() {
|
23 | return _super !== null && _super.apply(this, arguments) || this;
|
24 | }
|
25 | Rule.prototype.apply = function (sourceFile) {
|
26 | if (Rule.isWarningShown === false) {
|
27 | console.warn('Warning: no-function-constructor-with-string-args rule is deprecated. Replace your usage with the TSLint function-constructor rule.');
|
28 | Rule.isWarningShown = true;
|
29 | }
|
30 | return this.applyWithFunction(sourceFile, walk);
|
31 | };
|
32 | Rule.metadata = {
|
33 | ruleName: 'no-function-constructor-with-string-args',
|
34 | type: 'maintainability',
|
35 | description: 'Do not use the version of the Function constructor that accepts a string argument to define the body of the function',
|
36 | options: null,
|
37 | optionsDescription: '',
|
38 | typescriptOnly: true,
|
39 | issueClass: 'SDL',
|
40 | issueType: 'Error',
|
41 | severity: 'Critical',
|
42 | level: 'Mandatory',
|
43 | recommendation: 'false',
|
44 | group: 'Security',
|
45 | commonWeaknessEnumeration: '95, 676, 242, 116'
|
46 | };
|
47 | Rule.FAILURE_STRING = 'forbidden: Function constructor with string arguments ';
|
48 | Rule.isWarningShown = false;
|
49 | return Rule;
|
50 | }(Lint.Rules.AbstractRule));
|
51 | exports.Rule = Rule;
|
52 | function walk(ctx) {
|
53 | function cb(node) {
|
54 | if (tsutils.isNewExpression(node)) {
|
55 | var functionName = AstUtils_1.AstUtils.getFunctionName(node);
|
56 | if (functionName === 'Function' && node.arguments && node.arguments.length > 0) {
|
57 | ctx.addFailureAt(node.getStart(), node.getWidth(), Rule.FAILURE_STRING);
|
58 | }
|
59 | }
|
60 | return ts.forEachChild(node, cb);
|
61 | }
|
62 | return ts.forEachChild(ctx.sourceFile, cb);
|
63 | }
|
64 |
|
\ | No newline at end of file |