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

Pluginfy rubocop-md #41

Merged
merged 1 commit into from
Feb 17, 2025
Merged

Conversation

koic
Copy link
Member

@koic koic commented Feb 16, 2025

This PR adds support for RuboCop's Plugin feature.

It replaces the ad-hoc Inject with RuboCop plugins introduced in RuboCop 1.72. Additionally, since RuboCop already requires Ruby 2.7 or higher as its runtime, the required_ruby_version will be updated to 2.7.

Follow-up rubocop/rubocop#13792

@koic koic force-pushed the pluginfy_with_lint_roller branch 2 times, most recently from 13c2631 to 37c66f9 Compare February 16, 2025 08:49
This PR adds support for RuboCop's Plugin feature.

It replaces the ad-hoc `Inject` with RuboCop plugins introduced in RuboCop 1.72.
Additionally, since RuboCop already requires Ruby 2.7 or higher as its runtime,
the `required_ruby_version` will be updated to 2.7.

Follow-up rubocop/rubocop#13792
@koic koic force-pushed the pluginfy_with_lint_roller branch from 37c66f9 to 7811d48 Compare February 16, 2025 09:43
@palkan
Copy link
Collaborator

palkan commented Feb 17, 2025

Awesome! Thanks!

@palkan palkan merged commit ba77b7b into rubocop:master Feb 17, 2025
3 checks passed
@koic koic deleted the pluginfy_with_lint_roller branch February 17, 2025 22:19
@palkan
Copy link
Collaborator

palkan commented Feb 18, 2025

@koic For some reason tests were not running on CI, and there is an issue with configuration: it looks like Exclude-s don't work. I had to disable Style/FrozenStringLiteralComment and Layout/CommentIndentation completely to make tests pass. Could it be something with inherit mode?

@koic
Copy link
Member Author

koic commented Feb 18, 2025

It seems to be an effect of rubocop/rubocop#13853 included in RuboCop 1.72.2. Since rubocop/rubocop#13853 is essential as it fixes a potential runtime bug affecting all RuboCop extensions, it cannot be avoided.

The test failures in rubocop-md are caused by its testing mechanism being affected by RuboCop::Config#make_excludes_absolute in the above.

The following is a workaround to make the build pass:

diff --git a/test/test_helper.rb b/test/test_helper.rb
index c36b667..40b5f21 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -18,6 +18,10 @@ require "rubocop-md"
 # NOTE: Since a custom testing framework is used, the following abstraction
 # for plugin callbacks during testing is not implemented yet.
 # https://github.com/rubocop/rubocop/pull/13840
-RuboCop::Plugin.integrate_plugins(RuboCop::Config.new, ["rubocop-md"])
+path = RuboCop::Markdown::CONFIG_DEFAULT.to_s
+hash = RuboCop::ConfigLoader.load_yaml_configuration(path)
+config = RuboCop::Config.new(hash, path)
+new_config = RuboCop::ConfigLoader.merge_with_default(config, path)
+RuboCop::ConfigLoader.instance_variable_set(:@default_configuration, new_config)

 RuboCop::Markdown.config_store = RuboCop::ConfigStore.new

Since I'm not yet fully familiar with the testing mechanism implementation of rubocop-md, this workaround is provided as a temporary fix. However, fundamentally, it would be best to update the testing mechanism to simulate RuboCop's plugin system, similar to rubocop/rubocop#13840.

If a workaround is acceptable for now, I can open a PR. What do you think?

@palkan
Copy link
Collaborator

palkan commented Feb 20, 2025

Thanks! So, as I understand, it only affects tests; thus, we'd better update tests to match the new architecture. I'll take a look later.

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