Class: RuboCop::Cop::Layout::SpaceInsideParens

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
ConfigurableEnforcedStyle, RangeHelp, SurroundingSpace
Defined in:
lib/rubocop/cop/layout/space_inside_parens.rb

Overview

Checks for spaces inside ordinary round parentheses.

Examples:

EnforcedStyle: no_space (default)

# The `no_space` style enforces that parentheses do not have spaces.

# bad
f( 3)
g = (a + 3 )
f( )

# good
f(3)
g = (a + 3)
f()

EnforcedStyle: space

# The `space` style enforces that parentheses have a space at the
# beginning and end.
# Note: Empty parentheses should not have spaces.

# bad
f(3)
g = (a + 3)
y( )

# good
f( 3 )
g = ( a + 3 )
y()

EnforcedStyle: compact

# The `compact` style enforces that parentheses have a space at the
# beginning with the exception that successive parentheses are allowed.
# Note: Empty parentheses should not have spaces.

# bad
f(3)
g = (a + 3)
y( )
g( f( x ) )
g( f( x( 3 ) ), 5 )
g( ( ( 3 + 5 ) * f) ** x, 5 )

# good
f( 3 )
g = ( a + 3 )
y()
g( f( x ))
g( f( x( 3 )), 5 )
g((( 3 + 5 ) * f ) ** x, 5 )

Constant Summary collapse

MSG =
'Space inside parentheses detected.'
MSG_SPACE =
'No space inside parentheses detected.'

Constants included from SurroundingSpace

SurroundingSpace::NO_SPACE_COMMAND, SurroundingSpace::SINGLE_SPACE_REGEXP, SurroundingSpace::SPACE_COMMAND

Constants inherited from Base

Base::RESTRICT_ON_SEND

Instance Attribute Summary

Attributes inherited from Base

#config, #processed_source

Instance Method Summary collapse

Methods included from AutoCorrector

support_autocorrect?

Methods included from ConfigurableEnforcedStyle

#alternative_style, #alternative_styles, #ambiguous_style_detected, #correct_style_detected, #detected_style, #detected_style=, #no_acceptable_style!, #no_acceptable_style?, #opposite_style_detected, #style, #style_configured?, #style_detected, #style_parameter_name, #supported_styles, #unexpected_style_detected

Methods inherited from Base

#active_support_extensions_enabled?, #add_global_offense, #add_offense, autocorrect_incompatible_with, badge, #begin_investigation, #callbacks_needed, callbacks_needed, #config_to_allow_offenses, #config_to_allow_offenses=, #cop_config, cop_name, #cop_name, department, documentation_url, exclude_from_registry, #excluded_file?, #external_dependency_checksum, inherited, #initialize, #inspect, joining_forces, lint?, match?, #message, #offenses, #on_investigation_end, #on_other_file, #parse, #ready, #relevant_file?, support_autocorrect?, support_multiple_source?, #target_rails_version, #target_ruby_version

Methods included from ExcludeLimit

#exclude_limit

Methods included from AutocorrectLogic

#autocorrect?, #autocorrect_enabled?, #autocorrect_requested?, #autocorrect_with_disable_uncorrectable?, #correctable?, #disable_uncorrectable?, #safe_autocorrect?

Methods included from IgnoredNode

#ignore_node, #ignored_node?, #part_of_ignored_node?

Methods included from Util

silence_warnings

Constructor Details

This class inherits a constructor from RuboCop::Cop::Base

Instance Method Details

#on_new_investigationObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rubocop/cop/layout/space_inside_parens.rb', line 66

def on_new_investigation
  tokens = processed_source.sorted_tokens

  case style
  when :space
    process_with_space_style(tokens)
  when :compact
    process_with_compact_style(tokens)
  else
    correct_extraneous_space(tokens)
  end
end