Skip to content

[eslint] Config (unnamed): Unexpected key "0" found. #273

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

Closed
daniel-stoian-lgp opened this issue Feb 7, 2025 · 8 comments
Closed

[eslint] Config (unnamed): Unexpected key "0" found. #273

daniel-stoian-lgp opened this issue Feb 7, 2025 · 8 comments

Comments

@daniel-stoian-lgp
Copy link

daniel-stoian-lgp commented Feb 7, 2025

Bug report

Hello,
After migrating to eslint 9 with flat config, the Eslint webpack plugin throws the following error:
[eslint] Config (unnamed): Unexpected key "0" found.

Actual Behavior

[eslint] Config (unnamed): Unexpected key "0" found.

Expected Behavior

No error should be shown

How Do We Reproduce?

Former configuration for eslintrc

		new ESLintPlugin({
			// Plugin options
			extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
			formatter: require.resolve('react-dev-utils/eslintFormatter'),
			eslintPath: require.resolve('eslint'),
			// ESLint class options
			resolvePluginsRelativeTo: __dirname,
			// @remove-on-eject-begin
			baseConfig: {
				extends: [require.resolve('eslint-config-enact/index.js')],
				rules: {
					...(!hasJsxRuntime && {
						'react/jsx-uses-react': 'warn',
						'react/react-in-jsx-scope': 'warn'
					})
				}
			},
			useEslintrc: false,
			// @remove-on-eject-end
			cache: true
		})

Current config for flat config:

		const eslintConfig = require('eslint-config-enact/index.js');

		new ESLintPlugin({
			// Plugin options
			configType: 'flat',
			extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
			formatter: require.resolve('react-dev-utils/eslintFormatter'),
			eslintPath: require.resolve('eslint'),
			// @remove-on-eject-begin
			baseConfig: [{
				...eslintConfig,
				rules: {
					...(!hasJsxRuntime && {
						'react/jsx-uses-react': 'warn',
						'react/react-in-jsx-scope': 'warn'
					})
				}
			}],
			overrideConfigFile: true,
			// @remove-on-eject-end
			cache: true
		})

The index.js looks like this:

	const eslint = require('@eslint/js');

	module.exports = [
		eslint.configs.recommended,
		{
			ignores: [
				'**/node_modules/',
				'**/node_modules/*',
				'**/build/',
				'**/build/*'
			]
		}
	];

I checked the API reference and the configuration should work https://eslint.org/docs/latest/integrate/nodejs-api#-new-eslintoptions . The configuration is pretty basic, it only reuses eslint recommended rules and ignores certain paths.

Eslint command using the above configuration works well. No errors.
When I try to build an app with webpack, I get the error mentioned in the description.

Please paste the results of npx webpack-cli info here, and mention other relevant information

@evenstensberg
Copy link
Member

Please format your code better. Right now it's very unreadable.

@daniel-stoian-lgp
Copy link
Author

Please format your code better. Right now it's very unreadable.

done, sorry for that

@alexander-akait
Copy link
Member

Do you use flat config?

@daniel-stoian-lgp
Copy link
Author

Do you use flat config?

Yes. Eslint 9.19. Flat config is enabled by default
Eslint command using the above configuration works well. No errors.
When I try to build an app with webpack, I get the error mentioned in the description.

@alexander-akait
Copy link
Member

Please set https://github.com/webpack-contrib/eslint-webpack-plugin?tab=readme-ov-file#configtype to flat, we are preparing the next major release with flat by default - #272

@daniel-stoian-lgp
Copy link
Author

Please set https://github.com/webpack-contrib/eslint-webpack-plugin?tab=readme-ov-file#configtype to flat, we are preparing the next major release with flat by default - #272

I already did that

@alexander-akait
Copy link
Member

@daniel-stoian-lgp Can you create reproducible test repo?

@daniel-stoian-lgp
Copy link
Author

I have to close the issue, as it does not seem to be caused by eslint-webpack-plugin.
In Eslint 9, The configData object which is used in options.baseConfig does not seem to allow extensions from other configurations anymore https://eslint.org/docs/latest/use/configure/ I came to this conclusion as nothing is mentioned about extending configurations.
In Eslint 8, it specifically mentioned the Extentending configuration files part: https://eslint.org/docs/v8.x/use/configure/
I managed to solve my issue by specifiying a new config file in options.overrideConfigFile

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

No branches or pull requests

3 participants