Skip to content

Commit 80568c5

Browse files
committed
remove the new line after targeted line
1 parent dc78d33 commit 80568c5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/services/codefixes/unusedIdentifierFixes.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,20 @@ namespace ts.codefix {
150150
}
151151

152152
function createCodeFixToRemoveNode(node: Node) {
153-
return createCodeFix("", node.getStart(), node.getWidth());
153+
let end = node.getEnd();
154+
const endCharCode = sourceFile.text.charCodeAt(end);
155+
const afterEndCharCode = sourceFile.text.charCodeAt(end + 1);
156+
if (isLineBreak(endCharCode)) {
157+
end += 1;
158+
}
159+
// in the case of CR LF, you could have two consecutive new line characters for one new line.
160+
// this needs to be differenciated from two LF LF chars that actually mean two new lines.
161+
if (isLineBreak(afterEndCharCode) && endCharCode !== afterEndCharCode) {
162+
end += 1;
163+
}
164+
165+
const start = node.getStart();
166+
return createCodeFix("", start, end - start);
154167
}
155168

156169
function findFirstNonSpaceCharPosStarting(start: number) {

0 commit comments

Comments
 (0)