1 | "use strict";
|
2 | var __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 | })();
|
12 | Object.defineProperty(exports, "__esModule", { value: true });
|
13 | var ts = require("typescript");
|
14 | var Lint = require("tslint");
|
15 | var FAILURE_STRING = 'Assigning this reference to local variable: ';
|
16 | var 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 | if (Rule.isWarningShown === false) {
|
23 | console.warn('Warning: no-var-self rule is deprecated. Replace your usage with the TSLint no-this-assignment rule.');
|
24 | Rule.isWarningShown = true;
|
25 | }
|
26 | return this.applyWithWalker(new NoVarSelfRuleWalker(sourceFile, this.getOptions()));
|
27 | };
|
28 | Rule.metadata = {
|
29 | ruleName: 'no-var-self',
|
30 | type: 'maintainability',
|
31 | description: 'Do not use var self = this; instead, manage scope with arrow functions/lambdas.',
|
32 | options: null,
|
33 | optionsDescription: '',
|
34 | typescriptOnly: true,
|
35 | issueClass: 'Non-SDL',
|
36 | issueType: 'Warning',
|
37 | severity: 'Important',
|
38 | level: 'Opportunity for Excellence',
|
39 | group: 'Deprecated',
|
40 | recommendation: 'false,',
|
41 | commonWeaknessEnumeration: '398, 710'
|
42 | };
|
43 | Rule.isWarningShown = false;
|
44 | return Rule;
|
45 | }(Lint.Rules.AbstractRule));
|
46 | exports.Rule = Rule;
|
47 | var NoVarSelfRuleWalker = (function (_super) {
|
48 | __extends(NoVarSelfRuleWalker, _super);
|
49 | function NoVarSelfRuleWalker(sourceFile, options) {
|
50 | var _this = _super.call(this, sourceFile, options) || this;
|
51 | _this.bannedVariableNames = /.*/;
|
52 | if (options.ruleArguments != null && options.ruleArguments.length > 0) {
|
53 | _this.bannedVariableNames = new RegExp(options.ruleArguments[0]);
|
54 | }
|
55 | return _this;
|
56 | }
|
57 | NoVarSelfRuleWalker.prototype.visitVariableDeclaration = function (node) {
|
58 | if (node.initializer != null && node.initializer.kind === ts.SyntaxKind.ThisKeyword) {
|
59 | if (node.name.kind === ts.SyntaxKind.Identifier) {
|
60 | var identifier = node.name;
|
61 | if (this.bannedVariableNames.test(identifier.text)) {
|
62 | this.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING + node.getText());
|
63 | }
|
64 | }
|
65 | }
|
66 | _super.prototype.visitVariableDeclaration.call(this, node);
|
67 | };
|
68 | return NoVarSelfRuleWalker;
|
69 | }(Lint.RuleWalker));
|
70 |
|
\ | No newline at end of file |