-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
When fixable rules are overlapping, It takes multiple format/fix commands to reach the same result as cli xo --fix #113
Comments
The extensions does not run things any differently than the CLI. There is no prettier or eslint step, they are both ran at the same time by eslint under the hood in xo.
Please let me know if this fixes the issue. |
Setting the "edits": {
"[0,0,0,21]-simple-import-sort/imports": {
"label": "Fix this simple-import-sort/imports problem",
"documentVersion": 13,
"ruleId": "simple-import-sort/imports",
"edit": {
"range": [ 0, 21 ],
"text": "import {a,b} from 'file'"
}
},
"[0,8,0,11]-prettier/prettier": {
"label": "Fix this prettier/prettier problem",
"documentVersion": 13,
"ruleId": "prettier/prettier",
"edit": {
"range": [ 8, 11],
"text": " b, a "
}
},
"result": {
"documentVersion": 13,
"edits": [
{
"range": { "start": { "line": 0, "character": 0 }, "end": { "line": 0, "character": 21 }
},
"newText": "import {a,b} from 'file'"
}
]
} The VSCode runs the fix at the same time and output an overlap free result. I guess the xo cmd runs the fix in sequence. |
@gutenye - thank you so much for digging into this problem. I will look more deeply into this and see if I need to strip out some of the old overlap logic to keep things more consistent with the cli. |
So after taking a look I realized that this is just a known issue. There is actually not a core problem, you just have to run format 2x to get the same results as the CLI for some overlapping rules. This is something I am interested in fixing long term, but it's not a very high priority since the work around is just executing format 2x. This is a duplicate of #42 Unfortunately, solving this issue is not as trivial as "run x before y" - we will need to recreate the same logic that eslint already uses to handle cases where a single line has overlapping fixes and I believe it's complicated. I will keep this open until I have time to fix, but this will likely remain a low priority since its a very minor inconvenience and the extension still gets to the same final result after a couple of format commands. |
Save two or more times is not an option for me, every time I save a file, I have to take extra time to check if there's still eslint error? If so, save it again, if not, skip it. It's slow and not developer-friendly. Will this solution be easier? Add a The Eslint VSCode Exension has this option
The VSCode will run
Another idea, can we change vscode-linter-xo/server/server.js Line 684 in 736f91e
to const result = await xo.lintText(contents, { ...options, fix: true });
result contains the overlay-free text. when we perform a fix. This one does not need to recreate the same logic. |
eslint suffers from this too, but is admittedly a little better than this xo extension --- try formatting big unformatted files with eslint, xo + unicorn plugins and prettier. -- You will have to save multiple times. Also, it doesn't happen very often in this extension at all, it is not nearly as inconvenient as you are making it out to be.
Maybe - this is on the road map. I have recently started supporting code actions, but I haven't done the code actions on save. Feel free to take a look at the LSP spec and implement this. I don't really think this will be any simpler, it will still have to deal with the overlapping problem.
Feel free to test this out! I will play with this idea. My suspicion is that this will not work well at all because it will cause the squiggly error underlines in vscode to be in the wrong places, or results won't return all the correct information for the original errors, so it will be missing errors and flagging the wrong places. Note that every lint error already has the "fixed" result in it, if it is fixable, even without the "fix" option. The likely only way to really fix this is to manually implement logic in And please trust me that I have attempted to fix this problem on numerous occasions because I do know it is annoying when it happens, but I haven't found an easy way yet. I do accept PRs, although I have only got 1 I think since taking over maintenance of this extension. |
Was able to get it working in the latest release so that this should no longer occur, thanks for the suggestions |
The .xo-config.cjs
Using eslint-plugin-simple-import-sort
This code
is formatted into below using VSCode
Format Document with - XO
is formatted into below using Cmd
xo --fix
The result is different.
I guess the Cmd runs
eslint fix -> prettier
in order, but the VSCode runseslint fix
only.The text was updated successfully, but these errors were encountered: