Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
[Fix rubocop#2228] Use the config of a related cop whether it's enabl…
Browse files Browse the repository at this point in the history
…ed or not
  • Loading branch information
madwort committed Jan 31, 2016
1 parent 0e4f86d commit b121b85
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* [#2703](https://github.com/bbatsov/rubocop/issues/2703): Handle byte order mark in `Style/IndentationWidth`, `Style/ElseAlignment`, `Lint/EndAlignment`, and `Lint/DefEndAlignment`. ([@jonas054][])
* [#2710](https://github.com/bbatsov/rubocop/pull/2710): Fix handling of fullwidth characters in some cops. ([@seikichi][])
* [#2690](https://github.com/bbatsov/rubocop/issues/2690): Fix alignment of operands that are part of an assignment in `Style/MultilineOperationIndentation`. ([@jonas054][])
* [#2228](https://github.com/bbatsov/rubocop/issues/2228): Use the config of a related cop whether it's enabled or not. ([@madwort][])

### Changes

Expand Down Expand Up @@ -1926,3 +1927,4 @@
[@stormbreakerbg]: https://github.com/stormbreakerbg
[@owst]: https://github.com/owst
[@seikichi]: https://github.com/seikichi
[@madwort]: https://github.com/madwort
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/space_after_punctuation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def investigate(processed_source)

def space_forbidden_before_rcurly?
cfg = config.for_cop('Style/SpaceInsideBlockBraces')
style = cfg['Enabled'] ? cfg['EnforcedStyle'] : 'space'
style = cfg['EnforcedStyle'] || 'space'
style == 'no_space'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/mixin/space_before_punctuation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def investigate(processed_source)

def space_required_after_lcurly?
cfg = config.for_cop('Style/SpaceInsideBlockBraces')
style = cfg['Enabled'] ? cfg['EnforcedStyle'] : 'space'
style = cfg['EnforcedStyle'] || 'space'
style == 'space'
end

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/else_alignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def check_assignment(node, rhs)
return unless rhs

end_config = config.for_cop('Lint/EndAlignment')
style = end_config['Enabled'] ? end_config['AlignWith'] : 'keyword'
style = end_config['AlignWith'] || 'keyword'
base = variable_alignment?(node.loc, rhs, style.to_sym) ? node : rhs

return if rhs.type != :if
Expand Down
8 changes: 2 additions & 6 deletions lib/rubocop/cop/style/indentation_width.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,7 @@ def on_send(node)
*_, body = *args.first

def_end_config = config.for_cop('Lint/DefEndAlignment')
style = if def_end_config['Enabled']
def_end_config['AlignWith']
else
'start_of_line'
end
style = def_end_config['AlignWith'] || 'start_of_line'
base = style == 'def' ? args.first : node

check_indentation(base.source_range, body)
Expand Down Expand Up @@ -174,7 +170,7 @@ def check_assignment(node, rhs)
return unless rhs

end_config = config.for_cop('Lint/EndAlignment')
style = end_config['Enabled'] ? end_config['AlignWith'] : 'keyword'
style = end_config['AlignWith'] || 'keyword'
base = variable_alignment?(node.loc, rhs, style.to_sym) ? node : rhs

case rhs.type
Expand Down
8 changes: 0 additions & 8 deletions spec/rubocop/cop/style/else_alignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,6 @@

include_examples 'assignment and if with keyword alignment'
end

context 'when alignment style is keyword by default' do
let(:end_alignment_config) do
{ 'Enabled' => false, 'AlignWith' => 'variable' }
end

include_examples 'assignment and if with keyword alignment'
end
end

it 'accepts an if/else branches with rescue clauses' do
Expand Down
8 changes: 0 additions & 8 deletions spec/rubocop/cop/style/indentation_width_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -597,14 +597,6 @@

include_examples 'assignment and if with keyword alignment'
end

context 'when alignment style is keyword by default' do
let(:end_alignment_config) do
{ 'Enabled' => false, 'AlignWith' => 'variable' }
end

include_examples 'assignment and if with keyword alignment'
end
end

it 'accepts an if/else branches with rescue clauses' do
Expand Down

0 comments on commit b121b85

Please sign in to comment.