Content-Length: 485759 | pFad | https://github.com/kufu/eslint-plugin-smarthr/pull/154

9B chore!: ESLint v9 by s-sasaki-0529 · Pull Request #154 · kufu/eslint-plugin-smarthr · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore!: ESLint v9 #154

Merged
merged 15 commits into from
Dec 12, 2024
Merged

chore!: ESLint v9 #154

merged 15 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 へのマイグレーションを行います。

WHY

eslint-config-smarthr 及び各プロダクトの ESLint も v9 対応を進めたいが、依存先である本プラグインのバージョンアップが最初に必要なため

HOW

  • 各パッケージを最新化 (ESLint 以外もついでも全部あげてます)
  • codemod による自動修正
  • FlatConfig からの利用を見据えた調整

確認方法

個別のカスタムルールについては、単体テストをパスしているのでOKとします。

プラグインとして使えるかどうかは、eslint-config-smarthr との組み合わせて検証しています。長くなるので折りたたんでいますが、興味がある方、検証してみたい方は是非試してみてください。

詳細な検証方法

eslint-plugin-smarthr をセットアップ

本リポジトリをクローンし、本PRのブランチをチェックアウトしてください。

パッケージをインストール後、yalc を用いてローカルにパッケージを公開します。

$ yarn install
$ npx yalc publish

eslint-config-smarthr をセットアップ

eslint-config-smarthr も同様にリポジトリをクローンし、以下のPRのブランチをチェックアウトしてください。

パッケージをインストール後、先程ローカルに公開したバージョンの eslint-plugin-smarthr を依存に追加します。

$ yarn install
$ npx yalc add eslint-plugin-smarthr

以下コマンドを実行することで、インスペクタを設定ファイルの可視化ができます。
このインスペクタは FlatConfig でしか使用できない上、FlatConfig の設定が不適切だとエラーが出るため、ここで設定が概ね確認できれば成功と言えます。

$ yarn eslint --inspect-config

プロダクト側で利用する

さらに、eslint-config-smarthr も yalc でローカル公開することで、各プロダクトから利用することができます。

# eslint-config-smarthr
$ npx yalc publish
# product repository
$ npx yalc add eslint-config-smarthr

ただし FlatConfig を前提としているので、プロダクト側も eslint.config.js を FlatConfig で書き直す必要があります。(私の担当プロダクトでは検証済み)

備考

利用可能な Node/ESLint のバージョン下限が変わるため、メジャーバージョンアップを想定しています。
そろそろ v1.0.0 でも良さそう…?

@s-sasaki-0529 s-sasaki-0529 self-assigned this Nov 26, 2024
plugins: {
recommended: generateRecommendedConfig(rules),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

v9 でデフォルト化した Flat Config によせてエントリーファイルの構造を調整します。

著名なプラグインパッケージはv8/v9 互換のためにそれぞれの設定ファイルを返してるんですが、社内向けなので割り切って最新版のみメンテする方針にしてます。

@@ -5,6 +5,9 @@
"license": "MIT",
"description": "A sharable ESLint plugin for SmartHR",
"main": "index.js",
"engines": {
"node": ">=20.9.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.

ESLint v9 が Node20.9 からしかサポートしてないのであわせておきます。

"eslint": "^9.15.0",
"jest": "^29.7.0",
"standard-version": "^9.5.0",
"typescript-eslint": "^8.14.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.

ESLint ついでにすべてのパッケージを最新化して再検証してます。

},
"peerDependencies": {
"eslint": "^7 || ^8"
"eslint": "^9"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/kufu/eslint-plugin-smarthr/pull/154/files#r1858246684
の通り、互換性をもたせるのがまぁまぁ大変なので強気の v9 限定プラグインにします。

@@ -141,7 +141,8 @@ module.exports = {
schema: [],
},
create(context) {
const filenames = context.getFilename().replace(rootPathSlashed, '').replace(extRegex, '').split('/')
const filename = context.filename ?? context.getFilename();
const filenames = filename.replace(rootPathSlashed, '').replace(extRegex, '').split('/')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

以降の差分は codemod による自動マイグレーションです。正直信じる気持ちでしかない。テストが通ってるからまぁ。
https://github.com/eslint/eslint-transforms

@@ -149,7 +147,6 @@ ruleTester.run('a11y-clickable-element-has-text', rule, {
{ code: 'const Hoge = styled(Link)``', errors: [ { message: `Hogeを正規表現 "/Link$/" がmatchする名称に変更してください。` } ] },
{ code: 'const Hoge = styled(Button)``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください。` } ] },
{ code: 'const Fuga = styled(HogeAnchor)``', errors: [ { message: `Fugaを正規表現 "/Anchor$/" がmatchする名称に変更してください。` } ] },
{ code: 'const Fuga = styled(HogeAnchor)``', errors: [ { message: `Fugaを正規表現 "/Anchor$/" がmatchする名称に変更してください。` } ] },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ここは L151 にまったく同じテストがあるやろがいってエラーが出たので消してます。そういうエラーが出る機能がどっかのバージョンで入ったみたい。

@s-sasaki-0529 s-sasaki-0529 changed the title chore!: ESLint v9 chore!: ESLint v9 Nov 26, 2024
@s-sasaki-0529 s-sasaki-0529 marked this pull request as ready for review November 28, 2024 05:16
@s-sasaki-0529 s-sasaki-0529 requested a review from a team as a code owner November 28, 2024 05:16
@s-sasaki-0529 s-sasaki-0529 requested review from yt-ymmt, yamish123 and a team and removed request for a team November 28, 2024 05:16
@s-sasaki-0529 s-sasaki-0529 requested a review from a team December 6, 2024 03:31
Copy link
Contributor Author

@s-sasaki-0529 s-sasaki-0529 left a comment

Choose a reason for hiding this comment

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

特に反対意見も出なかったのでGOGOですかね…?

これマージしたらメジャーバージョン上げてリリースして、続けて config-smarthr のほうも対応進めるので、各プロダクトがバージョン追従ややムズ状態になっちゃうんですが。

@AtsushiM
Copy link
Member

AtsushiM commented Dec 9, 2024

タイミングは見計らったほうが良いかも?
年末でバタバタしてそうだし来年とかにしますか?

@s-sasaki-0529
Copy link
Contributor Author

GOGO のイキフンなので進めちゃいたいと思います!
PR本文の通りの一通りの動作確認を改めた完了したのでどなたかApproveいただけるとー。

@AtsushiM AtsushiM self-requested a review December 11, 2024 23:40
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 a0b79fd into main Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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-plugin-smarthr/pull/154

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy