Skip to content

Commit

Permalink
[Fix rubocop#7641] Remove Style/BracesAroundHashParameters cop
Browse files Browse the repository at this point in the history
  • Loading branch information
pocke committed Jan 15, 2020
1 parent 4de0f32 commit fd6dcac
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 1,083 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
### Changes

* [#7636](https://github.com/rubocop-hq/rubocop/issues/7636): Remove `console` from `Lint/Debugger` to prevent false positives. ([@gsamokovarov][])
* [#7641](https://github.com/rubocop-hq/rubocop/issues/7641): **(Breaking)** Remove `Style/BracesAroundHashParameters` cop. ([@pocke][])

## 0.79.0 (2020-01-06)

Expand Down
18 changes: 0 additions & 18 deletions config/default.yml
Expand Up @@ -2356,24 +2356,6 @@ Style/BlockDelimiters:
# collection.each do |element| puts element end
AllowBracesOnProceduralOneLiners: false

Style/BracesAroundHashParameters:
Description: 'Enforce braces style around hash parameters.'
Enabled: true
VersionAdded: '0.14.1'
VersionChanged: '0.28'
EnforcedStyle: no_braces
SupportedStyles:
# The `braces` style enforces braces around all method parameters that are
# hashes.
- braces
# The `no_braces` style checks that the last parameter doesn't have braces
# around it.
- no_braces
# The `context_dependent` style checks that the last parameter doesn't have
# braces around it, but requires braces if the second to last parameter is
# also a hash literal.
- context_dependent

Style/CaseEquality:
Description: 'Avoid explicit use of the case equality operator(===).'
StyleGuide: '#no-case-equality'
Expand Down
1 change: 0 additions & 1 deletion lib/rubocop.rb
Expand Up @@ -402,7 +402,6 @@
require_relative 'rubocop/cop/style/begin_block'
require_relative 'rubocop/cop/style/block_comments'
require_relative 'rubocop/cop/style/block_delimiters'
require_relative 'rubocop/cop/style/braces_around_hash_parameters'
require_relative 'rubocop/cop/style/case_equality'
require_relative 'rubocop/cop/style/character_literal'
require_relative 'rubocop/cop/style/class_and_module_children'
Expand Down
3 changes: 2 additions & 1 deletion lib/rubocop/config_obsoletion.rb
Expand Up @@ -69,7 +69,8 @@ class ConfigObsoletion
'Style/TrailingCommaInHashLiteral',
'Style/TrailingCommaInLiteral' => 'Style/TrailingCommaInArrayLiteral ' \
'and/or ' \
'Style/TrailingCommaInHashLiteral'
'Style/TrailingCommaInHashLiteral',
'Style/BracesAroundHashParameters' => nil
}.map do |old_name, other_cops|
if other_cops
more = ". Please use #{other_cops} instead".gsub(%r{[A-Z]\w+/\w+},
Expand Down
4 changes: 0 additions & 4 deletions lib/rubocop/cop/layout/multiline_hash_brace_layout.rb
Expand Up @@ -105,10 +105,6 @@ class MultilineHashBraceLayout < Cop
ALWAYS_SAME_LINE_MESSAGE = 'Closing hash brace must be on the same ' \
'line as the last hash element.'

def self.autocorrect_incompatible_with
[Style::BracesAroundHashParameters]
end

def on_hash(node)
check_brace_layout(node)
end
Expand Down
11 changes: 2 additions & 9 deletions lib/rubocop/cop/layout/space_inside_hash_literal_braces.rb
Expand Up @@ -83,17 +83,10 @@ def on_hash(node)

def autocorrect(range)
lambda do |corrector|
# It is possible that BracesAroundHashParameters will remove the
# braces while this cop inserts spaces. This can lead to unwanted
# changes to the inspected code. If we replace the brace with a
# brace plus space (rather than just inserting a space), then any
# removal of the same brace will give us a clobbering error. This
# in turn will make RuboCop fall back on cop-by-cop
# auto-correction. Problem solved.
case range.source
when /\s/ then corrector.remove(range)
when '{' then corrector.replace(range, '{ ')
else corrector.replace(range, ' }')
when '{' then corrector.insert_after(range, ' ')
else corrector.insert_before(range, ' ')
end
end
end
Expand Down
11 changes: 2 additions & 9 deletions lib/rubocop/cop/mixin/trailing_comma.rb
Expand Up @@ -23,7 +23,7 @@ def check(node, items, kind, begin_pos, end_pos)
if comma_offset && !inside_comment?(after_last_item, comma_offset)
check_comma(node, kind, after_last_item.begin_pos + comma_offset)
elsif should_have_comma?(style, node)
put_comma(node, items, kind)
put_comma(items, kind)
end
end

Expand Down Expand Up @@ -145,9 +145,7 @@ def avoid_comma(kind, comma_begin_pos, extra_info)
add_offense(range, location: range, message: msg)
end

def put_comma(node, items, kind)
return if avoid_autocorrect?(elements(node))

def put_comma(items, kind)
last_item = items.last
return if last_item.block_pass_type?

Expand All @@ -169,11 +167,6 @@ def autocorrect_range(item)
range_between(expr.begin_pos + ix, expr.end_pos)
end

# By default, there's no reason to avoid auto-correct.
def avoid_autocorrect?(_nodes)
false
end

def any_heredoc?(items)
items.any? { |item| heredoc?(item) }
end
Expand Down
209 changes: 0 additions & 209 deletions lib/rubocop/cop/style/braces_around_hash_parameters.rb

This file was deleted.

22 changes: 0 additions & 22 deletions lib/rubocop/cop/style/trailing_comma_in_arguments.rb
Expand Up @@ -68,28 +68,6 @@ def autocorrect(range)
def self.autocorrect_incompatible_with
[Layout::HeredocArgumentClosingParenthesis]
end

private

def avoid_autocorrect?(args)
args.last.hash_type? && args.last.braces? &&
braces_will_be_removed?(args)
end

# Returns true if running with --auto-correct would remove the braces
# of the last argument.
def braces_will_be_removed?(args)
brace_config = config.for_cop('Style/BracesAroundHashParameters')
return false unless brace_config.fetch('Enabled')
return false if brace_config['AutoCorrect'] == false

brace_style = brace_config['EnforcedStyle']
return true if brace_style == 'no_braces'

return false unless brace_style == 'context_dependent'

args.one? || !args[-2].hash_type?
end
end
end
end
Expand Down
1 change: 0 additions & 1 deletion manual/cops.md
Expand Up @@ -315,7 +315,6 @@ In the following section you find all available cops:
* [Style/BeginBlock](cops_style.md#stylebeginblock)
* [Style/BlockComments](cops_style.md#styleblockcomments)
* [Style/BlockDelimiters](cops_style.md#styleblockdelimiters)
* [Style/BracesAroundHashParameters](cops_style.md#stylebracesaroundhashparameters)
* [Style/CaseEquality](cops_style.md#stylecaseequality)
* [Style/CharacterLiteral](cops_style.md#stylecharacterliteral)
* [Style/ClassAndModuleChildren](cops_style.md#styleclassandmodulechildren)
Expand Down

0 comments on commit fd6dcac

Please sign in to comment.