fix(36102): fix extra new line in Organize Imports (#36911)

Organize Imports was inserting extra newline.

Fixes #36102
This commit is contained in:
Sachin Grover 2020-03-13 03:21:48 +05:30 committed by GitHub
parent 3d76c37cbe
commit bff0ddc941
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -889,7 +889,9 @@ namespace ts.textChanges {
: format(change.node);
// strip initial indentation (spaces or tabs) if text will be inserted in the middle of the line
const noIndent = (options.preserveLeadingWhitespace || options.indentation !== undefined || getLineStartPositionForPosition(pos, sourceFile) === pos) ? text : text.replace(/^\s+/, "");
return (options.prefix || "") + noIndent + (options.suffix || "");
return (options.prefix || "") + noIndent
+ ((!options.suffix || endsWith(noIndent, options.suffix))
? "" : options.suffix);
}
function getFormatCodeSettingsForWriting({ options }: formatting.FormatContext, sourceFile: SourceFile): FormatCodeSettings {