-
Notifications
You must be signed in to change notification settings - Fork 336
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
'Fix all auto-fixable problems' doesn't fix as many issues as possible #154
Comments
Can confirm. It only does a single pass. |
The above example is handled fine by the JS formatter and we now support format on save in 1.6. Are there other examples than formatting of fixes that require multiple passes? |
Maybe the extension could run the formatter instead of autofix from the context menu if it handles this better. I haven't had this issue outside of dealing with white-space. |
Format on save requires that you have installed formatter extensions, which will run on each save.
Yes. when the errors are both stylistic and non-stylistic. Example:
Here line 5 has 2 errors: a And, in general, I can't rule out that there aren't other cases other than formatting that require multiple passes. The For reference, what the
So, my suggestion is to offer a user setting with which to implement ESLint '--fix' functionality as it is in CLI: |
@darkred Frankly, I cannot get warm for implementing formatting using a multi-pass linting approach. Formatters are great at formatting and I don't want to maintain separate settings for formatting and linting. See also https://medium.com/@Jakeherringbone/why-linting-makes-me-yawn-cadbd9a51ca9#.9tw56pje0 from @alexeagle by https://github.com/Microsoft/vscode-tslint/issues/84#issuecomment-246158200. For VS Code we have a commit hook that doesn't allow a check-in if there are formatting violations. This implemented using a formatter and not a linter. |
I'm afraid that might have been a misunderstanding here. To clarify: |
@darkred sorry, my comment was less about implementation. I've just reacted to the 'identity crisis' of linters vs formatters. I'll calm down now 😄
This would destroy markers like break points. The right way to do this is to diff the output with the current version and generate separate edits to create a minimal update, but @dbaeumer knows all about this... |
This behavior causes problems when performing a very common set of actions. If I have a code block nested inside another code block and delete the outer code block, then the inner block is now improperly indented. When I save the document, only the first level of the code block is moved to the correct indentation. Now any code within that block is incorrectly indented. |
As @egamma pointed out the fix should only provide a minimal edit set to keep as many markers in the file as possible. In addition the time a save participant has in VS Code is very limited. All participant have one second and if you are the guy who causes other to not run 3 times you will be disabled. So everything we do here in save participation must keep performance in mind. |
Per the discussion of preferring a formatter to do formatting: |
@alexeagle The following is just my opinion
|
I have to agree with @dsbert on this. I just deleted an outmost code block on a mocha file and had to run fix five times to fix my indenting down the chain. I could install and configure a separate formatter... but on the other hand eslint --fix does the job just fine. |
Does anyone of you know why eslint needs n rounds to fix up these things. Doing n rounds in the extension needs quite some coding since it is a pre save hook and all the modifications need to be described on the version of the document. The way how I understand the round concept in eslint is that fixes are applied like this fix(fix(fix(fix(n) which moves the document to version n + 4. So I can't simply take the fixes compute the rounds 2, 3, 4 and apply them to the document version n. Moreover I suspect that the edits might be overlapping and therefore a merge might not be possible. So the only save answer I see here is to run the fix rounds until I reach a fix point and then use a compare algorithm to compute a minimal edit set :-( |
@dbaeumer check eslint/eslint#5329 (comment), |
@darkred thanks for the pointers. Reading through it makes it clear that the n round approach is here to stay. So I will look into how we can best adopt this. One thing that is already clear is that I need to time budget this, given that a save participant can only run for so many ms. So it still might be the case that not all auto fixes are applied in one save. |
Personally I'm less worried about on save than when I run the command manually. Josh F Sent from On Wed, Nov 02, 2016 at 08:58 "Dirk Bäumer" <
a, pre, code, a:link, body { word-wrap: break-word !important; } https://github.com/darkred — You are receiving this because you are subscribed to this thread. Reply to this email directly, |
Is anyone still looking into this ? if not i might take a stab at it in the next few days |
A pull request is highly appreciated here. |
Any update about this issue? |
No update. PR is still welcome. |
@dbaeumer I've began taking a look at it. However, it seems we are doing loads of processing with the ranges reported by Eslint and it's really hard to figure out what's going on. function fixJob({ cliEngineOptions, contents, eslint, filePath }) {
const report = lintJob({ cliEngineOptions, contents, eslint, filePath })
eslint.CLIEngine.outputFixes(report)
if (!report.results.length || !report.results[0].messages.length) {
return 'Linter-ESLint: Fix complete.'
}
return 'Linter-ESLint: Fix attempt complete, but linting errors remain.'
} Basically just run validate on the file, get the report and pass it to outputFixes() cli method. Thoughts ? |
@arcanis and @nunogois it is already possible to fix this with VS Code ESLint + Prettier extension as I explained here in this post #154 (comment) It is a workaround but it works for now. Ideally one should not use the Prettier extension just to use the ESLint extension properly. Which is what this issue is about to fix. |
@arcanis also, potential performance is not the blocker here, it's the merging fixes logic mentioned above. I just mentioned performance since that should also be considered |
I've experienced this multiple save or exec of Can be reproduced on this repo: https://github.com/octref/veturpack Clone it, install deps, and open Hope it can be fixed one day, really annoying and makes manual or auto eslint fix unusable :( |
@bkucera are you still working on a pr? and is it solving the actual issue or just running fix a couple of times behind the scenes? (I would imagine that basing fixes on a list of rules might not be enough - so eslint should be able to provide the fix?) |
@raix running fix multiple times behind the scenes (until there are no more fixable problems left) which is what ESLint does via the cli. |
This issue can be solved by registering ESLint as a formatter rather than a command. I tried playing around with As you can see here, when I run the autofix command, the cursor, which used to be on line 2 on the word For comparison, here’s the original behavior — I had to run it several times, but here the cursor should stay at the word However, by registering ESLint as a document formatter (activated via “Format document” command instead), we can simply send the final code to VS Code, and it will diff the editor’s contents with the formatted code to compute the minimal changes to apply. As far as I know, this function is not exposed via the extension API anywhere except through the “Format document” command. I mentioned this about a year ago in this issue. Here, I updated the extension to register itself as a code formatter, and by calling the “Format document” command, the cursor stays at the correct position: |
Brilliant!
On Fri, Sep 20, 2019 at 9:38 AM Thai Pangsakulyanont < ***@***.***> wrote:
This issue can be solved by registering ESLint as a formatter rather than
a command.
I tried playing around with vscode-eslint’s source code and modified it
so that it takes the final output from eslint --fix and send the whole
formatted code back to VS Code (rather than sending individual fixes as
separate edit).
As you can see here, when I run the autofix command, the cursor, which
used to be on line 2 on the word arguments, immediately jumps down to the
bottom, since the whole editor’s content is replaced.
[image: after1]
<https://user-images.githubusercontent.com/193136/65342933-ff6c3080-dbfd-11e9-80ea-dcaf8f5eb3f8.gif>
For comparison, here’s the original behavior — I had to run it several
times, but here the cursor should stay at the word arguments and not jump
down to the bottom of the file.
[image: before]
<https://user-images.githubusercontent.com/193136/65343552-71914500-dbff-11e9-98ed-5512036c1c45.gif>
However, by registering ESLint as a document formatter (activated via
“Format document” command instead), we can simply send the final code to VS
Code, and it will diff the editor’s contents with the formatted code to
compute the minimal changes to apply
<https://github.com/microsoft/vscode/blob/66dc7a11b709c9353d6bb2fd144c7e088ad35ecf/src/vs/editor/common/services/editorSimpleWorker.ts#L445>.
As far as I know, this function is not exposed via the extension API
anywhere except through the “Format document” command. I mentioned this
about a year ago in this issue
<#154 (comment)>
.
Here, I updated the extension to register itself as a code formatter, and
by calling the “Format document” command, the cursor stays at the correct
position:
[image: after]
<https://user-images.githubusercontent.com/193136/65343294-d8fac500-dbfe-11e9-8a7f-20aa7fe4187c.gif>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#154?email_source=notifications&email_token=AAMT4BCJH2XHGF7LWV3BTWTQKT36RA5CNFSM4CSPNPJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7HH2CQ#issuecomment-533626122>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAMT4BGSL5PRZJMPGE7NJ4DQKT36RANCNFSM4CSPNPJA>
.
--
Best,
Spencer Carstens
|
PR to register vscode-eslint as document formatter submitted — #766 |
I don't want to pile on, just wondering: Is this related to the "toggling" behavior, where multiple saves will result in content switching among 2 or more formatted states? (I'm researching solutions for issue shown in the gifs here: https://github.com/tcg/vscode-eslint-prettier-autoformat-glitch) |
@tcg afaik this issue is unrelated to what you are experiencing. Your issue is a conflict of different formatters fighting for the right format. Just use ESLint with prettier config, and disable prettier itself. I.e. get ESLint CLI config to work properly with prettier and disable prettier ext. |
Thanks @moltar. Unfortunately I already “just” did that. I think. I’m reading your last two sentences as recommending opposite things. So , ESLint w/ eslint-prettier plugin and no Prettier extension (my current setup) ?? Or ESLint and Prettier extensions, somehow configured not to interfere w/ each other’s rules? |
@tcg no prettier extension, but running eslint --fix at save by your IDE or webpack. https://prettier.io/docs/en/integrating-with-linters.html |
@ThomasKientz Thanks for that clarification. Sorry to hijack! I started everything from scratch, and followed those directions (yesterday, and again this morning) and still seeing some weird behavior, but I now think it's specific to rules/code I'm looking at, and not across the board. I really appreciate the extra info! 👋 |
@tcg I think you're still going to see weird behavior. With the suggested "ESLint with prettier config", you'll need to save multiple times to get all your fixes run. (That's what this issue is about.) |
The issue still persists. :( Also, there are no other formatters installed, and my settings file looks like this: "eslint.autoFixOnSave": true, |
A new version with the fix is not released yet. You can run download and run this extension from source code in the meantime. |
I released 2.0.4 today which addresses this. Please note that for large file you need to increase the time budget to compute the fixes using |
Works so well! My life is completely changed! No more Cmd+S, Cmd+S, Cmd+S, Cmd+S 😂 ❤️ |
The fix is amazing, thank you! |
I have ESLint extension 1.0.7 with VSCode 1.6.0 in win10 x64
and ESLint 3.7.1 globally installed.
First of all, please note that since ESLint 2.9.0:
Let's say I have the following .eslintrc.js in
C:\Users\Kostas
:Now, I have this Javascript file:
If I do
eslint --fix myfile.js
via CLI (a single time) it will be fixed into:But, in VSCode the ``Eslint: Fix all auto-fixable problems` command doesn't fix all indentation at once:
executing it the first time will only fix indentation on line 3,
a second time fixes lines 4 + 9,
and finally a 3rd time fixes lines 5-8,
i.e. it requires multiple (3) executions.
For reference, in Atom with linter 1.11.18 and linter-eslint 8.0.0 using my global ESLint installation as well,
with the relevant command (
Linter eslint: Fix File
) all indentation is fixed with a single execution.The text was updated successfully, but these errors were encountered: