SonarSource / eslint-plugin-sonarjs

SonarJS rules for ESLint

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make the plugin work with the new eslint.config.js config format

acommodari opened this issue · comments

I want to request a feature.

I would like for this plugin to work with the new flat config eslint.config.js file format that will become the default in eslint@9 and that I'm trying to currently use in eslint@8.41`

I want to report a bug.

Not sure if this is considered a bug since eslint mentioned that all plugins should work out of the box. Maybe this plugin is doing something non-standard?

Reproducer

// eslint.config.js
const js = require('@eslint/js');
const sonarjs = require('eslint-plugin-sonarjs');
const globals = require('globals');

module.exports = [
	{
		ignores: ['**/tests/coverage', '**/.serverless', '**/.esbuild'],
	},
	js.configs.recommended,
	sonarjs.configs.recommended,
	{
		files: ['./services/**/*.js', './packages/**/*.js', './libs/**/*.js', './jest.config.js', 'eslint.config.js'],
		languageOptions: {
			globals: {
				...globals.node,
			},
			ecmaVersion: 2022,
		},
		linterOptions: {
			noInlineConfig: true,
			reportUnusedDisableDirectives: true,
		},
		plugins: {
			sonarjs,
		},
		rules: {},
	},
];

Expected behavior

It should lint correctly however I get the following error message:

Oops! Something went wrong! :(

ESLint: 8.41.0

TypeError: Key "plugins": Key "0": Expected an object.
    at Object.validate (/Users/alessandro.commodari/ssense/dm-shipping/node_modules/eslint/lib/config/flat-config-schema.js:315:23)
    at ObjectSchema.validate (/Users/alessandro.commodari/ssense/dm-shipping/node_modules/@humanwhocodes/object-schema/src/object-schema.js:218:35)
    at /Users/alessandro.commodari/ssense/dm-shipping/node_modules/@humanwhocodes/object-schema/src/object-schema.js:171:18
    at Array.reduce (<anonymous>)
    at ObjectSchema.merge (/Users/alessandro.commodari/ssense/dm-shipping/node_modules/@humanwhocodes/object-schema/src/object-schema.js:169:24)
    at /Users/alessandro.commodari/ssense/dm-shipping/node_modules/@humanwhocodes/config-array/api.js:884:42
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfig (/Users/alessandro.commodari/ssense/dm-shipping/node_modules/@humanwhocodes/config-array/api.js:883:39)
    at FlatConfigArray.isFileIgnored (/Users/alessandro.commodari/ssense/dm-shipping/node_modules/@humanwhocodes/config-array/api.js:911:15)
    at /Users/alessandro.commodari/ssense/dm-shipping/node_modules/eslint/lib/eslint/eslint-helpers.js:312:49

I want to provide the following feedback.

For more info on the new format you can look here: https://eslint.org/docs/latest/use/configure/configuration-files-new

Example

eslint-plugin-sonarjs version: 0.19.0

eslint version: 8.41.0

Node.js version: 18.16.0

Rule key:

Thanks for reporting, we will have a look at this. I also created a related issue in our Sonar plugin repo SonarSource/SonarJS#3968

Hi, could you add a warning on your readme somewhere about this? It would save people from trying to debug their eslint.

Hi,

I would also appreciate that this plugin work properly with the new flat config..