Open DanKaplanSES opened 9 months ago
I am open for a PR to improve this. However, one thing we need to keep in mind that this can't be disturbing for users that open files that can't be linted. In the past we were too eager to warn the user about this and we got pushback since people do open JS code for which no ESLint is configured.
The code in question is around here: https://github.com/microsoft/vscode-eslint/blob/17e79c0f7bcd38f3033d0fbc346a5607fbb4c60f/server/src/eslint.ts#L881
Were we set silent to true if we probe support for the given file. If that files and we are in the probing run we don't print things to the suer. But I agree that a Info entry would be useful.
I am open for a PR to improve this. However, one thing we need to keep in mind that this can't be disturbing for users that open files that can't be linted. In the past we were too eager to warn the user about this and we got pushback since people do open JS code for which no ESLint is configured.
What do you think about falling back to a reasonable default eslint config if the file is not in the project? In other words, there may not be a need for an error message if it formats regardless.
Actually I am not a fan of a default. It is IMO in the longer term more confusing than helpful. The message of course should contain some links / text on how to create a config file or how to install eslint.
Not sure which extension is responsible for this behavior or which behavior is working incorrectly (if any), but I get interesting behavior when I use this extension: buenon.scratchpads.
In this extension, when you create a scratchpad it opens a new tab and pastes your clipboard into it. Immediately after, it appears that vscode-eslint formats the scratchpad:
But the file is not in my project, it resides in: C:\Users\<user>\AppData\Roaming\Code\User\globalStorage\buenon.scratchpads\scratchpads\2598de6c6ff8511bd5e99191be2e3a80\scratch33.js
Then after that first time, Format Document
will show the alert I describe in in my original post.
On one hand, troubleshooting this may take a log of effort, on the other hand, this might reveal a legitimate vscode-eslint bug. Either way, it sounds like you are saying it should never have formatted the document that first time?
This actually depends on whether an ESLint instance (npm module) and configuration file is found in C:\Users\<user>\AppData\Roaming\Code\User\globalStorage\buenon.scratchpads\scratchpads\2598de6c6ff8511bd5e99191be2e3a80
or one of its parent directories.
This actually depends on whether an ESLint instance (npm module) and configuration file is found in
C:\Users\<user>\AppData\Roaming\Code\User\globalStorage\buenon.scratchpads\scratchpads\2598de6c6ff8511bd5e99191be2e3a80
or one of its parent directories.
Why would that make it format once but give me the pop up every time after? Either way, the only files in that directory are scratchpad's I have created, so I don't think that's the reason it formats: There are no NPM modules or configuration files.
Could it be that you specify the ESLint formatter as default in the user settings ?
Could it be that you specify the ESLint formatter as default in the user settings ?
I do have this in my settings.json
:
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[javascript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
Does that explain why it formats the first time but gives me the pop up whenever I use it on the file later?
What is wired is the fact that you say you can format it the first time. When you have eslint set as the default formatter and you format a TS/JS file here is what is happening in VS Code:
In a setup where the probing fails you will see the dialog, however it should already appear on the first attempt of formatting that file.
So for the scratch pad files I would assume formatting always fails, even on first attempt. I tried to reproduce the scenario of not being able to execute eslint on a file and I can never format the file. Even the first attempt fails for me.
Clarification: It doesn't format the first time I try, it formats automatically when I create the scratch pad. This extension automatically pastes what's in your clipboard into the scratch pad and it formats what it pastes automatically.
The new scratch pad will have formatted a javascript in it.
I am pretty confident that the first format is not done by ESLint. Can you disable ESLint extension and try the same to prove this.
Environment
Environment Info:
Node version: v18.17.1 npm version: v9.6.7 Local ESLint version: v8.50.0 (Currently used) Global ESLint version: Not found Operating System: win32 10.0.19045
What parser are you using?
Default (Espree)
What did you do?
Configuration
``` { "env": { "browser": true, "es6": true, "node": true, "jasmine": true }, "plugins": [], "extends": [ "eslint:recommended", "prettier", "plugin:prettier/recommended" ], "globals": { "Atomics": "readonly", "SharedArrayBuffer": "readonly", "State": "writable", "setup": "writable" }, "parserOptions": { "sourceType": "module" }, "rules": { "prettier/prettier": "error", "quotes": ["off"], "no-plusplus": ["off"], "curly": ["error", "all"], "prefer-const": ["warn"] } } ```What did you expect to happen?
I expected this JavaScript file to be formatted by ESLint.
If it doesn't work for some reason, I expected to see a helpful log message in the output tab explaining why the ESLint extension didn't/couldn't format the file.
Originally, I opened this issue in the core eslint repository by mistake. But on the bright side, I received an insightful reply from @rec0il :
I suspected the same reason, but in my humble opinion, the ESLint extension should error with more information on how to resolve the issue.
For example, the output tab didn't print anything when this occurred: this implies something external to the ESLint extension is causing the error. My first reaction was to check if the ESLint extension was set as the default formatter for JS files. Since that wasn't the case, I googled for this error message and some of the answers said I need to toggle some of the extension settings off and on to fix a corrupt configuration. This was not the only answer to the symptom, suggesting that 1) there are multiple reasons this could happen and 2), people are throwing stuff at the wall to see what sticks. A lot of this could be short-circuited if there was a detailed log message in the output tab.
In addition, I think that the ESLint extension should format the file based on the VS Code project's .eslintrc.json file. If there are more than two, pick a sensible default (e.g., the one closer to the project root?). Since this could mask eslint and eslint extension configuration issues, I think the output tab should also log a warning that no suitable .eslintrc.json file was found so it's defaulting to "x".
What actually happened?
I get this error message:
Pressing that configure button does not let me select
eslint
as an option.Nothing is logged to the eslint output tab. I have debugging on and I have server trace on.
Link to Minimal Reproducible Example
https://github.com/DanKaplanSES/jsdom-sandbox
Participation
Additional comments
You will still have to follow the steps in the minimal reproduction example: I can't commit a file outside of its repository and that is one of the steps.