Class: RuboCop::Cop::SpaceCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::SpaceCorrector
- Extended by:
- SurroundingSpace
- Defined in:
- lib/rubocop/cop/correctors/space_corrector.rb
Overview
This auto-corrects whitespace
Constant Summary
Constants included from SurroundingSpace
RuboCop::Cop::SurroundingSpace::NO_SPACE_COMMAND, RuboCop::Cop::SurroundingSpace::SINGLE_SPACE_REGEXP, RuboCop::Cop::SurroundingSpace::SPACE_COMMAND
Class Attribute Summary collapse
-
.processed_source ⇒ Object
readonly
Returns the value of attribute processed_source.
Class Method Summary collapse
- .add_space(processed_source, corrector, left_token, right_token) ⇒ Object
- .empty_corrections(processed_source, corrector, empty_config, left_token, right_token) ⇒ Object
- .remove_space(processed_source, corrector, left_token, right_token) ⇒ Object
Class Attribute Details
.processed_source ⇒ Object (readonly)
Returns the value of attribute processed_source.
10 11 12 |
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 10 def processed_source @processed_source end |
Class Method Details
.add_space(processed_source, corrector, left_token, right_token) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 36 def add_space(processed_source, corrector, left_token, right_token) @processed_source = processed_source unless left_token.space_after? corrector.insert_after(left_token.pos, ' ') end return if right_token.space_before? corrector.insert_before(right_token.pos, ' ') end |
.empty_corrections(processed_source, corrector, empty_config, left_token, right_token) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 12 def empty_corrections(processed_source, corrector, empty_config, left_token, right_token) @processed_source = processed_source range = range_between(left_token.end_pos, right_token.begin_pos) if offending_empty_space?(empty_config, left_token, right_token) corrector.remove(range) corrector.insert_after(left_token.pos, ' ') elsif offending_empty_no_space?(empty_config, left_token, right_token) corrector.remove(range) end end |
.remove_space(processed_source, corrector, left_token, right_token) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rubocop/cop/correctors/space_corrector.rb', line 24 def remove_space(processed_source, corrector, left_token, right_token) @processed_source = processed_source if left_token.space_after? range = side_space_range(range: left_token.pos, side: :right) corrector.remove(range) end return unless right_token.space_before? range = side_space_range(range: right_token.pos, side: :left) corrector.remove(range) end |