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 ErrorTolerantWalker_1 = require("./utils/ErrorTolerantWalker");
|
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 | var noDeleteExpression = new NoDeleteExpression(sourceFile, this.getOptions());
|
23 | return this.applyWithWalker(noDeleteExpression);
|
24 | };
|
25 | Rule.metadata = {
|
26 | ruleName: 'no-delete-expression',
|
27 | type: 'maintainability',
|
28 | description: 'Do not delete expressions. Only properties should be deleted',
|
29 | options: null,
|
30 | optionsDescription: '',
|
31 | typescriptOnly: true,
|
32 | issueClass: 'SDL',
|
33 | issueType: 'Error',
|
34 | severity: 'Critical',
|
35 | level: 'Mandatory',
|
36 | group: 'Security'
|
37 | };
|
38 | Rule.FAILURE_STRING = 'Variables should not be deleted: ';
|
39 | return Rule;
|
40 | }(Lint.Rules.AbstractRule));
|
41 | exports.Rule = Rule;
|
42 | var NoDeleteExpression = (function (_super) {
|
43 | __extends(NoDeleteExpression, _super);
|
44 | function NoDeleteExpression() {
|
45 | return _super !== null && _super.apply(this, arguments) || this;
|
46 | }
|
47 | NoDeleteExpression.prototype.visitExpressionStatement = function (node) {
|
48 | _super.prototype.visitExpressionStatement.call(this, node);
|
49 | if (node.expression.kind === ts.SyntaxKind.DeleteExpression) {
|
50 | var deletedObject = node.expression.getChildren()[1];
|
51 | if (deletedObject != null && deletedObject.kind === ts.SyntaxKind.Identifier) {
|
52 | this.addNoDeleteFailure(deletedObject);
|
53 | }
|
54 | }
|
55 | };
|
56 | NoDeleteExpression.prototype.addNoDeleteFailure = function (deletedObject) {
|
57 | var msg = Rule.FAILURE_STRING + deletedObject.getFullText().trim();
|
58 | this.addFailureAt(deletedObject.getStart(), deletedObject.getWidth(), msg);
|
59 | };
|
60 | return NoDeleteExpression;
|
61 | }(ErrorTolerantWalker_1.ErrorTolerantWalker));
|
62 |
|
\ | No newline at end of file |