Skip to content
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

any plan for support eslint new config file eslint.config.js? #1518

Closed
zhanglolo opened this issue Aug 27, 2022 · 40 comments · Fixed by #1522
Closed

any plan for support eslint new config file eslint.config.js? #1518

zhanglolo opened this issue Aug 27, 2022 · 40 comments · Fixed by #1522
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities

Comments

@zhanglolo
Copy link

zhanglolo commented Aug 27, 2022

new eslint 8.23.0 release. and cli can use new config file.

eslint/eslint#16235

Is there any plan for support eslint new config file eslint.config.js? 👀

@zhanglolo zhanglolo changed the title any plan for support eslint new config file eslint.config.js any plan for support eslint new config file eslint.config.js? Aug 27, 2022
@dbaeumer
Copy link
Member

It should be support in the sense that the config file is read correctly. The only thing that is missing is the watching of that new config file.

@zhanglolo
Copy link
Author

It should be support in the sense that the config file is read correctly. The only thing that is missing is the watching of that new config file.

But it show: No ESLint configuration found

截屏2022-08-29 16 27 47

@dbaeumer
Copy link
Member

Actually, you are right. To use the new config files new API classes are to be used :-(. This is more effort.

@dbaeumer dbaeumer added feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities labels Aug 29, 2022
@dbaeumer dbaeumer added this to the On Deck milestone Aug 29, 2022
@koshic
Copy link

koshic commented Oct 24, 2022

@dbaeumer do we have any estimates to release it? Asking you because it's not a new feature, it's a kind of compatibility with existing eslint (experimental, yep) functionality.

@dbaeumer
Copy link
Member

Somewhen in the next weeks.

@uhyo
Copy link
Contributor

uhyo commented Nov 8, 2022

Hello, may I kindly ask for the release of this? We are very eagerly waiting for this. 🥺 If anythig blocks the release, I may be able to help.

@dbaeumer
Copy link
Member

Nothing is blocking it except time :-)

@dbaeumer
Copy link
Member

If you want you can help me sanity check:

vscode-eslint-2.3.0.zip

Download the zip and rename it to vsix and run the command install extension from vsix

@uhyo
Copy link
Contributor

uhyo commented Nov 14, 2022

Thank you! I tested it with our project and found a problem; it doesn't check .ts files 😨 (and maybe other files that require custom parser)
I will look into it very soon.

@dbaeumer
Copy link
Member

OK. Great. Let me know the outcome!

@uhyo
Copy link
Contributor

uhyo commented Nov 15, 2022

@dbaeumer Hi, so it turned that the current approach for detecting custom parsers based on languageId2ParserRegExp, languageId2PluginName and languageId2ParserOptions no longer works with the new config format.

The reason is that in eslint.config.js users don't specify parser by name, but import the parser at the user side and passes the imported object to ESLint.

// old config format
  parser: "@typescript-eslint/parser"

// new config format
import typescriptEslintParser from "@typescript-eslint/parser";

  parser: typescriptEslintParser

So it is now hard for the extension to know what exact parser is used for a file.
I have a couple of idea:

  • Provide an option to specify what languageId to lint.
  • Or, stop trying to detect what exact parser is used, and instead try to lint any file with custom parser specified (plus JavaScript files that are linted by default).

What do you think? 🥲

@dbaeumer
Copy link
Member

dbaeumer commented Nov 16, 2022

@uhyo this doesn't sound good.

Provide an option to specify what languageId to lint.

we have been there and the feedback was bad since users expected that the extension works out of the box.

Or, stop trying to detect what exact parser is used,

Always try to lint a file type even if no parser exists results in bad experiences as well. I tried this before introducing the detection but may think have changed.

Have you looked whether there is API on the ESLint instance to get some sort of config that list these parsers? If not, we could talk to the ESLint people to provide such an API since we have this information in the configuration object.

Can you setup an example GitHub repository with a custom parser? Then I can have a look as well.

@uhyo
Copy link
Contributor

uhyo commented Nov 16, 2022

@dbaeumer

Can you setup an example GitHub repository with a custom parser? Then I can have a look as well.

Here's an example setup with new config format and custom parser:

https://github.com/uhyo/vscode-eslint/tree/flat-config-ts/playgrounds/flatConfig

Have you looked whether there is API on the ESLint instance to get some sort of config that list these parsers?

There does exist one, but we can no longer retrieve the name of parser, but only the parser object.

So what we could do is:

// Current approach (rough sketch)
eslintConfig.parser === "@typescript-eslint/parser"
// New approach (rough sketch)
eslintConfig.parser === require('@typescript-eslint/parser')

With the current ESLint API, the above seems the only possible way. I'm not sure whether this is the right way to go...

@dbaeumer
Copy link
Member

After a lot of documentation reading, I found an easy fix for this. The key is this section: https://eslint.org/docs/latest/user-guide/configuring/configuration-files-new#specifying-files-and-ignores

Basically the new flat config will not validate files (except **/*.js, **/*.cjs, and **/*.mjs) if there is not corresponding section configuration section with a files pattern in the flat config.

If no configuration section is in the flat config then calculateConfigForFile returns undefined for that file. If this is the case we mark the file as probe failed. If we find one then we simply assume that the section uses a correctly configured parser and plugin. Otherwise linting on the command line would fail as well.

This was different with the old configuration mechanism where the .eslintrc* file didn't need to indicate for which file types it is used. Hence, I needed the parser checks to see if for example the config file will be able to validate TypeScript file.

See branch dbaeumer/fresh-wildebeest-lavender

@dbaeumer
Copy link
Member

Here is a zip that can be used for another sanity check

vscode-eslint-2.3.0.zip

@dbaeumer
Copy link
Member

@uhyo let me know how it goes

@uhyo
Copy link
Contributor

uhyo commented Nov 18, 2022

@dbaeumer Genius, this works perfectly! In addition to the example setup, I tested with our actual project and there is no problem.

Thank you for your work.

@dbaeumer
Copy link
Member

One minor tweak I did as well is to rename the setting to experimental.useFlatConfig`

@dburles
Copy link

dburles commented Nov 24, 2022

Just wondering if the plan is for this feature to ship with 2.3.0?

@dbaeumer
Copy link
Member

Yes, that is the plan.

@dmaskasky
Copy link

When is 2.3.0 planned for release?

@dbaeumer
Copy link
Member

dbaeumer commented Dec 5, 2022

@2.3.0 will be a pre-release which I will release this week.

@uhyo
Copy link
Contributor

uhyo commented Dec 9, 2022

@dbaeumer Hello, thank you for the 2.3.0 release -- but I noticed that the config name has been reverted in the released version. 😢

スクリーンショット 2022-12-09 10 35 03

@dbaeumer
Copy link
Member

dbaeumer commented Dec 9, 2022

Let me check.

@dbaeumer
Copy link
Member

dbaeumer commented Dec 9, 2022

That is strange: I see

image

@uhyo
Copy link
Contributor

uhyo commented Dec 9, 2022

@dbaeumer I restarted VSCode a couple of times and now the config name seems fine to me. Sorry to have botherd you. 🥺

@dbaeumer
Copy link
Member

No problem.

@danielrentz
Copy link

Hi! Thanks for your great work with this plugin.
The only pain point during experiments with the new config in our project is that the plugin does not watch the config file. Could you add this please?

@dbaeumer
Copy link
Member

This is actually caused by a problem in ESLint itself. I opened eslint/eslint#16660

@danielrentz
Copy link

Great, thank you!

@dburles
Copy link

dburles commented Dec 13, 2022

Hey @dbaeumer, would you consider maybe adding another option, ie. eslint.experimental.flatConfigFilename to support specifying the config filename? It would allow for using an ESM config within CJS projects. I've opened an issue to potentially support .mjs (and resolve the config as Node would) out of the box. As a workaround, ESlint supports a cli flag to specify the filename, eg. ESLINT_USE_FLAT_CONFIG=true npx eslint -c eslint.config.mjs ..

Though I can understand that it might be worthwhile waiting for a resolution there before adding the filename option, just not sure what that might look like. It may simply remain as above, and in that case the option would make sense.

@dbaeumer
Copy link
Member

The ESLint extension has akready support to pass options to the linter. The options available are the ESLint options passed to the ESLint instance created (https://eslint.org/docs/latest/developer-guide/nodejs-api#-new-eslintoptions) and can be set using the eslint.options setting.

@dburles
Copy link

dburles commented Dec 14, 2022

Thanks @dbaeumer! For anyone else with a similar setup (ESM config in a CJS project), this will get things working:

VSCode:

  "eslint.experimental": {
    "useFlatConfig": true
  },
  "eslint.options": {
    "overrideConfigFile": "eslint.config.mjs"
  }

and for the cli:
ESLINT_USE_FLAT_CONFIG=true npx eslint -c eslint.config.mjs .

@tigrr
Copy link

tigrr commented Feb 14, 2023

I am getting an error: "Could not find config file", with the "Experimental: Use Flat Config" option enabled if a project has a .eslintrc file rather than eslint.config.js. The full error in the ESLint output:

Uncaught exception received.
Error: Could not find config file.
    at calculateConfigArray (\node_modules\eslint\lib\eslint\flat-eslint.js:357:19)
    at async FlatESLint.calculateConfigForFile (\node_modules\eslint\lib\eslint\flat-eslint.js:1158:25)
    at async FlatESLint.isPathIgnored (\node_modules\eslint\lib\eslint\flat-eslint.js:1169:24)
    at async c:\Users\user\.vscode\extensions\dbaeumer.vscode-eslint-2.4.0\server\out\eslintServer.js:1:23325
    at async Object.E [as withClass] (c:\Users\user\.vscode\extensions\dbaeumer.vscode-eslint-2.4.0\server\out\eslintServer.js:1:18742)
    at async w.then.g.validate (c:\Users\user\.vscode\extensions\dbaeumer.vscode-eslint-2.4.0\server\out\eslintServer.js:1:23296)

Isn't the old .eslintrc format supposed to be supported at all when "Experimental: Use Flat Config" is enabled?

ESLint: 8.34.0
Node: 16.15.0
npm: 8.5.5
Windows 11

@dbaeumer
Copy link
Member

Flat configs are currently implemented using a different class in ESLint and that needs to be decided upfront. Don't know what the further plans in ESLint are. I guess that separate class will go away.

@tigrr
Copy link

tigrr commented Feb 14, 2023

Thank you. I think we can workaround this so far, by enabling the flat config on per workspace basis rather than globally.

@ryancwalsh
Copy link

@dbaeumer and @dburles You seem to know a lot about Eslint and VSC, and I wonder if you know the answer to https://stackoverflow.com/questions/76184736/vscode-no-longer-shows-eslint-errors-after-i-switched-to-eslint-flat-config-alt

I appreciate your help!

@sharh
Copy link

sharh commented Nov 11, 2023

with "eslint.experimental.useFlatConfig": true, the config file .eslintrc.js does not work, vscode-eslint throw error:
image
while disable useFlatConfig works well

@dbaeumer
Copy link
Member

@sharh does validation work for you in the terminal?

@kecrily
Copy link

kecrily commented Nov 14, 2023

@sharh I think it's about https://github.com/microsoft/vscode-eslint/pull/.

@dbaeumer dbaeumer removed this from the On Deck milestone Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

Successfully merging a pull request may close this issue.