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 FAILURE_STRING = 'Replace void 0 with undefined';
|
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 | return this.applyWithFunction(sourceFile, walk);
|
27 | };
|
28 | Rule.metadata = {
|
29 | ruleName: 'void-zero',
|
30 | type: 'maintainability',
|
31 | description: 'Avoid using void 0; use undefined instead.',
|
32 | hasFix: true,
|
33 | rationale: 'void 0, which resolves to undefined, can be confusing to newcomers. Exclusively use undefined to reduce ambiguity.',
|
34 | options: null,
|
35 | optionsDescription: '',
|
36 | typescriptOnly: true,
|
37 | issueClass: 'Non-SDL',
|
38 | issueType: 'Warning',
|
39 | severity: 'Low',
|
40 | level: 'Opportunity for Excellence',
|
41 | group: 'Clarity',
|
42 | commonWeaknessEnumeration: '480'
|
43 | };
|
44 | return Rule;
|
45 | }(Lint.Rules.AbstractRule));
|
46 | exports.Rule = Rule;
|
47 | function walk(ctx) {
|
48 | function cb(node) {
|
49 | if (tsutils.isVoidExpression(node)) {
|
50 | if (node.expression !== undefined && node.expression.getText() === '0') {
|
51 | var nodeStart = node.getStart();
|
52 | var nodeWidth = node.getWidth();
|
53 | var fix = new Lint.Replacement(nodeStart, nodeWidth, 'undefined');
|
54 | ctx.addFailureAt(nodeStart, nodeWidth, FAILURE_STRING, fix);
|
55 | }
|
56 | }
|
57 | return ts.forEachChild(node, cb);
|
58 | }
|
59 | return ts.forEachChild(ctx.sourceFile, cb);
|
60 | }
|
61 |
|
\ | No newline at end of file |