vscode-linter-xo icon indicating copy to clipboard operation
vscode-linter-xo copied to clipboard

Deletes code if previous line has trailing spaces/tabs

Open melusc opened this issue 3 years ago • 6 comments

If you have something like this (note the trailing tabs on the first line):

				
veryLongFunction();

and you format it using the extension it removes the trailing tabs and cuts off a bit of the next line. The result is something like this:

ryLongFunction();

If you use xo from the cli it doesn't cut off anything, and if you use [email protected] it doesn't either.

I tried v3.3.1 and v3.3.2 and both behaved like this. v3.3.0 crashes for me because I use Windows but I'd guess the bug snuck in there.

I have created a repo with a minimal reproducible example: https://github.com/melusc/vscode-xo-indent-bug.

melusc avatar Oct 16 '21 10:10 melusc

This only happens if you have files.trimFinalNewlines set to true.

melusc avatar Oct 16 '21 10:10 melusc

@melusc thank you for the detailed bug report. Unfortunately I couldn't repro this behavior, even in the linked repro and tested after toggling all the final new line options and trying to make changes and apply fixes very quickly.

question 1 - what command do you use to format? Do you use "xo: fix all fixable problems" or do you use "format document" with xo enabled as the default formatter?

I added a debounce to the linting in 3.3+ which helps performance, but may be causing some random regressions. I am going to be releasing another update today which makes that configurable. Perhaps turning that off will fix this for you (and this may be a broader windows problem).

In the meantime, let me know if you can narrow it down any further!

spence-s avatar Oct 16 '21 14:10 spence-s

question 1 - what command do you use to format? Do you use "xo: fix all fixable problems" or do you use "format document" with xo enabled as the default formatter?

If I use "xo: fix all fixable problems" or "format document" it works perfectly, the issue occurs when I save, because I have format on save enabled and xo is the default formatter. That means that it must be running "trim trailing whitespace" and xo at the same time which must be causing issues.

I also noticed that I copied the wrong setting-name in my previous comment, the conflict only occurs with "files.trimTrailingWhitespace" enabled.

melusc avatar Oct 16 '21 16:10 melusc

I tried removing all the settings that didn't change this behaviour and I ended up with

{
  "[javascript]": {
    "editor.defaultFormatter": "samverschueren.linter-xo"
  },
  "editor.formatOnSave": true,
  "xo.format.enable": true,
  "files.trimTrailingWhitespace": true
}

melusc avatar Oct 16 '21 17:10 melusc

Thank you - I can reproduce this now. And confirmed it is indeed the debounce that causes this - although I am not quite sure why. It may be a VSCode bug for this race condition to be possible. I am going to be releasing a new version later today with the debounce off by default and configurable for large file performance and this will solve this. I will let you know when I do.

spence-s avatar Oct 16 '21 17:10 spence-s

@melusc - I just published 3.4.0 which defaults the debounce to 0 and fixes this issue. I recommend in the docs that you don't use these options together anymore. I'm going to leave this open as there may still be an issue on our side that can resolve this even with debounce turned on. Thanks!

spence-s avatar Oct 18 '21 17:10 spence-s