diff options
Diffstat (limited to 'node_modules/tslint/lib/rules/noSwitchCaseFallThroughRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/noSwitchCaseFallThroughRule.js | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/node_modules/tslint/lib/rules/noSwitchCaseFallThroughRule.js b/node_modules/tslint/lib/rules/noSwitchCaseFallThroughRule.js index 94c570c29..db7d04575 100644 --- a/node_modules/tslint/lib/rules/noSwitchCaseFallThroughRule.js +++ b/node_modules/tslint/lib/rules/noSwitchCaseFallThroughRule.js @@ -32,20 +32,20 @@ var Rule = (function (_super) { Rule.prototype.apply = function (sourceFile) { return this.applyWithWalker(new NoSwitchCaseFallThroughWalker(sourceFile, this.ruleName, undefined)); }; + /* tslint:disable:object-literal-sort-keys */ + Rule.metadata = { + ruleName: "no-switch-case-fall-through", + description: "Disallows falling through case statements.", + descriptionDetails: (_a = ["\n For example, the following is not allowed:\n\n ```ts\n switch(foo) {\n case 1:\n someFunc(foo);\n case 2:\n someOtherFunc(foo);\n }\n ```\n\n However, fall through is allowed when case statements are consecutive or\n a magic `/* falls through */` comment is present. The following is valid:\n\n ```ts\n switch(foo) {\n case 1:\n someFunc(foo);\n /* falls through */\n case 2:\n case 3:\n someOtherFunc(foo);\n }\n ```"], _a.raw = ["\n For example, the following is not allowed:\n\n \\`\\`\\`ts\n switch(foo) {\n case 1:\n someFunc(foo);\n case 2:\n someOtherFunc(foo);\n }\n \\`\\`\\`\n\n However, fall through is allowed when case statements are consecutive or\n a magic \\`/* falls through */\\` comment is present. The following is valid:\n\n \\`\\`\\`ts\n switch(foo) {\n case 1:\n someFunc(foo);\n /* falls through */\n case 2:\n case 3:\n someOtherFunc(foo);\n }\n \\`\\`\\`"], Lint.Utils.dedent(_a)), + rationale: "Fall though in switch statements is often unintentional and a bug.", + optionsDescription: "Not configurable.", + options: null, + optionExamples: [true], + type: "functionality", + typescriptOnly: false, + }; return Rule; }(Lint.Rules.AbstractRule)); -/* tslint:disable:object-literal-sort-keys */ -Rule.metadata = { - ruleName: "no-switch-case-fall-through", - description: "Disallows falling through case statements.", - descriptionDetails: (_a = ["\n For example, the following is not allowed:\n\n ```ts\n switch(foo) {\n case 1:\n someFunc(foo);\n case 2:\n someOtherFunc(foo);\n }\n ```\n\n However, fall through is allowed when case statements are consecutive or\n a magic `/* falls through */` comment is present. The following is valid:\n\n ```ts\n switch(foo) {\n case 1:\n someFunc(foo);\n /* falls through */\n case 2:\n case 3:\n someOtherFunc(foo);\n }\n ```"], _a.raw = ["\n For example, the following is not allowed:\n\n \\`\\`\\`ts\n switch(foo) {\n case 1:\n someFunc(foo);\n case 2:\n someOtherFunc(foo);\n }\n \\`\\`\\`\n\n However, fall through is allowed when case statements are consecutive or\n a magic \\`/* falls through */\\` comment is present. The following is valid:\n\n \\`\\`\\`ts\n switch(foo) {\n case 1:\n someFunc(foo);\n /* falls through */\n case 2:\n case 3:\n someOtherFunc(foo);\n }\n \\`\\`\\`"], Lint.Utils.dedent(_a)), - rationale: "Fall though in switch statements is often unintentional and a bug.", - optionsDescription: "Not configurable.", - options: null, - optionExamples: [true], - type: "functionality", - typescriptOnly: false, -}; exports.Rule = Rule; var NoSwitchCaseFallThroughWalker = (function (_super) { tslib_1.__extends(NoSwitchCaseFallThroughWalker, _super); @@ -78,13 +78,10 @@ var NoSwitchCaseFallThroughWalker = (function (_super) { NoSwitchCaseFallThroughWalker.prototype.isFallThroughAllowed = function (clause) { var _this = this; var comments = ts.getLeadingCommentRanges(this.sourceFile.text, clause.end); - return comments !== undefined && comments.some(function (comment) { return commentText(comment, _this.sourceFile).trim() === "falls through"; }); + return comments !== undefined && + comments.some(function (comment) { return /^\s*falls through\b/i.test(_this.sourceFile.text.slice(comment.pos + 2, comment.end)); }); }; return NoSwitchCaseFallThroughWalker; }(Lint.AbstractWalker)); exports.NoSwitchCaseFallThroughWalker = NoSwitchCaseFallThroughWalker; -function commentText(_a, sourceFile) { - var pos = _a.pos, end = _a.end, kind = _a.kind; - return sourceFile.text.slice(pos + 2, kind === ts.SyntaxKind.MultiLineCommentTrivia ? end - 2 : end); -} var _a; |