From cdd47fa8a0a42a478a1a8b19d64cc059260c3ad9 Mon Sep 17 00:00:00 2001 From: neotaso Date: Mon, 12 Jan 2026 21:36:50 +0900 Subject: [PATCH 1/4] =?UTF-8?q?GameSystem=E3=81=AB=E3=81=8A=E3=81=84?= =?UTF-8?q?=E3=81=A6SuperClass=E3=81=AErequire=E3=81=8C=E8=A1=8C=E3=82=8F?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=82=8B=E3=81=8B=E3=83=81=E3=82=A7=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AEcop?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85=E3=80=82=E6=97=A2=E5=AD=98=E6=A4=9C?= =?UTF-8?q?=E7=9F=A5=E9=83=A8=E5=88=86=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .rubocop.yml | 6 ++ lib/bcdice/game_system/BlackJacket_Korean.rb | 1 + .../game_system/DungeonsAndDragons_Korean.rb | 2 + lib/bcdice/game_system/Emoklore_Korean.rb | 2 + lib/bcdice/game_system/JuinKansen_Korean.rb | 2 + lib/bcdice/game_system/KizunaBullet_Korean.rb | 3 +- lib/bcdice/game_system/Ventangle_Korean.rb | 1 + .../sword_world/transcendent_test.rb | 1 + rubocop/cop/bcdice/game_system_dependency.rb | 62 +++++++++++++++++++ 9 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 rubocop/cop/bcdice/game_system_dependency.rb diff --git a/.rubocop.yml b/.rubocop.yml index 464a33cf1..f3a6dc95f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ inherit_from: .rubocop_todo.yml +require: + ./rubocop/cop/bcdice/game_system_dependency.rb + AllCops: TargetRubyVersion: 2.7 NewCops: disable @@ -141,3 +144,6 @@ Style/WhileUntilModifier: Style/YodaCondition: EnforcedStyle: forbid_for_equality_operators_only + +BCDice/GameSystemDependency: + Enabled: true \ No newline at end of file diff --git a/lib/bcdice/game_system/BlackJacket_Korean.rb b/lib/bcdice/game_system/BlackJacket_Korean.rb index 49309522c..5fd82fa8c 100644 --- a/lib/bcdice/game_system/BlackJacket_Korean.rb +++ b/lib/bcdice/game_system/BlackJacket_Korean.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'bcdice/game_system/BlackJacket' require 'bcdice/dice_table/range_table' module BCDice diff --git a/lib/bcdice/game_system/DungeonsAndDragons_Korean.rb b/lib/bcdice/game_system/DungeonsAndDragons_Korean.rb index 32fd1e5f7..7c3e95f4e 100644 --- a/lib/bcdice/game_system/DungeonsAndDragons_Korean.rb +++ b/lib/bcdice/game_system/DungeonsAndDragons_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/DungeonsAndDragons' + module BCDice module GameSystem class DungeonsAndDragons_Korean < DungeonsAndDragons diff --git a/lib/bcdice/game_system/Emoklore_Korean.rb b/lib/bcdice/game_system/Emoklore_Korean.rb index 6656642d7..fffe3a308 100644 --- a/lib/bcdice/game_system/Emoklore_Korean.rb +++ b/lib/bcdice/game_system/Emoklore_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/Emoklore' + module BCDice module GameSystem class Emoklore_Korean < Emoklore diff --git a/lib/bcdice/game_system/JuinKansen_Korean.rb b/lib/bcdice/game_system/JuinKansen_Korean.rb index 6f75f47f8..cb5447ec0 100644 --- a/lib/bcdice/game_system/JuinKansen_Korean.rb +++ b/lib/bcdice/game_system/JuinKansen_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/JuinKansen' + module BCDice module GameSystem class JuinKansen_Korean < JuinKansen diff --git a/lib/bcdice/game_system/KizunaBullet_Korean.rb b/lib/bcdice/game_system/KizunaBullet_Korean.rb index 2275caf6d..5576fd97f 100644 --- a/lib/bcdice/game_system/KizunaBullet_Korean.rb +++ b/lib/bcdice/game_system/KizunaBullet_Korean.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -require "bcdice/game_system/kizuna_bullet/tables" +require 'bcdice/game_system/KizunaBullet' +require 'bcdice/game_system/kizuna_bullet/tables' module BCDice module GameSystem diff --git a/lib/bcdice/game_system/Ventangle_Korean.rb b/lib/bcdice/game_system/Ventangle_Korean.rb index 949225233..a3fafa87b 100644 --- a/lib/bcdice/game_system/Ventangle_Korean.rb +++ b/lib/bcdice/game_system/Ventangle_Korean.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'bcdice/base' +require 'bcdice/game_system/Ventangle' module BCDice module GameSystem diff --git a/lib/bcdice/game_system/sword_world/transcendent_test.rb b/lib/bcdice/game_system/sword_world/transcendent_test.rb index 30a263b04..0dadd94cb 100644 --- a/lib/bcdice/game_system/sword_world/transcendent_test.rb +++ b/lib/bcdice/game_system/sword_world/transcendent_test.rb @@ -2,6 +2,7 @@ require "bcdice/result" require "bcdice/translate" +require "bcdice/game_system/SwordWorld" module BCDice module GameSystem diff --git a/rubocop/cop/bcdice/game_system_dependency.rb b/rubocop/cop/bcdice/game_system_dependency.rb new file mode 100644 index 000000000..a0ea03a0b --- /dev/null +++ b/rubocop/cop/bcdice/game_system_dependency.rb @@ -0,0 +1,62 @@ +require "rubocop" + +module RuboCop + module Cop + module BCDice + class GameSystemDependency < Base + MSG = "superclass file must be required: %s".freeze + + def on_class(node) + return unless processed_source.file_path.include?("bcdice/game_system/") + + _name, superclass, _body = *node + return unless superclass + + parent_name = superclass.source + + return if ["Base", "StandardError"].include?(parent_name) + + # DiceTableのスーパークラスを利用している場合はOKとする + # 本来はBase.rbのrequireを再帰的に確認するメソッドを実装すべきだが大変 + return if parent_name.start_with?("DiceTable::") + + # 同じファイル内でスーパークラスが定義されていたときは無視する + return if processed_source.ast.each_node(:class).any? { |c| c.identifier.source == parent_name } + + require_path = + if parent_name.include?("::") + "bcdice/game_system/#{parent_name.split('::')[0]}" + else + "bcdice/game_system/#{parent_name}" + end + + # requireが記述されているか確認 + return if require_present?(require_path) + + add_offense(node, message: format(MSG, require_path: require_path)) + end + + private + + def require_present?(path) + processed_source.ast.each_node(:send) do |node| + next unless node.method?(:require) + + arg = node.first_argument + return true if arg && arg.str_content == path + end + false + end + + # dice_tableなどのスーパークラスの確認のために実装したが未使用 + def to_snake_case(str) + str + .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') + .gsub(/([a-z\d])([A-Z])/, '\1_\2') + .tr("-", "_") + .downcase + end + end + end + end +end From 8a22f61e5b0e7b514f2ecbbe04da859c8d3deab2 Mon Sep 17 00:00:00 2001 From: neotaso Date: Mon, 12 Jan 2026 22:08:27 +0900 Subject: [PATCH 2/4] =?UTF-8?q?auto=20corrector=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rubocop/cop/bcdice/game_system_dependency.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rubocop/cop/bcdice/game_system_dependency.rb b/rubocop/cop/bcdice/game_system_dependency.rb index a0ea03a0b..391b0e20b 100644 --- a/rubocop/cop/bcdice/game_system_dependency.rb +++ b/rubocop/cop/bcdice/game_system_dependency.rb @@ -33,7 +33,14 @@ def on_class(node) # requireが記述されているか確認 return if require_present?(require_path) - add_offense(node, message: format(MSG, require_path: require_path)) + add_offense(node, message: format(MSG, require_path: require_path)) do |corrector| + last_require = processed_source.ast.each_node(:send).select { |n| n.method?(:require) }.last + if last_require + corrector.insert_after(last_require, "\nrequire '#{require_path}'") + else + corrector.insert_before(processed_source.ast, "require '#{require_path}'\n\n") + end + end end private From 282696d8a240b22d9c1b7f4feca65edd354eb023 Mon Sep 17 00:00:00 2001 From: neotaso Date: Mon, 12 Jan 2026 22:20:02 +0900 Subject: [PATCH 3/4] =?UTF-8?q?extend=E3=81=AE=E8=A8=98=E8=BF=B0=E3=81=8C?= =?UTF-8?q?=E6=8A=9C=E3=81=91=E3=81=A6=E3=81=84=E3=81=9F=E3=81=9F=E3=82=81?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rubocop/cop/bcdice/game_system_dependency.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rubocop/cop/bcdice/game_system_dependency.rb b/rubocop/cop/bcdice/game_system_dependency.rb index 391b0e20b..aac12d46f 100644 --- a/rubocop/cop/bcdice/game_system_dependency.rb +++ b/rubocop/cop/bcdice/game_system_dependency.rb @@ -4,6 +4,8 @@ module RuboCop module Cop module BCDice class GameSystemDependency < Base + extend AutoCorrector + MSG = "superclass file must be required: %s".freeze def on_class(node) From 20e1621b3e78008caf601063aa35765fa8695baa Mon Sep 17 00:00:00 2001 From: SAKATA Sinji Date: Sat, 21 Feb 2026 11:17:34 +0900 Subject: [PATCH 4/4] cop --- lib/bcdice/game_system/GardenOrder_Korean.rb | 2 ++ lib/bcdice/game_system/MagicPunk_Korean.rb | 2 ++ lib/bcdice/game_system/Nuekagami_Korean.rb | 2 ++ lib/bcdice/game_system/ShinobiGami_Korean.rb | 1 + lib/bcdice/game_system/TacticalExorcist.rb | 2 ++ lib/bcdice/game_system/ZombiLine_Korean.rb | 2 ++ 6 files changed, 11 insertions(+) diff --git a/lib/bcdice/game_system/GardenOrder_Korean.rb b/lib/bcdice/game_system/GardenOrder_Korean.rb index 234f56a02..c4fc2fa2d 100644 --- a/lib/bcdice/game_system/GardenOrder_Korean.rb +++ b/lib/bcdice/game_system/GardenOrder_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/GardenOrder' + module BCDice module GameSystem class GardenOrder_Korean < GardenOrder diff --git a/lib/bcdice/game_system/MagicPunk_Korean.rb b/lib/bcdice/game_system/MagicPunk_Korean.rb index a02169a52..bcd3ceb10 100644 --- a/lib/bcdice/game_system/MagicPunk_Korean.rb +++ b/lib/bcdice/game_system/MagicPunk_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/MagicPunk' + module BCDice module GameSystem class MagicPunk_Korean < MagicPunk diff --git a/lib/bcdice/game_system/Nuekagami_Korean.rb b/lib/bcdice/game_system/Nuekagami_Korean.rb index 771cbcd2d..64b7e9f59 100644 --- a/lib/bcdice/game_system/Nuekagami_Korean.rb +++ b/lib/bcdice/game_system/Nuekagami_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/Nuekagami' + module BCDice module GameSystem class Nuekagami_Korean < Nuekagami diff --git a/lib/bcdice/game_system/ShinobiGami_Korean.rb b/lib/bcdice/game_system/ShinobiGami_Korean.rb index 122d21f66..590909f56 100644 --- a/lib/bcdice/game_system/ShinobiGami_Korean.rb +++ b/lib/bcdice/game_system/ShinobiGami_Korean.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'bcdice/dice_table/table' +require 'bcdice/game_system/ShinobiGami' module BCDice module GameSystem diff --git a/lib/bcdice/game_system/TacticalExorcist.rb b/lib/bcdice/game_system/TacticalExorcist.rb index 8f8338afd..135814eb5 100644 --- a/lib/bcdice/game_system/TacticalExorcist.rb +++ b/lib/bcdice/game_system/TacticalExorcist.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/NinjaSlayer2' + module BCDice module GameSystem class TacticalExorcist < NinjaSlayer2 diff --git a/lib/bcdice/game_system/ZombiLine_Korean.rb b/lib/bcdice/game_system/ZombiLine_Korean.rb index ddf009317..3a47d18e2 100644 --- a/lib/bcdice/game_system/ZombiLine_Korean.rb +++ b/lib/bcdice/game_system/ZombiLine_Korean.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'bcdice/game_system/ZombiLine' + module BCDice module GameSystem class ZombiLine_Korean < ZombiLine