diff --git a/src/services/codefixes/unusedIdentifierFixes.ts b/src/services/codefixes/unusedIdentifierFixes.ts index 0ca01a81eb1..3e74f81d8aa 100644 --- a/src/services/codefixes/unusedIdentifierFixes.ts +++ b/src/services/codefixes/unusedIdentifierFixes.ts @@ -150,7 +150,20 @@ namespace ts.codefix { } function createCodeFixToRemoveNode(node: Node) { - return createCodeFix("", node.getStart(), node.getWidth()); + let end = node.getEnd(); + const endCharCode = sourceFile.text.charCodeAt(end); + const afterEndCharCode = sourceFile.text.charCodeAt(end + 1); + if (isLineBreak(endCharCode)) { + end += 1; + } + // in the case of CR LF, you could have two consecutive new line characters for one new line. + // this needs to be differenciated from two LF LF chars that actually mean two new lines. + if (isLineBreak(afterEndCharCode) && endCharCode !== afterEndCharCode) { + end += 1; + } + + const start = node.getStart(); + return createCodeFix("", start, end - start); } function findFirstNonSpaceCharPosStarting(start: number) {