Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

one-line: avoid crash on parse error #3538

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/rules/oneLineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ class OneLineWalker extends Lint.AbstractWalker<Options> {
case ts.SyntaxKind.InterfaceDeclaration:
case ts.SyntaxKind.ClassDeclaration:
case ts.SyntaxKind.ClassExpression: {
this.check(getChildOfKind(node, ts.SyntaxKind.OpenBraceToken, sourceFile)!);
const openBrace = getChildOfKind(node, ts.SyntaxKind.OpenBraceToken, sourceFile);
if (openBrace !== undefined) {
this.check(openBrace);
}
break;
}
case ts.SyntaxKind.IfStatement: {
Expand Down
13 changes: 13 additions & 0 deletions test/rules/one-line/all/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ if (true) {
} else {
false;
}

// don't crash on parse error
interface InvalidInterface = {
foo: string,
}

class InvalidClass = {
foo: string,
}

foo = class InvalidClassExpression = {
foo: string,
}
13 changes: 13 additions & 0 deletions test/rules/one-line/all/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,16 @@ if (true) {
~~~~ [missing whitespace]
false;
}

// don't crash on parse error
interface InvalidInterface = {
foo: string,
}

class InvalidClass = {
foo: string,
}

foo = class InvalidClassExpression = {
foo: string,
}