-
Notifications
You must be signed in to change notification settings - Fork 7
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
chore!: ESLint v9 #154
Conversation
plugins: { | ||
recommended: generateRecommendedConfig(rules), | ||
} | ||
} |
There was a problem hiding this comment.
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" | |||
}, |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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('/') |
There was a problem hiding this comment.
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する名称に変更してください。` } ] }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここは L151 にまったく同じテストがあるやろがいってエラーが出たので消してます。そういうエラーが出る機能がどっかのバージョンで入ったみたい。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
特に反対意見も出なかったのでGOGOですかね…?
これマージしたらメジャーバージョン上げてリリースして、続けて config-smarthr のほうも対応進めるので、各プロダクトがバージョン追従ややムズ状態になっちゃうんですが。
タイミングは見計らったほうが良いかも? |
GOGO のイキフンなので進めちゃいたいと思います! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
WHAT
ESLint v9 へのマイグレーションを行います。
WHY
eslint-config-smarthr
及び各プロダクトの ESLint も v9 対応を進めたいが、依存先である本プラグインのバージョンアップが最初に必要なためHOW
確認方法
個別のカスタムルールについては、単体テストをパスしているのでOKとします。
プラグインとして使えるかどうかは、eslint-config-smarthr との組み合わせて検証しています。長くなるので折りたたんでいますが、興味がある方、検証してみたい方は是非試してみてください。
詳細な検証方法
eslint-plugin-smarthr
をセットアップ本リポジトリをクローンし、本PRのブランチをチェックアウトしてください。
パッケージをインストール後、
yalc
を用いてローカルにパッケージを公開します。eslint-config-smarthr
をセットアップeslint-config-smarthr
も同様にリポジトリをクローンし、以下のPRのブランチをチェックアウトしてください。パッケージをインストール後、先程ローカルに公開したバージョンの
eslint-plugin-smarthr
を依存に追加します。以下コマンドを実行することで、インスペクタを設定ファイルの可視化ができます。
このインスペクタは FlatConfig でしか使用できない上、FlatConfig の設定が不適切だとエラーが出るため、ここで設定が概ね確認できれば成功と言えます。
プロダクト側で利用する
さらに、
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 でも良さそう…?