class RuboCop::Cop::Layout::SpaceAroundMethodCallOperator
Checks method call operators to not have spaces around them.
@example
# bad foo. bar foo .bar foo . bar foo. bar .buzz foo . bar . buzz foo&. bar foo &.bar foo &. bar foo &. bar&. buzz RuboCop:: Cop RuboCop:: Cop:: Base :: RuboCop::Cop # good foo.bar foo.bar.buzz foo .bar .buzz foo&.bar foo&.bar&.buzz RuboCop::Cop RuboCop::Cop::Base ::RuboCop::Cop
Constants
- MSG
- SPACES_REGEXP
Public Instance Methods
on_const(node)
click to toggle source
# File lib/rubocop/cop/layout/space_around_method_call_operator.rb, line 53 def on_const(node) return unless node.loc.respond_to?(:double_colon) && node.loc.double_colon check_space_after_double_colon(node) end
on_send(node)
click to toggle source
# File lib/rubocop/cop/layout/space_around_method_call_operator.rb, line 45 def on_send(node) return unless node.dot? || node.safe_navigation? check_space_before_dot(node) check_space_after_dot(node) end
Also aliased as: on_csend
Private Instance Methods
check_space(begin_pos, end_pos)
click to toggle source
# File lib/rubocop/cop/layout/space_around_method_call_operator.rb, line 87 def check_space(begin_pos, end_pos) return if end_pos <= begin_pos range = range_between(begin_pos, end_pos) return unless range.source.match?(SPACES_REGEXP) add_offense(range) { |corrector| corrector.remove(range) } end
check_space_after_dot(node)
click to toggle source
# File lib/rubocop/cop/layout/space_around_method_call_operator.rb, line 67 def check_space_after_dot(node) dot_pos = node.loc.dot.end_pos selector_pos = # `Proc#call` shorthand syntax if node.method?(:call) && !node.loc.selector node.loc.begin.begin_pos else node.loc.selector.begin_pos end check_space(dot_pos, selector_pos) end
check_space_after_double_colon(node)
click to toggle source
# File lib/rubocop/cop/layout/space_around_method_call_operator.rb, line 81 def check_space_after_double_colon(node) double_colon_pos = node.loc.double_colon.end_pos name_pos = node.loc.name.begin_pos check_space(double_colon_pos, name_pos) end
check_space_before_dot(node)
click to toggle source
# File lib/rubocop/cop/layout/space_around_method_call_operator.rb, line 61 def check_space_before_dot(node) receiver_pos = node.receiver.source_range.end_pos dot_pos = node.loc.dot.begin_pos check_space(receiver_pos, dot_pos) end