`eslint-plugin-sonarjs` doesn't work with flat config

If I follow your recommendations on SonarJS/packages/jsts/src/rules/README.md at master · SonarSource/SonarJS · GitHub, then I get ConfigError: Config (unnamed): Key "plugins": Cannot redefine plugin "sonarjs". error. If I remove the plugin from the list, then I get TypeError: originalContext.getScope is not a function. Rule: "sonarjs/rules-of-hooks" error.

eslint 9.14.0, eslint-plugin-sonarjs 2.0.4

Let me know if you need a reproducible example, but it seems to me that you haven’t tested the plugin with flat config.

Hey there.

That would be a big help.

Could you please check rule "sonarjs/rules-of-hooks" with flat config? If you can’t reproduce the issue, then of course I will make the reproducible example.

This is a Community Forum. Our expectation is that if you’re having an issue, you provide us with a reproducer, not the other way around.

1 Like

Here is a reproducible example.

@dschuessler thanks for the reproducer, it helps greatly.

You are correct: our documentation is wrong.

In your configuration, following our recommendations, you are both declaring the sonarjs plugin and including the recommended configuration:

import sonarjs from 'eslint-plugin-sonarjs';

export default [
  {
    plugins: {
      sonarjs
    }
  },
  sonarjs.configs.recommended,
];

Thus, eslint complains that you are redeclaring the sonarjs plugin because the recommended configuration already declares the sonarjs plugin. If you remove the declaration of the plugin, it should work as expected:

import sonarjs from 'eslint-plugin-sonarjs';

export default [
  sonarjs.configs.recommended,
];

We need to fix our documentation, I created a ticket to make sure that it is handled.

Thanks a lot for noticing and reporting the issue to us. :pray: