Class: RuboCop::Cop::RBS::Layout::SpaceBeforeColon
- Inherits:
-
RBS::CopBase
- Object
- Base
- RBS::CopBase
- RuboCop::Cop::RBS::Layout::SpaceBeforeColon
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rbs/layout/space_before_colon.rb
Overview
Constant Summary collapse
- MSG =
'Avoid using spaces before `:`.'
Instance Attribute Summary
Attributes inherited from RBS::CopBase
Instance Method Summary collapse
Methods inherited from RBS::CopBase
documentation_url, #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
Methods included from RBS::OnTypeHelper
Instance Method Details
#on_rbs_def(decl) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rubocop/cop/rbs/layout/space_before_colon.rb', line 19 def on_rbs_def(decl) source = processed_source.raw_source loc = decl.location colon_start_pos = source.index(':', loc.start_pos) return unless colon_start_pos word_before_colon_pos = source.rindex(/[^\s]/, colon_start_pos - 1) return unless word_before_colon_pos if word_before_colon_pos + 1 != colon_start_pos colon = range_between(colon_start_pos, colon_start_pos + 1) add_offense(colon) do |corrector| range = range_between( word_before_colon_pos + 1, colon_start_pos, ) corrector.remove(range) end end end |