Skip to content
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 7 commits into from Nov 12, 2022
Merged

Commits on Oct 21, 2022

  1. 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 <aaossa@uc.cl>
    aaossa committed Oct 21, 2022
    Copy the full SHA
    74861f0 View commit details
    Browse the repository at this point in the history

Commits on Oct 24, 2022

  1. 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 <aaossa@uc.cl>
    aaossa committed Oct 24, 2022
    Copy the full SHA
    7a1e0e7 View commit details
    Browse the repository at this point in the history
  2. Update CHANGES.md

    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 <aaossa@uc.cl>
    aaossa committed Oct 24, 2022
    Copy the full SHA
    1a409b2 View commit details
    Browse the repository at this point in the history

Commits on Oct 26, 2022

  1. Copy the full SHA
    a2150e9 View commit details
    Browse the repository at this point in the history

Commits on Nov 11, 2022

  1. 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 <aaossa@uc.cl>
    aaossa committed Nov 11, 2022
    Copy the full SHA
    c842d58 View commit details
    Browse the repository at this point in the history
  2. 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 <aaossa@uc.cl>
    aaossa committed Nov 11, 2022
    Copy the full SHA
    a8f6841 View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    58739ae View commit details
    Browse the repository at this point in the history