bmatcuk / stylelint-lsp

A stylelint Language Server
MIT License
46 stars 4 forks source link

autoFix empty the file when there are syntax errors #2

Closed clyfish closed 4 years ago

clyfish commented 4 years ago

I've created a PR. #3

bmatcuk commented 4 years ago

Hey @clyfish, I think we jumped the gun. Did you test your change? As I went to write tests for it, I realized your change isn't correct. I'm going to revert it for now.

Do you have an example of a file that gets emptied when you run autoFix?

clyfish commented 4 years ago

I found the file gets emptied when it's a less or scss file. It's ok with css files.

a.less

a

b.scss

a {
}
b
clyfish commented 4 years ago

https://github.com/stylelint/stylelint/issues/4452 I've created an issue for stylelint.

Before they fix the bug, we can have a workaround.

  1. You format output to empty string
  2. When stylelint fixed the code successfully, output is updated to the fixed code, it can rarely be an empty string.

So, when output is empty string, stylelint doesn't done its job.

What a pity that stylelint use output for error message and fixed code.

bmatcuk commented 4 years ago

Hey @clyfish, I had a chance to try out a couple of your examples and I think I see the right way to fix this, or, at least, prevent it from clearing the file. I'll have a fix in the next day or so... have family things what with Thanksgiving.

bmatcuk commented 4 years ago

I just cut a new version, v1.0.3, that I think will avoid clearing the file if there's a syntax error. Let me know if you have any trouble with it.

clyfish commented 4 years ago

Plan A: if (result.ignored || output === "") { Plan B: if (errored || result.ignored || output === "") { I think plan A is better than plan B. When there's a syntax error in a css file, it gets fixed with plan A, but not with plan B. (errored === true, output !== "") When there's a syntax error in a less file, output is always empty, so it doesn't get fixed with plan A and plan B. (errored = true, output === "")

https://github.com/stylelint/stylelint/issues/4452#issuecomment-559436082

For CSS we use postcss-safe-parser, which could tolerate syntax errors. There is no such syntax for Less.

bmatcuk commented 4 years ago

Ah, you're right. I've updated the code and cut a new version.

clyfish commented 4 years ago

Thank you for the coc-stylelintplus tool.

Please update package.json and yarn.lock in coc-stylelintplus.

  1. coc.nvim version in package.json should set to 0.0.74 or neoclide/coc.nvim#9edc0ed (release branch)
  2. coc.nvim and stylelint-lsp version in yarn.lock should be updated.

I use vim-plug to install coc-stylelintplus, my nvim config:

Plug 'bmatcuk/coc-stylelintplus', {'do': 'yarn install --frozen-lockfile'}
bmatcuk commented 4 years ago

I've updated coc-stylelintplus. You could remove the --frozen-lockfile part to accomplish the same thing in the future.