概要
Sonarjsのeslintプラグインを入れるときに少しハマったのでメモ。
eslint-plugin-sonarjsに記載された書きかただと下記エラーがでて動かない。
Oops! Something went wrong! :(
ESLint: 9.39.0
ConfigError: Config "UserConfig[0][1] > UserConfig[0][0] > ExtendedConfig[6]": Key "plugins": Cannot redefine plugin "sonarjs".
調査
sonarsourceで下記のやり取りがされていた。
You are correct: our documentation is wrong.
We need to fix our documentation, I created a ticket to make sure that it is handled
ご指摘の通り、弊社のドキュメントは間違っています。
ドキュメントを修正する必要があるため、確実に処理されるようにチケットを作成しました。
待てば、ドキュメントは直るのだろう。
対応
修正した点は下記。
import eslint from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import sonarjs from 'eslint-plugin-sonarjs';
import tseslint from 'typescript-eslint';
export default defineConfig([
globalIgnores(['node_modules/', '.config/', 'dist/', 'tsconfig.json']),
{
extends: [
eslint.configs.recommended,
tseslint.configs.recommended,
sonarjs.configs.recommended,
],
- {
- "plugins": {
- sonarjs,
- }
}
},
]);
参考
ESLintはv9に上げてからFlat Configに移行した方がやりやすそう
Fix Usage section of the documentation