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

Rubocop expects formatters to be a string #168

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

macumber
Copy link
Contributor

I found that this change is needed using ruby 3.2.2 as rubocop expects BUILTIN_FORMATTERS_FOR_KEYS to be a map of keys to strings and not to classes, see rubocop-1.63.5\lib\rubocop\formatter\formatter_set.rb

Without this change I get the error "no implicit conversion of Class into String" when trying to run rubocop -d -f extension_review -o report.html


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.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -26,8 +26,8 @@
# formatters. Naughty! Naughty!
class RuboCop::Formatter::FormatterSet
formatters = BUILTIN_FORMATTERS_FOR_KEYS.dup
formatters['extension_review'] =
RuboCop::Formatter::ExtensionReviewFormatter
formatters['extension_review'] = 'ExtensionReviewFormatter'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will then look for 'ExtensionReviewFormatter' in the RuboCop::Formatter namespace?

Copy link
Contributor Author

@macumber macumber Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, RuboCop::Formatter.const_get(formatter_name) at https://github.com/rubocop/rubocop/blob/master/lib/rubocop/formatter/formatter_set.rb#L102 is calling const_get on the RuboCop::Formatter module. The argument to const_get is a symbol or a string, https://www.rubydoc.info/stdlib/core/Module:const_get. Maybe this used to accept a Class in Ruby 2.x but it seems to not accept that in Ruby 3.x.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Thank you for the PR. I guess the CI tests never tests the custom formatter.

I had a quick look at RuboCop docs, and it appear to still be lacking a clear good API to add custom extensions and formatters without monkey patching some parts of RuboCop. So this has always been something that has a higher risk of breaking.

@thomthom thomthom merged commit f4ee056 into SketchUp:main Jun 4, 2024
6 checks passed
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.

2 participants