0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

eslintをv8.57.1に戻してsonarjsなどの設定を行ったメモ

Last updated at Posted at 2024-09-28

概要

前回はeslint9のflatconfigを試した。
今回は静的解析をeslintで行うSonarJSを導入する。
sonarjsはまだv9に対応しきっていないのでv8にダウングレードした。(v8は2024.10.05でEOLになってしまうが...)
ついでにまだv9対応されていないimportプラグインなども入れた。

プルリク
v9 -> v8

2024.10.11
eslint-importが2.31.0でeslint9に対応したのでv.8.57にする必要はなくなった。*

追加設定

v8に落としたことで、エイリアスが認識されなくなった。

eslint-import-resolver-typescriptプラグインで対応した。

packages/eslint-config-custom/default.js
// 省略
export default tseslint.config({
  extends: [ js.configs.recommended
            , ...tseslint.configs.recommended
            , ...compat.extends('airbnb-base')
            , ...compat.extends('plugin:import/recommended')
            , ...compat.extends('plugin:sonarjs/recommended-legacy')
            , ...compat.extends('eslint-config-turbo')
            , prettierConfig
          ],
  plugins: { 'unused-imports': unuserdPlugin, sonarjs },
  rules: {
    // 省略
    'import/extensions': ['off'],
  },
+  settings: {
+    'import/resolver': {
+      node: {
+        extensions: ['.js', '.jsx', '.ts', '.tsx'],
+      },
+      typescript: {},
+    },
  },
});

また。フロントエンド側のtsconfigにreferencesを使っていたのでそのままでは認識されなかった。

apps/pl-app/tsconfig.json
{
  "files": [],
  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.node.json" }
  ]
}

これもResolverに追加設定で解決した。

apps/pl-app/eslint.config.mjs
import customConfig from '@async-ttrpg/eslint-config-custom/frontend.js';
import tseslint from 'typescript-eslint';

export default tseslint.config({
  extends: [...customConfig],
  settings: {
    'import/resolver': {
      node: {
        extensions: ['.js', '.jsx', '.ts', '.tsx'],
      },
      typescript: {
+        project: "./tsconfig.app.json",
      },
    },
  },
});
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?