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.
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.
Why does it matter if trailing whitespace is removed for lines you didn't change?
Because it leads to noisy diffs in code reviews. Also makes the change looks bigger when you inspect history.
I think https://marketplace.visualstudio.com/items?itemName=EditorConfig.EditorConfig does this if you want to try that out.
Hmm... I see it mention trim_trailing_whitespace
, but nothing about limiting it to changed lines only.
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.
For reference on an editor that already have such feature: RubyMine (And the other JetBrain editors)
Think trimming changed lines only is the default - which I think is a nice default option. That means new files will get trimmed - and existing files doesn't end up with changes all over.
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 editor.renderWhitespace
setting would be good:
"files.trimTrailingWhitespace": "all" | "modified" | "off"
Yeah that would definitely be handy, I normally just disable trimming all together on such code bases and just try to be careful.
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.
Because it leads to noisy diffs in code reviews. Also makes the change looks bigger when you inspect history.
You can ignore all whitespace:
git diff other-branch -w
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:
"trailing-spaces.deleteModifiedLinesOnly": true,
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 trimOnSave
and deleteModifiedLinesOnly
settings. I've reported this problem, but for now it seems that we still don't have any way to get this functionality in VS Code.
I tend to work with "remove trailing space" enabled, then, after git add
use this trick to remove whitespace only lines changes.
@bmaupin, the Trailing Spaces extension looks promising, but doesn't seem to work when enabling the
trimOnSave
anddeleteModifiedLinesOnly
settings. I've reported this problem
Here's the ticket.
Hi.
I see VScode 1.49 has option format modified lines on save.
But what about trailing spaces?
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: https://github.com/editorconfig/editorconfig/issues/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.
Most helpful comment
A set of string settings similar to the
editor.renderWhitespace
setting would be good:"files.trimTrailingWhitespace": "all" | "modified" | "off"