diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d71c1a0d1c..9ab90efaef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ * [#7655](https://github.com/rubocop-hq/rubocop/issues/7655): Fix an error when processing a regexp with a line break at the start of capture parenthesis. ([@koic][]) * [#7647](https://github.com/rubocop-hq/rubocop/issues/7647): Fix an `undefined method on_numblock` error when using Ruby 2.7's numbered parameters. ([@hanachin][]) * [#7675](https://github.com/rubocop-hq/rubocop/issues/7675): Fix a false negative for `Layout/SpaceBeforeFirstArg` when a vertical argument positions are aligned. ([@koic][]) +* [#7688](https://github.com/rubocop-hq/rubocop/issues/7688): Fix a bug in `Style/MethodCallWithArgsParentheses` that made `--auto-gen-config` crash. ([@buehmann][]) ### Changes diff --git a/lib/rubocop/cop/mixin/configurable_enforced_style.rb b/lib/rubocop/cop/mixin/configurable_enforced_style.rb index 7b1d05e0970..8bea3750c1a 100644 --- a/lib/rubocop/cop/mixin/configurable_enforced_style.rb +++ b/lib/rubocop/cop/mixin/configurable_enforced_style.rb @@ -60,6 +60,10 @@ def detected_style=(style) alias conflicting_styles_detected no_acceptable_style! alias unrecognized_style_detected no_acceptable_style! + def style_configured? + cop_config.key?(style_parameter_name) + end + def style @style ||= begin s = cop_config[style_parameter_name].to_sym diff --git a/lib/rubocop/cop/style/method_call_with_args_parentheses.rb b/lib/rubocop/cop/style/method_call_with_args_parentheses.rb index 5f06f9d3e68..6b22f26e2cf 100644 --- a/lib/rubocop/cop/style/method_call_with_args_parentheses.rb +++ b/lib/rubocop/cop/style/method_call_with_args_parentheses.rb @@ -150,6 +150,8 @@ class MethodCallWithArgsParentheses < Cop def initialize(*) super + return unless style_configured? + case style when :require_parentheses extend RequireParentheses @@ -158,6 +160,9 @@ def initialize(*) end end + # @abstract Overridden in style modules + def autocorrect(_node); end + private def args_begin(node)