Running "Remove Duplicate Lines" without a selection (whole file) removes the file's final newline.
dedupe() does lines = self.view.substr(selection).splitlines() and text = "\n".join(OrderedDict.fromkeys(lines)); splitlines() drops the trailing line break and "\n".join() doesn't add one back, so a buffer that ended with \n no longer does.
Reproduced in Sublime Text 4200 (Windows 11), RemoveDuplicateLines 2.1.1 from Package Control, on a scratch view, no selection:
'a\nb\na\nc\nb\n' -> 'a\nb\nc' # expected 'a\nb\nc\n'
'a\nb\na' -> 'a\nb' # (no final newline in, none out: fine)
Most text files (and Git) expect a final newline, so the command turns a clean file into "\ No newline at end of file" in diffs. (Selections that include the final newline of their last line behave correctly, e.g. the first three lines of the buffer above keep their newline.)
Fix: remember whether the region ended with a line break (self.view.substr(selection).endswith(("\n", "\r"))) and append "\n" to text in that case (or use split("\n") semantics instead of splitlines()).
Found while testing packages from the Package Control catalog.
Running "Remove Duplicate Lines" without a selection (whole file) removes the file's final newline.
dedupe()doeslines = self.view.substr(selection).splitlines()andtext = "\n".join(OrderedDict.fromkeys(lines));splitlines()drops the trailing line break and"\n".join()doesn't add one back, so a buffer that ended with\nno longer does.Reproduced in Sublime Text 4200 (Windows 11), RemoveDuplicateLines 2.1.1 from Package Control, on a scratch view, no selection:
Most text files (and Git) expect a final newline, so the command turns a clean file into "\ No newline at end of file" in diffs. (Selections that include the final newline of their last line behave correctly, e.g. the first three lines of the buffer above keep their newline.)
Fix: remember whether the region ended with a line break (
self.view.substr(selection).endswith(("\n", "\r"))) and append"\n"totextin that case (or usesplit("\n")semantics instead ofsplitlines()).Found while testing packages from the Package Control catalog.