From: Antonio Ossa-Guerra Date: Sat, 12 Nov 2022 01:05:36 +0000 (-0300) Subject: Remove whitespaces of whitespace-only files (#3348) X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/d97b7898b34b67eb3c6839998920e17ac8c77908?ds=sidebyside;hp=d97b7898b34b67eb3c6839998920e17ac8c77908 Remove whitespaces of whitespace-only files (#3348) Currently, empty and whitespace-only (with or without newlines) are not modified. In some discussions (issues and pull requests) consensus was to reformat whitespace-only files to empty or single-character files, preserving line endings when possible. With that said, this commit introduces the following behaviors: * Empty files are left as is * Whitespace-only files (no newline) reformat into empty files * Whitespace-only files (1 or more newlines) reformat into a single newline character To implement these changes, we moved the initial check at `format_file_contents` that raises `NothingChanged` if the source (with no whitespaces) is an empty string. In the case of *.ipynb files, `format_ipynb_string` checks a similar condition and removed whitespaces. In the case of Python files, `format_str_once` includes a check on the output that returns the correct newline character if possible or an empty string otherwise. Signed-off-by: Antonio Ossa Guerra ---