Skip to content
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
7 changes: 7 additions & 0 deletions src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,13 @@ function isSemicolonDeletionContext(context: FormattingContext): boolean {
|| nextTokenKind === SyntaxKind.EndOfFileToken;
}

if (
nextTokenKind === SyntaxKind.SemicolonToken &&
context.currentTokenSpan.kind === SyntaxKind.SemicolonToken
) {
return true;
}

if (
nextTokenKind === SyntaxKind.SemicolonClassElement ||
nextTokenKind === SyntaxKind.SemicolonToken
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/fourslash/formatRemoveSemicolons1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class C {
["p"]
zero: void
["one"] = {};
["two"];
["two"]
;
}
a;
\`b\`
b;
(3)
4;
/ regex /;
/ regex /
;
[];
/** blah */[0]
Expand Down
48 changes: 48 additions & 0 deletions tests/cases/fourslash/formatRemoveSemicolons4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/// <reference path="fourslash.ts" />

////declare const opt: number | undefined;
////
////const a = 1;
////const b = 2;
////;[1, 2, 3]
////
////const c = opt ? 1 : 2;
////const d = opt ? 1 : 2;
////;[1, 2, 3]
////
////const e = opt ?? 1;
////const f = opt ?? 1;
////;[1, 2, 3]
////
////type a = 1;
////type b = 2;
////;[1, 2, 3]
////
////type c = typeof opt extends 1 ? 1 : 2;
////type d = typeof opt extends 1 ? 1 : 2;
////;[1, 2, 3]

format.setFormatOptions({ ...format.copyFormatOptions(), semicolons: ts.SemicolonPreference.Remove });
format.document();
verify.currentFileContentIs(
`declare const opt: number | undefined

const a = 1
const b = 2
;[1, 2, 3]

const c = opt ? 1 : 2
const d = opt ? 1 : 2
;[1, 2, 3]

const e = opt ?? 1
const f = opt ?? 1
;[1, 2, 3]

type a = 1
type b = 2
;[1, 2, 3]

type c = typeof opt extends 1 ? 1 : 2
type d = typeof opt extends 1 ? 1 : 2
;[1, 2, 3]`);