Class: RuboCop::Cop::RBS::Style::DuplicatedType
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Style::DuplicatedType
show all
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rbs/style/duplicated_type.rb
Overview
Instance Attribute Summary
Attributes inherited from RBS::CopBase
#processed_rbs_source
Instance Method Summary
collapse
#investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_attribute, #on_rbs_class, #on_rbs_constant, #on_rbs_global, #on_rbs_interface, #on_rbs_module, #on_rbs_new_investigation, #on_rbs_parsing_error, #on_rbs_private, #on_rbs_public, #on_rbs_type_alias, #on_rbs_var, #parse_rbs, #rbs_buffer, #tokenize, #walk
#on_not_type, #on_type
Instance Method Details
#check_type(type) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rubocop/cop/rbs/style/duplicated_type.rb', line 29
def check_type(type)
case type
when ::RBS::Types::Record,
::RBS::Types::Tuple,
::RBS::Types::Optional,
::RBS::Types::ClassInstance,
::RBS::Types::Proc
type.each_type do |t|
check_type(t)
end
when ::RBS::Types::Union,
::RBS::Types::Intersection
set = Set.new
type.types.each do |t|
if set.include?(t)
if t.location
range = location_to_range(t.location)
add_offense(range, message: "Duplicated type `#{t}`.")
end
else
set.add(t)
end
end
type.each_type do |t|
check_type(t)
end
end
end
|
#on_rbs_def(decl) ⇒ Object
20
21
22
23
24
25
26
|
# File 'lib/rubocop/cop/rbs/style/duplicated_type.rb', line 20
def on_rbs_def(decl)
decl.overloads.each do |overload|
overload.method_type.each_type do |type|
check_type(type)
end
end
end
|