New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Fix #8256] Fix an error for --auto-gen-config
when running a cop without autocorrect
#8258
[Fix #8256] Fix an error for --auto-gen-config
when running a cop without autocorrect
#8258
Conversation
@@ -126,6 +125,13 @@ def output_cop_comments(output_buffer, cfg, cop_name, offense_count) | |||
output_cop_param_comments(output_buffer, params, default_cfg) | |||
end | |||
|
|||
def support_autocorrect?(cop_name) | |||
cop_class = Cop::Cop.registry.find_by_cop_name(cop_name) | |||
return false unless (cop_instance = cop_class&.new) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it will read better if it says unless cop_class
here. Then you won't need &.
either when you're creating the cop instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, cool! I updated it.
7a85438
to
be1912f
Compare
cop_class = Cop::Cop.registry.find_by_cop_name(cop_name) | ||
return false unless (cop_instance = cop_class&.new) | ||
|
||
cop_instance.respond_to?(:support_autocorrect?) && cop_instance.support_autocorrect? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How come we have cops that don't support this method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
support_autocorrect?
is a class method, so new
was not needed 💦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my mistake, I didn't see it. This is new since the Cop refactor.
Thanks @koic
aaecaf3
to
e6ced1f
Compare
…a cop without autocorrect Fixes rubocop#8256. This PR fixes an error for `--auto-gen-config` when running a cop who do not support auto-correction.
e6ced1f
to
bd2981f
Compare
Thanks! |
Fixes #8256.
This PR fixes an error for
--auto-gen-config
when running a cop who do not support auto-correction.Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and RuboCop for itself, and generates the documentation.