-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove whitespaces of whitespace-only files #3348
Merged
Merged
Commits on Oct 21, 2022
-
Remove whitespaces of whitespace-only files
Currently, empty and whitespace-only (with or without newlines) are not modified. In some discussions (issues and pull requests) consesus 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 <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 74861f0 - Browse repository at this point
Copy the full SHA 74861f0View commit details
Commits on Oct 24, 2022
-
Test expected behavior on whitespace-only input
This commit introduces two tests and modifies other two tests. The introduced tests verify the expected behaviour on files containing a single newline character via 1) `format_str` and 2) `format_file_in_place`. In the other hand, the first modified test (`test_format_file_contents`) verify that `NothingChanged` is raised on files containing only a single newline, and that whitespace-only files are properly formatted to a single newline character. The second modified test (`test_reformat_one_with_stdin_empty`) validates the expected behavior when the input is passed via stdin. Before the fix introduced in the previous commit, these tests (and a couple of others) failed on cases covering whitespace-only files. Now, these tests are passed for all cases. Signed-off-by: Antonio Ossa Guerra <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 7a1e0e7 - Browse repository at this point
Copy the full SHA 7a1e0e7View commit details -
Add entry about new behavior on whitespace-only files: removing whitespace characters and return a single newline (if present) or an empty file Signed-off-by: Antonio Ossa Guerra <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 1a409b2 - Browse repository at this point
Copy the full SHA 1a409b2View commit details
Commits on Oct 26, 2022
-
Configuration menu - View commit details
-
Copy full SHA for a2150e9 - Browse repository at this point
Copy the full SHA a2150e9View commit details
Commits on Nov 11, 2022
-
Move whitespace-only behavior to preview style
The new criteria to reformat empty and whitespace-only files should go into the preview style Signed-off-by: Antonio Ossa Guerra <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for c842d58 - Browse repository at this point
Copy the full SHA c842d58View commit details -
Minor improvements on code readability
Adding comments on a non-intuitive behavior ar `_format_str_once`, and improving the `test_one_empty_line` test readability by using a pre-defined function that implements the same assertions Signed-off-by: Antonio Ossa Guerra <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for a8f6841 - Browse repository at this point
Copy the full SHA a8f6841View commit details -
Configuration menu - View commit details
-
Copy full SHA for 58739ae - Browse repository at this point
Copy the full SHA 58739aeView commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.