diff options
Diffstat (limited to 'node_modules/tslint/lib/rules/oneLineRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/oneLineRule.js | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/node_modules/tslint/lib/rules/oneLineRule.js b/node_modules/tslint/lib/rules/oneLineRule.js index be8ebd0c6..08d1ef212 100644 --- a/node_modules/tslint/lib/rules/oneLineRule.js +++ b/node_modules/tslint/lib/rules/oneLineRule.js @@ -17,6 +17,7 @@ */ Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); +var tsutils_1 = require("tsutils"); var ts = require("typescript"); var Lint = require("../index"); var OPTION_BRACE = "check-open-brace"; @@ -33,32 +34,32 @@ var Rule = (function (_super) { var oneLineWalker = new OneLineWalker(sourceFile, this.getOptions()); return this.applyWithWalker(oneLineWalker); }; + /* tslint:disable:object-literal-sort-keys */ + Rule.metadata = { + ruleName: "one-line", + description: "Requires the specified tokens to be on the same line as the expression preceding them.", + optionsDescription: (_a = ["\n Five arguments may be optionally provided:\n\n * `\"", "\"` checks that `catch` is on the same line as the closing brace for `try`.\n * `\"", "\"` checks that `finally` is on the same line as the closing brace for `catch`.\n * `\"", "\"` checks that `else` is on the same line as the closing brace for `if`.\n * `\"", "\"` checks that an open brace falls on the same line as its preceding expression.\n * `\"", "\"` checks preceding whitespace for the specified tokens."], _a.raw = ["\n Five arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks that \\`catch\\` is on the same line as the closing brace for \\`try\\`.\n * \\`\"", "\"\\` checks that \\`finally\\` is on the same line as the closing brace for \\`catch\\`.\n * \\`\"", "\"\\` checks that \\`else\\` is on the same line as the closing brace for \\`if\\`.\n * \\`\"", "\"\\` checks that an open brace falls on the same line as its preceding expression.\n * \\`\"", "\"\\` checks preceding whitespace for the specified tokens."], Lint.Utils.dedent(_a, OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE, OPTION_BRACE, OPTION_WHITESPACE)), + options: { + type: "array", + items: { + type: "string", + enum: [OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE, OPTION_BRACE, OPTION_WHITESPACE], + }, + minLength: 0, + maxLength: 5, + }, + optionExamples: [[true, OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE]], + type: "style", + typescriptOnly: false, + }; + /* tslint:enable:object-literal-sort-keys */ + Rule.BRACE_FAILURE_STRING = "misplaced opening brace"; + Rule.CATCH_FAILURE_STRING = "misplaced 'catch'"; + Rule.ELSE_FAILURE_STRING = "misplaced 'else'"; + Rule.FINALLY_FAILURE_STRING = "misplaced 'finally'"; + Rule.WHITESPACE_FAILURE_STRING = "missing whitespace"; return Rule; }(Lint.Rules.AbstractRule)); -/* tslint:disable:object-literal-sort-keys */ -Rule.metadata = { - ruleName: "one-line", - description: "Requires the specified tokens to be on the same line as the expression preceding them.", - optionsDescription: (_a = ["\n Five arguments may be optionally provided:\n\n * `\"", "\"` checks that `catch` is on the same line as the closing brace for `try`.\n * `\"", "\"` checks that `finally` is on the same line as the closing brace for `catch`.\n * `\"", "\"` checks that `else` is on the same line as the closing brace for `if`.\n * `\"", "\"` checks that an open brace falls on the same line as its preceding expression.\n * `\"", "\"` checks preceding whitespace for the specified tokens."], _a.raw = ["\n Five arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks that \\`catch\\` is on the same line as the closing brace for \\`try\\`.\n * \\`\"", "\"\\` checks that \\`finally\\` is on the same line as the closing brace for \\`catch\\`.\n * \\`\"", "\"\\` checks that \\`else\\` is on the same line as the closing brace for \\`if\\`.\n * \\`\"", "\"\\` checks that an open brace falls on the same line as its preceding expression.\n * \\`\"", "\"\\` checks preceding whitespace for the specified tokens."], Lint.Utils.dedent(_a, OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE, OPTION_BRACE, OPTION_WHITESPACE)), - options: { - type: "array", - items: { - type: "string", - enum: [OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE, OPTION_BRACE, OPTION_WHITESPACE], - }, - minLength: 0, - maxLength: 5, - }, - optionExamples: [[true, OPTION_CATCH, OPTION_FINALLY, OPTION_ELSE]], - type: "style", - typescriptOnly: false, -}; -/* tslint:enable:object-literal-sort-keys */ -Rule.BRACE_FAILURE_STRING = "misplaced opening brace"; -Rule.CATCH_FAILURE_STRING = "misplaced 'catch'"; -Rule.ELSE_FAILURE_STRING = "misplaced 'else'"; -Rule.FINALLY_FAILURE_STRING = "misplaced 'finally'"; -Rule.WHITESPACE_FAILURE_STRING = "missing whitespace"; exports.Rule = Rule; var OneLineWalker = (function (_super) { tslib_1.__extends(OneLineWalker, _super); @@ -234,15 +235,8 @@ var OneLineWalker = (function (_super) { } }; OneLineWalker.prototype.handleClassLikeDeclaration = function (node) { - var lastNodeOfDeclaration = node.name; var openBraceToken = Lint.childOfKind(node, ts.SyntaxKind.OpenBraceToken); - if (node.heritageClauses != null) { - lastNodeOfDeclaration = node.heritageClauses[node.heritageClauses.length - 1]; - } - else if (node.typeParameters != null) { - lastNodeOfDeclaration = node.typeParameters[node.typeParameters.length - 1]; - } - this.handleOpeningBrace(lastNodeOfDeclaration, openBraceToken); + this.handleOpeningBrace(tsutils_1.getPreviousToken(openBraceToken), openBraceToken); }; OneLineWalker.prototype.handleIterationStatement = function (node) { // last child is the statement, second to last child is the close paren |