Class: RuboCop::Cop::RBS::Lint::LiteralIntersection
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Lint::LiteralIntersection
show all
- Defined in:
- lib/rubocop/cop/rbs/lint/literal_intersection.rb
Overview
Checks that there are no repeated overload bodies
Constant Summary
collapse
- MSG =
"Don't use literals with `&`."
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_class, #on_rbs_interface, #on_rbs_module, #on_rbs_new_investigation, #on_rbs_parsing_error, #on_rbs_private, #on_rbs_public, #parse_rbs, #rbs_buffer, #tokenize, #walk
#on_not_type, #on_type
Instance Method Details
#check_intersection(intersection) ⇒ Object
41
42
43
44
45
|
# File 'lib/rubocop/cop/rbs/lint/literal_intersection.rb', line 41
def check_intersection(intersection)
intersection.types.each do |type|
check_intersection_child(type)
end
end
|
#check_intersection_child(type) ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/rubocop/cop/rbs/lint/literal_intersection.rb', line 47
def check_intersection_child(type)
case type
when ::RBS::Types::Literal
range = location_to_range(type.location)
add_offense(range)
when ::RBS::Types::Intersection
check_intersection(type)
end
end
|
#check_type(type) ⇒ Object
27
28
29
30
31
|
# File 'lib/rubocop/cop/rbs/lint/literal_intersection.rb', line 27
def check_type(type)
on_type([::RBS::Types::Intersection], type) do |intersection|
check_intersection(intersection)
end
end
|
#on_rbs_constant(type) ⇒ Object
Also known as:
on_rbs_global, on_rbs_type_alias, on_rbs_attribute, on_rbs_var
33
34
35
|
# File 'lib/rubocop/cop/rbs/lint/literal_intersection.rb', line 33
def on_rbs_constant(type)
check_type(type.type)
end
|
#on_rbs_def(decl) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/rubocop/cop/rbs/lint/literal_intersection.rb', line 19
def on_rbs_def(decl)
decl.overloads.each do |overload|
overload.method_type.each_type do |type|
check_type(type)
end
end
end
|