Skip to content
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

Conversation

koic
Copy link
Member

@koic koic commented Jul 7, 2020

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:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -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)
Copy link
Collaborator

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.

Copy link
Member Author

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.

@koic koic force-pushed the fix_error_for_auto_gen_config_when_running_cop_without_autocorrect branch from 7a85438 to be1912f Compare July 7, 2020 06:09
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?
Copy link
Collaborator

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?

Copy link
Member Author

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 💦

Copy link
Contributor

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

@koic koic force-pushed the fix_error_for_auto_gen_config_when_running_cop_without_autocorrect branch 2 times, most recently from aaecaf3 to e6ced1f Compare July 7, 2020 06:30
…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.
@koic koic force-pushed the fix_error_for_auto_gen_config_when_running_cop_without_autocorrect branch from e6ced1f to bd2981f Compare July 7, 2020 09:24
@bbatsov bbatsov merged commit 0d09c1b into rubocop:master Jul 7, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 7, 2020

Thanks!

@koic koic deleted the fix_error_for_auto_gen_config_when_running_cop_without_autocorrect branch July 7, 2020 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"undefined method `support_autocorrect?'" when using "--auto-gen-config"
3 participants