Skip to content

Commit

Permalink
Address some small problems in SpaceInsideParens
Browse files Browse the repository at this point in the history
  • Loading branch information
bbatsov committed Apr 16, 2018
1 parent c6efac6 commit c44dc83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
11 changes: 5 additions & 6 deletions lib/rubocop/cop/layout/space_inside_parens.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ module Layout
# Checks for spaces inside ordinary round parentheses.
#
# @example EnforcedStyle: no_space (default)
# # The `no_space` style enforces that parentheses do not have spaces
# # The `no_space` style enforces that parentheses do not have spaces.
#
# @example
# # bad
# f( 3)
# g = (a + 3 )
Expand All @@ -20,7 +19,7 @@ module Layout
# @example EnforcedStyle: space
# # The `space` style enforces that parentheses have a space at the
# # beginning and end.
# # Note: Empty paraentheses should not have spaces.
# # Note: Empty parentheses should not have spaces.
#
# # bad
# f(3)
Expand All @@ -35,18 +34,18 @@ module Layout
class SpaceInsideParens < Cop
include SurroundingSpace
include RangeHelp
include ConfigurableEnforcedStyle

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

def investigate(processed_source)
@processed_source = processed_source

if cop_config['EnforcedStyle'] == 'space'
if style == :space
each_missing_space(processed_source.tokens) do |range|
add_offense(range, location: range, message: MSG_SPACE)
end

else
each_extraneous_space(processed_source.tokens) do |range|
add_offense(range, location: range)
Expand All @@ -56,7 +55,7 @@ def investigate(processed_source)

def autocorrect(range)
lambda do |corrector|
if cop_config['EnforcedStyle'] == 'space'
if style == :space
corrector.insert_before(range, ' ')
else
corrector.remove(range)
Expand Down
7 changes: 3 additions & 4 deletions manual/cops_layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -3780,9 +3780,8 @@ Checks for spaces inside ordinary round parentheses.
#### EnforcedStyle: no_space (default)
```ruby
# The `no_space` style enforces that parentheses do not have spaces
```
```ruby
# The `no_space` style enforces that parentheses do not have spaces.

# bad
f( 3)
g = (a + 3 )
Expand All @@ -3796,7 +3795,7 @@ g = (a + 3)
```ruby
# The `space` style enforces that parentheses have a space at the
# beginning and end.
# Note: Empty paraentheses should not have spaces.
# Note: Empty parentheses should not have spaces.

# bad
f(3)
Expand Down

0 comments on commit c44dc83

Please sign in to comment.