diff --git a/src/rules/alignRule.ts b/src/rules/alignRule.ts index 78c62a01b5e..ecb7828b56b 100644 --- a/src/rules/alignRule.ts +++ b/src/rules/alignRule.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { getNextToken, isBlockLike, isEmptyStatement } from "tsutils"; +import { getNextToken, isBlockLike } from "tsutils"; import * as ts from "typescript"; import * as Lint from "../index"; @@ -82,7 +82,7 @@ class AlignWalker extends Lint.AbstractWalker { public walk(sourceFile: ts.SourceFile) { const cb = (node: ts.Node): void => { if (this.options.statements && isBlockLike(node)) { - this.checkAlignment(node.statements.filter((s) => !isEmptyStatement(s)), OPTION_STATEMENTS); + this.checkAlignment(node.statements.filter((s) => s.kind !== ts.SyntaxKind.EmptyStatement), OPTION_STATEMENTS); } else { switch (node.kind) { case ts.SyntaxKind.NewExpression: @@ -131,12 +131,18 @@ class AlignWalker extends Lint.AbstractWalker { } break; case ts.SyntaxKind.ClassDeclaration: - case ts.SyntaxKind.ClassDeclaration: + case ts.SyntaxKind.ClassExpression: + if (this.options.members) { + this.checkAlignment( + (node as ts.ClassLikeDeclaration).members.filter((m) => m.kind !== ts.SyntaxKind.SemicolonClassElement), + OPTION_MEMBERS, + ); + } + break; case ts.SyntaxKind.InterfaceDeclaration: case ts.SyntaxKind.TypeLiteral: if (this.options.members) { - this.checkAlignment((node as ts.ClassLikeDeclaration | ts.InterfaceDeclaration | ts.TypeLiteralNode).members, - OPTION_MEMBERS); + this.checkAlignment((node as ts.InterfaceDeclaration | ts.TypeLiteralNode).members, OPTION_MEMBERS); } } } diff --git a/test/rules/align/members/test.ts.fix b/test/rules/align/members/test.ts.fix index b821cadb478..8b59a0a624e 100644 --- a/test/rules/align/members/test.ts.fix +++ b/test/rules/align/members/test.ts.fix @@ -7,11 +7,18 @@ interface Foo { class Foo { bar, - baz() {} + baz() { + + }; get bas() {} foo; } +let Bar = class { + bar, + foo +} + let foo = { foo, moep, diff --git a/test/rules/align/members/test.ts.lint b/test/rules/align/members/test.ts.lint index 72723c50462..51a20b69be1 100644 --- a/test/rules/align/members/test.ts.lint +++ b/test/rules/align/members/test.ts.lint @@ -2,42 +2,52 @@ interface Foo { bar, baz bas - ~~~ [members are not aligned] + ~~~ [0] foo; - ~~~~ [members are not aligned] + ~~~~ [0] } class Foo { bar, - baz() {} + baz() { + + }; get bas() {} - ~~~~~~~~~~~~ [members are not aligned] + ~~~~~~~~~~~~ [0] foo; - ~~~~ [members are not aligned] + ~~~~ [0] +} + +let Bar = class { + bar, + foo + ~~~ [0] } let foo = { foo, moep, baz, - ~~~ [members are not aligned] + ~~~ [0] baz: foo, - ~~~~~~~~ [members are not aligned] + ~~~~~~~~ [0] } let { foo, boo, baz, - ~~~ [members are not aligned] + ~~~ [0] baz, - ~~~ [members are not aligned] + ~~~ [0] } = foo; let foo: { foo bar - ~~~ [members are not aligned] + ~~~ [0] baz - ~~~ [members are not aligned] + ~~~ [0] } + +[0]: members are not aligned \ No newline at end of file