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 FAILURE_STRING = 'Found as-cast instead of a traditional type-cast. Please convert to a type-cast: ';
|
17 | var Rule = (function (_super) {
|
18 | __extends(Rule, _super);
|
19 | function Rule() {
|
20 | return _super !== null && _super.apply(this, arguments) || this;
|
21 | }
|
22 | Rule.prototype.apply = function (sourceFile) {
|
23 | return this.applyWithWalker(new PreferTypeCastRuleWalker(sourceFile, this.getOptions()));
|
24 | };
|
25 | Rule.metadata = {
|
26 | ruleName: 'prefer-type-cast',
|
27 | type: 'maintainability',
|
28 | description: 'Prefer the tradition type casts instead of the new \'as-cast\' syntax',
|
29 | options: null,
|
30 | optionsDescription: '',
|
31 | typescriptOnly: true,
|
32 | issueClass: 'Ignored',
|
33 | issueType: 'Warning',
|
34 | severity: 'Low',
|
35 | level: 'Opportunity for Excellence',
|
36 | group: 'Configurable',
|
37 | recommendation: 'true, // pick either type-cast format and use it consistently',
|
38 | commonWeaknessEnumeration: '398, 710'
|
39 | };
|
40 | return Rule;
|
41 | }(Lint.Rules.AbstractRule));
|
42 | exports.Rule = Rule;
|
43 | var PreferTypeCastRuleWalker = (function (_super) {
|
44 | __extends(PreferTypeCastRuleWalker, _super);
|
45 | function PreferTypeCastRuleWalker() {
|
46 | return _super !== null && _super.apply(this, arguments) || this;
|
47 | }
|
48 | PreferTypeCastRuleWalker.prototype.visitSourceFile = function (node) {
|
49 | if (/.*\.tsx/.test(node.fileName) === false) {
|
50 | _super.prototype.visitSourceFile.call(this, node);
|
51 | }
|
52 | };
|
53 | PreferTypeCastRuleWalker.prototype.visitNode = function (node) {
|
54 | if (node.kind === ts.SyntaxKind.AsExpression) {
|
55 | this.addFailureAt(node.getStart(), node.getWidth(), FAILURE_STRING + node.getText());
|
56 | }
|
57 | _super.prototype.visitNode.call(this, node);
|
58 | };
|
59 | return PreferTypeCastRuleWalker;
|
60 | }(ErrorTolerantWalker_1.ErrorTolerantWalker));
|
61 |
|
\ | No newline at end of file |