Skip to content

Commit

Permalink
Refactor MultipleTEnumValues cop to use TEnum mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
egiurleo committed Apr 19, 2024
1 parent 9d093e0 commit 603bdea
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,23 @@ module Sorbet
# end
# end
class MultipleTEnumValues < Base
def initialize(*)
@scopes = []
super
end
include TEnum

MSG = "`T::Enum` should have at least two values."

# @!method t_enum?(node)
def_node_matcher :t_enum?, <<~PATTERN
(class (const...) (const (const nil? :T) :Enum) ...)
PATTERN

# @!method enums_block?(node)
def_node_matcher :enums_block?, <<~PATTERN
(block (send nil? :enums) ...)
PATTERN

def on_class(node)
@scopes.push(node)
super

add_offense(node) if t_enum?(node) && node.body.nil?
end

def after_class(node)
@scopes.pop
end

def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
return if @scopes.empty? || !t_enum?(@scopes.last)
return unless in_t_enum_class?
return unless enums_block?(node)

scope = @scopes.last
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/cop/sorbet_cops.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
require_relative "sorbet/type_alias_name"
require_relative "sorbet/obsolete_strict_memoization"
require_relative "sorbet/buggy_obsolete_strict_memoization"
require_relative "sorbet/multiple_t_enum_values"

require_relative "sorbet/rbi/forbid_extend_t_sig_helpers_in_shims"
require_relative "sorbet/rbi/forbid_rbi_outside_of_allowed_paths"
Expand All @@ -44,4 +43,6 @@
require_relative "sorbet/sigils/enforce_sigil_order"
require_relative "sorbet/sigils/enforce_single_sigil"

require_relative "sorbet/t_enum/multiple_t_enum_values"

require_relative "sorbet/mutable_constant_sorbet_aware_behaviour"

0 comments on commit 603bdea

Please sign in to comment.