Skip to content

Commit 1e48057

Browse files
authored
fix(15398): skip adding line breaks when replacing JS checks directives (microsoft#38086)
1 parent 63ff657 commit 1e48057

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

src/services/codefixes/disableJsDiagnostics.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ namespace ts.codefix {
1616
return undefined;
1717
}
1818

19+
const newLineCharacter = sourceFile.checkJsDirective ? "" : getNewLineOrDefaultFromHost(host, formatContext.options);
1920
const fixes: CodeFixAction[] = [
2021
// fixId unnecessary because adding `// @ts-nocheck` even once will ignore every error in the file.
2122
createCodeFixActionWithoutFixAll(
2223
fixName,
2324
[createFileTextChanges(sourceFile.fileName, [
2425
createTextChange(sourceFile.checkJsDirective
2526
? createTextSpanFromBounds(sourceFile.checkJsDirective.pos, sourceFile.checkJsDirective.end)
26-
: createTextSpan(0, 0), `// @ts-nocheck${getNewLineOrDefaultFromHost(host, formatContext.options)}`),
27+
: createTextSpan(0, 0), `// @ts-nocheck${newLineCharacter}`),
2728
])],
2829
Diagnostics.Disable_checking_for_this_file),
2930
];
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowjs: true
4+
// @checkJs: true
5+
// @noEmit: true
6+
7+
// @filename: a.js
8+
////let x = "";
9+
////[|x|] = 1;
10+
11+
// verify.codeFixAvailable([
12+
// { description: ts.Diagnostics.Ignore_this_error_message.message },
13+
// { description: ts.Diagnostics.Disable_checking_for_this_file.message }
14+
// ]);
15+
16+
verify.codeFix({
17+
description: ts.Diagnostics.Disable_checking_for_this_file.message,
18+
index: 1,
19+
newFileContent:
20+
`// @ts-nocheck
21+
let x = "";
22+
x = 1;`,
23+
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowjs: true
4+
// @checkJs: true
5+
// @noEmit: true
6+
7+
// @filename: a.js
8+
////// @ts-check
9+
////let x = "";
10+
////[|x|] = 1;
11+
12+
// verify.codeFixAvailable([
13+
// { description: ts.Diagnostics.Ignore_this_error_message.message },
14+
// { description: ts.Diagnostics.Disable_checking_for_this_file.message }
15+
// ]);
16+
17+
verify.codeFix({
18+
description: ts.Diagnostics.Disable_checking_for_this_file.message,
19+
index: 1,
20+
newFileContent:
21+
`// @ts-nocheck
22+
let x = "";
23+
x = 1;`,
24+
});

0 commit comments

Comments
 (0)