Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
inherit_from: .rubocop_todo.yml

require:
./rubocop/cop/bcdice/game_system_dependency.rb

AllCops:
TargetRubyVersion: 2.7
NewCops: disable
Expand Down Expand Up @@ -141,3 +144,6 @@ Style/WhileUntilModifier:

Style/YodaCondition:
EnforcedStyle: forbid_for_equality_operators_only

BCDice/GameSystemDependency:
Enabled: true
1 change: 1 addition & 0 deletions lib/bcdice/game_system/BlackJacket_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# frozen_string_literal: true

require 'bcdice/game_system/BlackJacket'
require 'bcdice/dice_table/range_table'

module BCDice
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/DungeonsAndDragons_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/DungeonsAndDragons'

module BCDice
module GameSystem
class DungeonsAndDragons_Korean < DungeonsAndDragons
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/Emoklore_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/Emoklore'

module BCDice
module GameSystem
class Emoklore_Korean < Emoklore
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/GardenOrder_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/GardenOrder'

module BCDice
module GameSystem
class GardenOrder_Korean < GardenOrder
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/JuinKansen_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/JuinKansen'

module BCDice
module GameSystem
class JuinKansen_Korean < JuinKansen
Expand Down
3 changes: 2 additions & 1 deletion lib/bcdice/game_system/KizunaBullet_Korean.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/MagicPunk_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/MagicPunk'

module BCDice
module GameSystem
class MagicPunk_Korean < MagicPunk
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/Nuekagami_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/Nuekagami'

module BCDice
module GameSystem
class Nuekagami_Korean < Nuekagami
Expand Down
1 change: 1 addition & 0 deletions lib/bcdice/game_system/ShinobiGami_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'bcdice/dice_table/table'
require 'bcdice/game_system/ShinobiGami'

module BCDice
module GameSystem
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/TacticalExorcist.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/NinjaSlayer2'

module BCDice
module GameSystem
class TacticalExorcist < NinjaSlayer2
Expand Down
1 change: 1 addition & 0 deletions lib/bcdice/game_system/Ventangle_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'bcdice/base'
require 'bcdice/game_system/Ventangle'

module BCDice
module GameSystem
Expand Down
2 changes: 2 additions & 0 deletions lib/bcdice/game_system/ZombiLine_Korean.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'bcdice/game_system/ZombiLine'

module BCDice
module GameSystem
class ZombiLine_Korean < ZombiLine
Expand Down
1 change: 1 addition & 0 deletions lib/bcdice/game_system/sword_world/transcendent_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

require "bcdice/result"
require "bcdice/translate"
require "bcdice/game_system/SwordWorld"

module BCDice
module GameSystem
Expand Down
71 changes: 71 additions & 0 deletions rubocop/cop/bcdice/game_system_dependency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
require "rubocop"

module RuboCop
module Cop
module BCDice
class GameSystemDependency < Base
extend AutoCorrector

MSG = "superclass file must be required: %<require_path>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)) 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

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