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
Trim trailing whitespace only on changed lines #13157
Comments
Why does it matter if trailing whitespace is removed for lines you didn't change? |
I think https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig does this if you want to try that out. |
Because it leads to noisy diffs in code reviews. Also makes the change looks bigger when you inspect history.
Hmm... I see it mention |
Ah ignore me actually, I misread the issue. I set it as a feature request, you should be able to build an extension to do this. |
Yeah that would definitely be handy, I normally just disable trimming all together on such code bases and just try to be careful. |
A set of string settings similar to the
|
Yea, that's what I end up doing as well. But then also miss the opportunity to clean up when for instance a piece of code is copy/pasted etc. The main reason I post this request is that the default in VS Code is now to trim - which means you either need to set it to off on all installations of VSC that you do. Or remember to set it every time you set up VSC for an existing project. In searching for this I found a number of threads where the debate seemed surprisingly strong on both sides for on/off. Each side has its merits. But I think a default of trim only changed lines is a nice compromise. It answers to both sides of the debate - pragmatic approach. |
You can ignore all whitespace:
|
That doesn't apply to code review tools though. Most probably will have an option to adjust that - but you don't always have control over that. (Organisation policy etc.) Further more, ignoring all white-space isn't ideal either, as you want to catch space/tab changes etc. |
Based on #17883 I'd be surprised if this gets implemented. However, the Trailing Spaces extension does the job quite well with this setting:
It can also trim on demand or automatically on save. |
@bmaupin, the Trailing Spaces extension looks promising, but doesn't seem to work when enabling the |
I tend to work with "remove trailing space" enabled, then, after |
Hi. When will we see option to remove trailing spaces on save but only for modified lines? |
While we're at it, please upvote this as well: editorconfig/editorconfig#366 There's so many editors and tools that totally ignore this feature, and think it's okay to modify thousands of lines of existing code, just because a single line of code is changed. |
I'm new to VS Code, and when I go to the Trailing Spaces extension settings page in the UI, it was empty... the extension page talks about configuration via JSON which I don't know where or how to do. So ultimately, I got what I needed (highlighting of trailing whitespaces + auto-trim trailing white space of modified lines only upon save) with Trailing Whitespace extension, which does have easy-to-use and understand GUI Settings: |
I had the exact opposite issue. Having read your post I immediately tried installing the TWS extension and couldn't find its settings. Removed it, installed Trailing Spaces and it showed up in the settings right after installation. strange. |
You may also consider (both for an implementation idea or for your own use) the AutoTrim by chrisant996 extension. It works in a different and simpler way than similar addons: it tracks the line where cursor is, it detects if you've modified it and it removes trailing whitespace when you move away from it. |
Another point that I believe hasn't been mentioned yet - automatically trimming trailing whitespace on all lines can make git-blame less useful, because then git-blame can report the last person to touch a line of code when in fact it was only that person's editor that touched the line to trim the whitespace. |
5 days ago this ticket celebrated 5 years anniversary. |
@Tom-Bonnike How does it have anything to do with this feature request? |
Hi there, I just got here after about 20 years in $OTHER_EDITOR, and want to mention that this issue is one of the very few things that make me want to open up the old editor. There are a number of projects that have trailing whitespace that I may not always fix up (at least, not in the same patch/commit), when fixing a bug or adding a tiny feature. Running with "trim whitespace only on changed lines" has made my life very comfortable for a long time, but right now, it's gone. Please please add this feature! |
https://marketplace.visualstudio.com/items?itemName=shardulm94.trailing-spaces Use:
From docs, "[Trim on save] abides by the other settings." With above config, I believe only modified lines (since last save) are trimmed on every save. |
Yes, thank you. That works (in fact, I eventually found that extension and have those same settings right now, so I feel validated, haha). I think I'm just slow to catch on to the idea of "basic VS Code core behavior, and anything you want can be changed via extensions". That works. |
The Trailing spaces extension is a live-saver! I would highly recommend Microsoft to add this feature in built-in settings. |
FYI for you guys who haven't got the expected result, before using the extension config, try to disable config |
Any update on this as a built-in setting? |
Feature Request:
When working with existing old code base it's not ideal to have the whole file trimmed for trailing whitespace. However, it's still a nice feature to have active for changed lines. That way the codebase will be cleaned up as you work on it.
The text was updated successfully, but these errors were encountered: