|
| 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 | +exports.__esModule = true; |
| 13 | +var ts = require("typescript"); |
| 14 | +var Lint = require("tslint"); |
| 15 | +var tsutils_1 = require("tsutils"); |
| 16 | +var Rule = /** @class */ (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 | + return this.applyWithWalker(new DiagnosticsWalker(sourceFile, this.getOptions())); |
| 23 | + }; |
| 24 | + Rule.NOT_BRACED = "Multi-line case clauses should be braced."; |
| 25 | + return Rule; |
| 26 | +}(Lint.Rules.AbstractRule)); |
| 27 | +exports.Rule = Rule; |
| 28 | +var DiagnosticsWalker = /** @class */ (function (_super) { |
| 29 | + __extends(DiagnosticsWalker, _super); |
| 30 | + function DiagnosticsWalker() { |
| 31 | + return _super !== null && _super.apply(this, arguments) || this; |
| 32 | + } |
| 33 | + DiagnosticsWalker.prototype.visitDefaultClause = function (node) { |
| 34 | + this.checkDefaultOrCaseClause(node); |
| 35 | + _super.prototype.visitDefaultClause.call(this, node); |
| 36 | + }; |
| 37 | + DiagnosticsWalker.prototype.visitCaseClause = function (node) { |
| 38 | + this.checkDefaultOrCaseClause(node); |
| 39 | + _super.prototype.visitCaseClause.call(this, node); |
| 40 | + }; |
| 41 | + DiagnosticsWalker.prototype.checkDefaultOrCaseClause = function (node) { |
| 42 | + var count = node.statements.length; |
| 43 | + if (count > 1) { |
| 44 | + this.addFailureAtNode(node, Rule.NOT_BRACED); |
| 45 | + } |
| 46 | + else if (count == 1) { |
| 47 | + var stmt = node.statements[0]; |
| 48 | + if (stmt.kind != ts.SyntaxKind.Block) { |
| 49 | + if (!tsutils_1.isSameLine(node.getSourceFile(), node.getStart(), stmt.getStart())) { |
| 50 | + this.addFailureAtNode(node, Rule.NOT_BRACED); |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + }; |
| 55 | + return DiagnosticsWalker; |
| 56 | +}(Lint.RuleWalker)); |
0 commit comments