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 Rule = (function (_super) {
|
20 | __extends(Rule, _super);
|
21 | function Rule() {
|
22 | return _super !== null && _super.apply(this, arguments) || this;
|
23 | }
|
24 | Rule.prototype.apply = function (sourceFile) {
|
25 | if (Rule.isWarningShown === false) {
|
26 | console.warn('Warning: no-duplicate-case rule is deprecated. Replace your usage with the TSLint no-duplicate-switch-case rule.');
|
27 | Rule.isWarningShown = true;
|
28 | }
|
29 | return this.applyWithFunction(sourceFile, walk);
|
30 | };
|
31 | Rule.metadata = {
|
32 | ruleName: 'no-duplicate-case',
|
33 | type: 'maintainability',
|
34 | description: 'Do not use duplicate case labels in switch statements.',
|
35 | options: null,
|
36 | optionsDescription: '',
|
37 | typescriptOnly: true,
|
38 | issueClass: 'Non-SDL',
|
39 | issueType: 'Error',
|
40 | severity: 'Critical',
|
41 | level: 'Opportunity for Excellence',
|
42 | recommendation: 'false',
|
43 | group: 'Deprecated',
|
44 | commonWeaknessEnumeration: '398, 710'
|
45 | };
|
46 | Rule.FAILURE_STRING = 'Duplicate case found in switch statement: ';
|
47 | Rule.isWarningShown = false;
|
48 | return Rule;
|
49 | }(Lint.Rules.AbstractRule));
|
50 | exports.Rule = Rule;
|
51 | function walk(ctx) {
|
52 | function cb(node) {
|
53 | if (tsutils.isSwitchStatement(node)) {
|
54 | var seenLabels_1 = [];
|
55 | node.caseBlock.clauses.forEach(function (clauseOrDefault) {
|
56 | if (tsutils.isCaseClause(clauseOrDefault)) {
|
57 | var clause = clauseOrDefault;
|
58 | if (clause.expression) {
|
59 | var caseText = clause.expression.getText();
|
60 | if (seenLabels_1.indexOf(caseText) > -1) {
|
61 | ctx.addFailureAt(clause.getStart(), clause.getWidth(), Rule.FAILURE_STRING + caseText);
|
62 | }
|
63 | else {
|
64 | seenLabels_1.push(caseText);
|
65 | }
|
66 | }
|
67 | }
|
68 | });
|
69 | }
|
70 | return ts.forEachChild(node, cb);
|
71 | }
|
72 | return ts.forEachChild(ctx.sourceFile, cb);
|
73 | }
|
74 |
|
\ | No newline at end of file |