requireの無いSuperClassを検出するRubocopのカスタムcopの実装 #828
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
概要
requireのないSuperClassの読み込みに関するRubocopのカスタムcop。
bcdice-jsではSuperClassに対応するrequireが存在しない場合、エラーとなる。
また、現時点で検出されているゲームシステムでのrequireの追加も本変更で行っている。
現状
SuperClassで実装されているGameSystemで、requireが無いものは現状bcdice-jsでエラーが出る状態。
(bcdice-jsを採用しているCCFOLIAでBlackJacket_Koreanなどは読み込めなかった。)
CIでもエラーが発生している
https://github.com/bcdice/bcdice-js/actions/runs/20894099834/job/60051533024?pr=73
現状はアリアンロッド 韓国版のように適宜修正のコミットを実施している状態。
d2af4a0
対応
RubocopのカスタムCopで対応する
GameSystem以下で実装されたClassを確認し、SuperClassが
Baseや組み込み以外のもののrequireを確認し、対応するrequireが存在しなければoffenseを出す。auto correctorも実装したので、
rubocop -aで自動的にrequire追加まで行われる。Rubocopのアラートサンプル (本コミットの該当部分修正前の検知)
https://gist.github.com/neotaso/5da1e7f62c88df682b744066d096fe1b
備考
auto correctで、追加するrequireは最後のrequireの後に入れているので、内容次第では不自然な順番になるかもしれない
Class名を
BCDice/GameSystemDependencyにしているが、Lint/BCDiceGameSystemDependencyでも良いかもしれないRubocopにはrequire_toolsのcopがすでに存在するが、requireの中を再帰的に見ることはこちらもやってないので、これを導入すると
bcdice/base.rbをrequireしててもResultなどが検出してしまう。https://github.com/milch/rubocop-require_tools