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 trailing whitespace #1114

Closed
pylang opened this issue Oct 29, 2019 · 4 comments
Closed

Remove trailing whitespace #1114

pylang opened this issue Oct 29, 2019 · 4 comments
Labels
R: invalid This issue / pull request doesn't seem right

Comments

@pylang
Copy link

pylang commented Oct 29, 2019

Is your feature request related to a problem?

Running black (in VSCode) does not remove trailing whitespaces.

s = 'Hello world!"_ _

Describe the solution you'd like

Rather, I'd like black to remove trailing whitespace on all lines.

s = 'Hello world!"

Describe alternatives you've considered

I have to do a followup "Trim Whitespace" command in VSCode. I'd like this to be part of black by default.

There are some prior issues (#567) regarding trailing whitespace inside strings. Removing trailing whitespace by default can clean up code and even save some wasted space.

@pylang pylang added the T: enhancement New feature or request label Oct 29, 2019
@msgongora
Copy link

this can be fixed using vscode feature instead:

settings.json

"[python]": {
        "files.trimTrailingWhitespace": true,
    },
...

@ichard26
Copy link
Collaborator

Black already does this.

richard-26@ubuntu-laptop:~/programming/tools/ghprcl$ black test.py
reformatted test.py
All done! ✨ 🍰 ✨
1 file reformatted.
richard-26@ubuntu-laptop:~/programming/tools/ghprcl$ diff -u --color orig.py test.py
--- orig.py	2020-07-28 17:45:02.959401063 -0400
+++ test.py	2020-07-28 17:44:46.307273954 -0400
@@ -1 +1 @@
-s = "Hello world!"  
+s = "Hello world!"

BEFORE

Screenshot from 2020-07-28 17-57-26

and AFTER

Screenshot from 2020-07-28 17-58-15

This seems like a problem with how Visual Studio Code handling of diffs. Maybe related to this?


Environment:

  • OS version: Ubuntu 18.04.04 LTS
  • Python version: CPython 3.8.1
  • Black version: 19.10b0

@JelleZijlstra
Copy link
Collaborator

Closing as this is most likely an issue with VSCode, not Black.

@ichard26 ichard26 added R: not a bug This is deliberate behavior of Black. C: invalid code Black destroyed a valid Python file R: invalid This issue / pull request doesn't seem right and removed T: enhancement New feature or request R: not a bug This is deliberate behavior of Black. C: invalid code Black destroyed a valid Python file labels May 29, 2021
@rjurney
Copy link

rjurney commented Jan 16, 2024

Try these in <project_root>/.vscode/settings.json:

{
    "python.formatting.provider": "black",
    "[python]": {
        "files.trimTrailingWhitespace": true,
        "editor.formatOnSave": true
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: invalid This issue / pull request doesn't seem right
Projects
None yet
Development

No branches or pull requests

5 participants