Content-Length: 520856 | pFad | https://github.com/kufu/eslint-config-smarthr/pull/898

20 chore!: ESLint v9 + FlatConfig by s-sasaki-0529 · Pull Request #898 · kufu/eslint-config-smarthr · GitHub
Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

chore!: ESLint v9 + FlatConfig #898

Merged
merged 24 commits into from
Dec 12, 2024
Merged

chore!: ESLint v9 + FlatConfig #898

merged 24 commits into from
Dec 12, 2024

Conversation

s-sasaki-0529
Copy link
Contributor

@s-sasaki-0529 s-sasaki-0529 commented Nov 26, 2024

WHAT

ESLint v9 へのマイグレーション及び FlatConfig での書き直しをします。

WHY

  • 各プロダクトの ESLint も v9 対応を進めたいが、依存先である本パッケージのバージョンアップが最初に必要なため
  • FlatConfig 化することで、設定をシンプルにしたり様々な新機能を利用できるようになるため

HOW

  • 各パッケージを最新化 (ESLint 以外もついでも全部あげてます)
  • FlatConfig への地道な書き換え
  • テスト手法のリライト
    • 現状はサンプルコードに対して Config を元にした ESLint の実行結果をスナップショットでテストしてますが、バージョンアップ後も同じテストを維持することが困難だったこと、カバレッジが低いことから、テストの仕組みも見直して設定ファイル全体のスナップショットを取る方式に変えてます。
    • FlatConfig は ESM を扱えるので、ESMをテストしやすい vitest に乗り換えてます

確認方法

設定ファイルの差分を確認するのは困難だと思うので、チェックアウトして、$ npx eslint --inspect-config を実行するのをオススメします。

テストコード基盤自体も刷新してしまったので、テストコードが通ってるからOKとはいかないので目視確認をお願いします。

備考

利用可能な Node/ESLint のバージョン下限が変わるため、メジャーバージョンアップを想定しています。

@@ -18,19 +18,19 @@ commands:
# run tests!
- run: yarn test
jobs:
node-v18:
node-v20:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node のバージョンをサポート状況にあわせて更新。
これどのリポジトリでも更新漏れますねぇ。

/**
* @type {import('eslint').Linter.Config}
*/
export default [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

こちらも Flat Config で書き直し。
原則すべて Flat Config にリライトしただけで内容は一切変わらないよう努めてます。

"import": "./index.js",
"require": "./index.js"
}
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

プロダクト側の FlatConfig 上で ESM として扱えるようにするため調整してます。

"test": "jest",
"test:update-snapshot": "jest --updateSnapshot"
"test": "vitest",
"test:update-snapshot": "vitest --updateSnapshot"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESM を扱うには Jest は力不足すぎるので、この機会に vitest に差し替えてます。

"jest": "^29.7.0",
"react": "^18.3.1",
"standard-version": "^9.3.2",
"typescript": "^5.7.2"
},
"peerDependencies": {
"eslint": "^7.0.0 || ^8.0.0",
"eslint": "^9.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

それなりに頑張らない限りは v8 から利用することは難しいので、もう peer も v9 のみにしちゃいます。

})
const config = await eslint.calculateConfigForFile('index.js')
expect(config).toMatchSnapshot()
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

現行のテストコードでは、設定ファイルを使ってサンプルコードに対して ESLint を実行し、その結果レポートのスナップショットを取るという手法を取られてました。

しかし、ESLint 内部APIに依存しているその仕組みを v9 に移植するのが困難であることと、労力の割に得られるカバレッジがイマイチであることから、設定ファイル全体をスナップショットテストするように変更しました。

"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-smarthr": "^0.5.20"
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-smarthr": "1.0.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ついにv1か〜

@@ -16,12 +16,17 @@ yarn add --dev eslint-config-smarthr

## How to use

Add a following `.eslintrc.js` in your project.
Add a following `eslint.config.js` in your project.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

申し訳程度に README も更新。
プロダクト固有のカスタムが一切ない場合は、↓のサンプルの設定ファイルで動作します。

@s-sasaki-0529 s-sasaki-0529 marked this pull request as ready for review December 12, 2024 06:23
@s-sasaki-0529 s-sasaki-0529 requested a review from a team as a code owner December 12, 2024 06:23
@s-sasaki-0529 s-sasaki-0529 requested review from nabeliwo, yamish123 and a team and removed request for a team December 12, 2024 06:23
Copy link
Member

@AtsushiM AtsushiM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@s-sasaki-0529 s-sasaki-0529 merged commit 80a5104 into master Dec 12, 2024
1 check passed
@s-sasaki-0529 s-sasaki-0529 deleted the eslint-v9 branch December 12, 2024 09:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/kufu/eslint-config-smarthr/pull/898

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy