diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/tslint/lib/rules/alignRule.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/tslint/lib/rules/alignRule.js')
-rw-r--r-- | node_modules/tslint/lib/rules/alignRule.js | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/node_modules/tslint/lib/rules/alignRule.js b/node_modules/tslint/lib/rules/alignRule.js index d86f2f550..7d70b9229 100644 --- a/node_modules/tslint/lib/rules/alignRule.js +++ b/node_modules/tslint/lib/rules/alignRule.js @@ -39,30 +39,30 @@ var Rule = (function (_super) { statements: this.ruleArguments.indexOf(OPTION_STATEMENTS) !== -1, })); }; + /* tslint:disable:object-literal-sort-keys */ + Rule.metadata = { + ruleName: "align", + description: "Enforces vertical alignment.", + hasFix: true, + rationale: "Helps maintain a readable, consistent style in your codebase.", + optionsDescription: (_a = ["\n Five arguments may be optionally provided:\n\n * `\"", "\"` checks alignment of function parameters.\n * `\"", "\"` checks alignment of function call arguments.\n * `\"", "\"` checks alignment of statements.\n * `\"", "\"` checks alignment of members of classes, interfaces, type literal, object literals and\n object destructuring.\n * `\"", "\"` checks alignment of elements of array iterals, array destructuring and tuple types."], _a.raw = ["\n Five arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks alignment of function parameters.\n * \\`\"", "\"\\` checks alignment of function call arguments.\n * \\`\"", "\"\\` checks alignment of statements.\n * \\`\"", "\"\\` checks alignment of members of classes, interfaces, type literal, object literals and\n object destructuring.\n * \\`\"", "\"\\` checks alignment of elements of array iterals, array destructuring and tuple types."], Lint.Utils.dedent(_a, OPTION_PARAMETERS, OPTION_ARGUMENTS, OPTION_STATEMENTS, OPTION_MEMBERS, OPTION_ELEMENTS)), + options: { + type: "array", + items: { + type: "string", + enum: [OPTION_ARGUMENTS, OPTION_ELEMENTS, OPTION_MEMBERS, OPTION_PARAMETERS, OPTION_STATEMENTS], + }, + minLength: 1, + maxLength: 5, + }, + optionExamples: [[true, "parameters", "statements"]], + type: "style", + typescriptOnly: false, + }; + /* tslint:enable:object-literal-sort-keys */ + Rule.FAILURE_STRING_SUFFIX = " are not aligned"; return Rule; }(Lint.Rules.AbstractRule)); -/* tslint:disable:object-literal-sort-keys */ -Rule.metadata = { - ruleName: "align", - description: "Enforces vertical alignment.", - hasFix: true, - rationale: "Helps maintain a readable, consistent style in your codebase.", - optionsDescription: (_a = ["\n Five arguments may be optionally provided:\n\n * `\"", "\"` checks alignment of function parameters.\n * `\"", "\"` checks alignment of function call arguments.\n * `\"", "\"` checks alignment of statements.\n * `\"", "\"` checks alignment of members of classes, interfaces, type literal, object literals and\n object destructuring.\n * `\"", "\"` checks alignment of elements of array iterals, array destructuring and tuple types."], _a.raw = ["\n Five arguments may be optionally provided:\n\n * \\`\"", "\"\\` checks alignment of function parameters.\n * \\`\"", "\"\\` checks alignment of function call arguments.\n * \\`\"", "\"\\` checks alignment of statements.\n * \\`\"", "\"\\` checks alignment of members of classes, interfaces, type literal, object literals and\n object destructuring.\n * \\`\"", "\"\\` checks alignment of elements of array iterals, array destructuring and tuple types."], Lint.Utils.dedent(_a, OPTION_PARAMETERS, OPTION_ARGUMENTS, OPTION_STATEMENTS, OPTION_MEMBERS, OPTION_ELEMENTS)), - options: { - type: "array", - items: { - type: "string", - enum: [OPTION_ARGUMENTS, OPTION_ELEMENTS, OPTION_MEMBERS, OPTION_PARAMETERS, OPTION_STATEMENTS], - }, - minLength: 1, - maxLength: 5, - }, - optionExamples: [[true, "parameters", "statements"]], - type: "style", - typescriptOnly: false, -}; -/* tslint:enable:object-literal-sort-keys */ -Rule.FAILURE_STRING_SUFFIX = " are not aligned"; exports.Rule = Rule; var AlignWalker = (function (_super) { tslib_1.__extends(AlignWalker, _super); @@ -73,7 +73,7 @@ var AlignWalker = (function (_super) { var _this = this; var cb = function (node) { if (_this.options.statements && tsutils_1.isBlockLike(node)) { - _this.checkAlignment(node.statements.filter(function (s) { return !tsutils_1.isEmptyStatement(s); }), OPTION_STATEMENTS); + _this.checkAlignment(node.statements.filter(function (s) { return s.kind !== ts.SyntaxKind.EmptyStatement; }), OPTION_STATEMENTS); } else { switch (node.kind) { @@ -123,7 +123,11 @@ var AlignWalker = (function (_super) { } break; case ts.SyntaxKind.ClassDeclaration: - case ts.SyntaxKind.ClassDeclaration: + case ts.SyntaxKind.ClassExpression: + if (_this.options.members) { + _this.checkAlignment(node.members.filter(function (m) { return m.kind !== ts.SyntaxKind.SemicolonClassElement; }), OPTION_MEMBERS); + } + break; case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.TypeLiteral: if (_this.options.members) { @@ -151,7 +155,7 @@ var AlignWalker = (function (_super) { if (line !== pos.line && pos.character !== alignToColumn) { var diff = alignToColumn - pos.character; var fix = void 0; - if (0 < diff) { + if (diff >= 0) { fix = Lint.Replacement.appendText(start, " ".repeat(diff)); } else if (node.pos <= start + diff && /^\s+$/.test(sourceFile.text.substring(start + diff, start))) { |