Class: RuboCop::Cop::RBS::Layout::IndentationWidth
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Layout::IndentationWidth
show all
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rbs/layout/indentation_width.rb
Overview
Checks if the indentation width.
Instance Attribute Summary
Attributes inherited from RBS::CopBase
#processed_rbs_source
Instance Method Summary
collapse
documentation_url, #investigation_rbs, #location_to_range, #on_new_investigation, #on_other_file, #on_rbs_attribute, #on_rbs_class, #on_rbs_constant, #on_rbs_def, #on_rbs_global, #on_rbs_interface, #on_rbs_module, #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(decl, expect:) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/rubocop/cop/rbs/layout/indentation_width.rb', line 43
def check(decl, expect:)
line_start_pos = line_start_pos(decl)
actual = @first_char_columns[decl.location.start_line - 1]
if actual != expect
range = range_between(line_start_pos, line_start_pos + actual)
message = "Use #{expect} (not #{actual}) spaces for indentation."
add_offense(range, message: message) do |corrector|
corrector.replace(range, ' ' * expect)
end
end
end
|
#check_indentation(decl, expect:) ⇒ Object
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/rubocop/cop/rbs/layout/indentation_width.rb', line 32
def check_indentation(decl, expect:)
if decl.respond_to?(:members)
check(decl, expect: expect)
decl.members.each do |member|
check_indentation(member, expect: expect + 2)
end
else
check(decl, expect: expect)
end
end
|
#line_start_pos(decl) ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/rubocop/cop/rbs/layout/indentation_width.rb', line 55
def line_start_pos(decl)
rindex = processed_source.raw_source.rindex(/\R/, decl.location.start_pos)
if rindex
rindex + 1
else
0
end
end
|
#on_rbs_new_investigation ⇒ Object
23
24
25
26
27
28
29
30
|
# File 'lib/rubocop/cop/rbs/layout/indentation_width.rb', line 23
def on_rbs_new_investigation
@first_char_columns = processed_source.raw_source.each_line.map do |line|
line.index(/[^[:space:]]/) || 0
end
processed_rbs_source.decls.each do |decl|
check_indentation(decl, expect: 0)
end
end
|