diff --git a/CHANGELOG.md b/CHANGELOG.md index 0daac1a16cd9..2f4f88cf46cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -1926,3 +1927,4 @@ [@stormbreakerbg]: https://github.com/stormbreakerbg [@owst]: https://github.com/owst [@seikichi]: https://github.com/seikichi +[@madwort]: https://github.com/madwort diff --git a/lib/rubocop/cop/mixin/space_after_punctuation.rb b/lib/rubocop/cop/mixin/space_after_punctuation.rb index 4794ddb27b92..d58d672112af 100644 --- a/lib/rubocop/cop/mixin/space_after_punctuation.rb +++ b/lib/rubocop/cop/mixin/space_after_punctuation.rb @@ -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 diff --git a/lib/rubocop/cop/mixin/space_before_punctuation.rb b/lib/rubocop/cop/mixin/space_before_punctuation.rb index 05cec36975ae..14abcedf5c35 100644 --- a/lib/rubocop/cop/mixin/space_before_punctuation.rb +++ b/lib/rubocop/cop/mixin/space_before_punctuation.rb @@ -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 diff --git a/lib/rubocop/cop/style/else_alignment.rb b/lib/rubocop/cop/style/else_alignment.rb index 4c886929bcb7..07e549fd365d 100644 --- a/lib/rubocop/cop/style/else_alignment.rb +++ b/lib/rubocop/cop/style/else_alignment.rb @@ -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 diff --git a/lib/rubocop/cop/style/indentation_width.rb b/lib/rubocop/cop/style/indentation_width.rb index 799a17af346a..883e0cf456a8 100644 --- a/lib/rubocop/cop/style/indentation_width.rb +++ b/lib/rubocop/cop/style/indentation_width.rb @@ -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) @@ -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 diff --git a/spec/rubocop/cop/style/else_alignment_spec.rb b/spec/rubocop/cop/style/else_alignment_spec.rb index 06ad37516a07..3f90229f553c 100644 --- a/spec/rubocop/cop/style/else_alignment_spec.rb +++ b/spec/rubocop/cop/style/else_alignment_spec.rb @@ -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 diff --git a/spec/rubocop/cop/style/indentation_width_spec.rb b/spec/rubocop/cop/style/indentation_width_spec.rb index 36ce89daed9c..e5e635fa95b5 100644 --- a/spec/rubocop/cop/style/indentation_width_spec.rb +++ b/spec/rubocop/cop/style/indentation_width_spec.rb @@ -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