Skip to content

Commit

Permalink
one-line: Check block in case clause (palantir#3619)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-hanson authored and giladgray committed Jul 28, 2018
1 parent 1a0fe45 commit 629126f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/rules/oneLineRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class OneLineWalker extends Lint.AbstractWalker<Options> {
const cb = (node: ts.Node): void => {
switch (node.kind) {
case ts.SyntaxKind.Block:
if (!isBlockLike(node.parent!)) {
if (!isBlockLike(node.parent!)
|| node.parent!.kind === ts.SyntaxKind.CaseClause && (node.parent as ts.CaseClause).statements.length === 1) {
this.check({pos: node.pos, end: (node as ts.Block).statements.pos});
}
break;
Expand Down
3 changes: 2 additions & 1 deletion test/rules/one-line/all/test.ts.fix
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ for(var x= 0; x < 1; ++x) {
}

switch(y) {
case 0:
case 0: {
x--;
break;
}
default:
x++;
break;
Expand Down
3 changes: 3 additions & 0 deletions test/rules/one-line/all/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ switch(y)
{
~ [misplaced opening brace]
case 0:
{
~ [misplaced opening brace]
x--;
break;
}
default:
x++;
break;
Expand Down

0 comments on commit 629126f

Please sign in to comment.