Skip to content

Support ESLint "flat" configs #1408

Closed
@michaelfaith

Description

@michaelfaith

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions