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

Support ESLint "flat" configs #1408

Closed
michaelfaith opened this issue Jul 26, 2023 · 8 comments · Fixed by #1505
Closed

Support ESLint "flat" configs #1408

michaelfaith opened this issue Jul 26, 2023 · 8 comments · Fixed by #1505

Comments

@michaelfaith
Copy link

I searched through the issues for something similar, and didn't find anything related to supporting the new Flat Config. So I thought it would make sense to create this for tracking.

I'm currently building out a config using eslint.config.js and the new flat config structure. When using this plugin, I receive the following error:

TypeError: Key "plugins": Key "0": Expected an object.
    at Object.validate (D:\src\ux\.yarn\cache\eslint-npm-8.45.0-bb6c5f1226-3e6dcce5cc.zip\node_modules\eslint\lib\config\flat-config-schema.js:315:23)
    at ObjectSchema.validate (D:\src\ux\.yarn\cache\@humanwhocodes-object-schema-npm-1.2.1-43b3ca2646-a824a1ec31.zip\node_modules\@humanwhocodes\object-schema\src\object-schema.js:218:35)
    at D:\src\ux\.yarn\cache\@humanwhocodes-object-schema-npm-1.2.1-43b3ca2646-a824a1ec31.zip\node_modules\@humanwhocodes\object-schema\src\object-schema.js:171:18
    at Array.reduce (<anonymous>)
    at ObjectSchema.merge (D:\src\ux\.yarn\cache\@humanwhocodes-object-schema-npm-1.2.1-43b3ca2646-a824a1ec31.zip\node_modules\@humanwhocodes\object-schema\src\object-schema.js:169:24)
    at D:\src\ux\.yarn\cache\@humanwhocodes-config-array-npm-0.11.10-33012f902e-1b1302e240.zip\node_modules\@humanwhocodes\config-array\api.js:916:42
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfig (D:\src\ux\.yarn\cache\@humanwhocodes-config-array-npm-0.11.10-33012f902e-1b1302e240.zip\node_modules\@humanwhocodes\config-array\api.js:915:39)
    at FlatConfigArray.isFileIgnored (D:\src\ux\.yarn\cache\@humanwhocodes-config-array-npm-0.11.10-33012f902e-1b1302e240.zip\node_modules\@humanwhocodes\config-array\api.js:943:15)
    at D:\src\ux\.yarn\cache\eslint-npm-8.45.0-bb6c5f1226-3e6dcce5cc.zip\node_modules\eslint\lib\eslint\eslint-helpers.js:312:49

This is due to the fact that the shareable config defines plugins as a string array, rather than object:

const createConfig = (rules: Record<string, TSESLint.Linter.RuleLevel>) => ({
plugins: ['jest'],
env: { 'jest/globals': true },
rules,
});

I'm able to work around it by constructing the config manually using the recommended rules:

import jest from 'eslint-plugin-jest';
import globals from 'globals';

export default [
  {
    plugins: { jest },
    rules: {
      ...jest.configs.recommended.rules,
    },
    languageOptions: {
      globals: {
        ...globals.jest,
      }
    }
  },
];

The eslint-plugin-react and eslint-plugin-jsdoc projects have updated to support this new config approach, if that helps with providing inspiration / examples.

@G-Rath
Copy link
Collaborator

G-Rath commented Jul 26, 2023

Yeah we've had #1245 open implementing support, but everytime I sit down to try to make sense of the new flat config the docs always seem to be missing parts (and it is still actively being worked on) - as you've said it's pretty easy to work around for now.

Having said that it's been a while since I last looked at it, so I'll bump it up my todo list to try have another go next month.

@G-Rath G-Rath changed the title bug: shareable configs don't work with eslint's new "flat" config Support ESLint "flag" configs Jul 26, 2023
@morganney
Copy link

The new flat config docs are definitely missing parts, which is not helping the transition to the new flat config approach. The docs should be in line with the running code.

@michaelfaith
Copy link
Author

Having said that it's been a while since I last looked at it, so I'll bump it up my todo list to try have another go next month.

Appreciate it! If there's anything I can do to help with testing / validation / etc, let me know.

@michaelfaith
Copy link
Author

The new flat config docs are definitely missing parts, which is not helping the transition to the new flat config approach. The docs should be in line with the running code.

I've found this doc to be pretty solid for end-user usage. But to your point, for plugin authors it could use some work.

@michaelfaith michaelfaith changed the title Support ESLint "flag" configs Support ESLint "flat" configs Aug 3, 2023
@pauliesnug
Copy link

@G-Rath This would be amazing to have, also would necesitate generating d.ts files upon build.

@SimenB
Copy link
Member

SimenB commented Dec 30, 2023

Alpha for v9 is out, it's probably time to implement support: https://github.com/eslint/eslint/releases/tag/v9.0.0-alpha.0

@G-Rath
Copy link
Collaborator

G-Rath commented Feb 13, 2024

I've created #1503 for adding flat config support - I'd appreciate folks trying it out (though might be better to do so near the end of the week once I've had a chance to update it with the latest v9 changes😅)

Also fwiw it looks like there's now a FlatCompat class to help with migration.

Copy link

🎉 This issue has been resolved in version 27.9.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants