-
Notifications
You must be signed in to change notification settings - Fork 324
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
"Format Document" command should use ESLint #417
Comments
Yes! Please just build this into VS Code! There is literally no point in having a crummy linter that no body uses built into VS Code and the good one that everyone uses as a plugin! VS Code is advertised as having linting built in, this is a perfect opportunity to simplify and save time and effort for the user while eliminating the need for maintaining multiple plugins (bits of VS Code). Please hurry this along and add it to the next insiders! :) |
I can't believe this is not a thing. I was so sure that it is how the extension is supposed to work that I spent an hour reading the README, code and VS Code settings to understand why it is not working. Only to realize, via this issue, that there is no actual support for this yet. I think it's a must-have feature. |
You can run ESLint in |
@Hirse excellent!, how to do that also on save? 😄 |
@nschurmann I think you have to disable |
I ended up installing the prettier plugin and changing my configs. Prettier formats on save. It makes sense to have one plugin deal with all the formatting (prettier) and the other for the actual code best practice (eslint). I use the airbnb eslint config, so I installed the command line tool for prettier that detects clashing rules: https://github.com/prettier/eslint-config-prettier and then manually deleted them all from my eslint config. Took about half an hour copying from the command line results and finding/deleting in the eslint config in vscode , sorted :) |
@David-Else That's how we do it as well ... Prettier + ESLint |
This actually seems to affect JavaScript embedded in Markdown as well. |
Prettier is too opinionated and can't be really configured. Please, don't make it depend on prettier. |
clang-format hooks into vscode's Format Document functionality by providing a language formatter, eslint should do the same if it is not already. Seems Prettier does this also. Hopefully that is sufficient examples to inspire someone. |
If I run |
As @Hirse said, this works as expected. But would love to have a GUI option nonetheless!
Edit: Press the shortcut multiple times to get it fully formatted. Yet to find a fix for this. |
The key-bind workaround does seem like it comes sorta close, but ... it hardly seems right. It's only in a very narrow case that it works as expected. It's not just the key-bind that is the expectation, but the command, which can be called via other code, tasks, or other extensions. |
agreed. prettier, as an example, is able to format while typing and work with other formatters to arrive at a stable final result. because eslint has its own format command that mostly only runs on save, |
|
Yes, 1 thing of the many involved works with a setting, but none of the other important things work. |
It should be an automatic mechanism accepting the .eslintrc.json from the root directory of the project. As example: settings from the .vscode/*. If .eslintrc.json is absent - just ignore and turn on standard formatting. |
yes, I strongly agree that vscode-eslint should be able to bind to |
Here more productive tips for programmer: https://github.com/TomaszWaszczyk/keyboard-shortcuts-productive-hacks |
Like others have said, the easiest fix is to install Prettier from the VS Extension Marketplace. Create a
Works well with Airbnb eslint rules. |
Also there's a eslint-plugin-prettierx with more options than the default Prettier ones (I'm the author). For example, this is an .eslintrc.json with the "default" preset: {
"root": true,
"plugins": ["prettierx"],
"extends": [
"eslint:recommended",
"plugin:prettierx/default"
]
} It works like any other ESLint plugin, it can be used with the VS Code ESlint or in the command line with The plugin includes Prettierx, no need to install Prettier nor the VS Code Prettier extension, and it is not recommended as Prettier (w/o "x") is not compatible with ESLint. I am using it with |
https://github.com/ryuta46/vscode-multi-command
|
You need to install ESLint plugin first, then this will work really well. |
A couple things I'd like to point out here:
|
With ESLint's existing level of integration, and ever -increasing use, this seems so close to being perfect and harmonious. |
I use in default react native project this settings.
then open short keys JSON not default
|
There's an Extension API, which means that extensions may trigger code to Format Document, or execute code on Format Document, and simply doing a key-bind or on-save is completely irrelevant to the issue. |
The patch on the other hand looks great! |
This really needs to be "Fixed". Basically, the defaults on loading VSCode should 'just work'. Instead, every time you edit a file, all hell breaks loose. This is annoying and you lose productivity this way. I should be coding, not getting irritated and surfing the web on an ocean of orange underlines. |
This will be available in the next version. Please see #815 if you want to help test this. |
@dbaeumer Thanks so much for working on this! Ideally, the formatter should only fix formatting rules, not code smells. The problem with auto-fixing on format is that it changes what the code does, and can sometimes produce a bug. Can you please consider using |
Fixed in 2.0.4. See |
|
@joaohenriquef did you have another JavaScript formatter set as a default formatter. Then the eslint one will not win. To force the use of the eslint one you need to configure: "eslint.format.enable": true,
"[javascript]": { "editor.defaultFormatter": "dbaeumer.vscode-eslint" } |
@dbaeumer I'm not sure about what happened, ESLint wasn't showing up on that list, even after reinstalling the extension and double checking that the formatter was enabled in settings. Now, trying to replay this bug I upgraded it again but somehow everything worked fine, maybe I missed something. Thanks for your help and quick reply! |
@joaohenriquef no problem. You are welcome. |
@joaohenriquef did you open a TS / JS file before. ESLint is only registered inside VS Code for a formatter if a corresponding file is open. |
@joaohenriquef, I'm having the same issue. Working on a React Native project, VS Code sees the |
Might be worth mentioning: If you do have the Prettier extension installed, you may have to add the following to your "prettier.disableLanguages": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact"
] |
This was it! Now I can format in VS Code using ESLint. Thank you so much! |
@paulbargaoanu Glad that helped! |
There didn't seem to be any mention of this functionality, except a by implication in "formatOnSave" issues.
VSCode has a JavaScript formatter, but ESLint should replace it, not use a secondary one with a different conflicting command.
The text was updated successfully, but these errors were encountered: