Skip to content

Make LintRoller::Plugin sortable#7

Merged
jasonkarns merged 2 commits intostandardrb:mainfrom
koic:make_plugin_class_sortable
Feb 10, 2026
Merged

Make LintRoller::Plugin sortable#7
jasonkarns merged 2 commits intostandardrb:mainfrom
koic:make_plugin_class_sortable

Conversation

@koic
Copy link
Contributor

@koic koic commented Feb 4, 2025

Typically, it is expected that LintRoller::Plugin#about includes a name, and sorting would be performed based on that name. However, currently, executing sort on LintRoller results in the following error:

ArgumentError: comparison of LintRoller::PluginTest::SampleRoller with LintRoller::PluginTest::AnotherRoller failed

This PR makes LintRoller::Plugin sortable by name. I considered including the version as well, but I could not come up with any use cases where multiple plugins with the same name would need to be processed simultaneously.

Typically, it is expected that `LintRoller::Plugin#about` includes a name,
and sorting would be performed based on that name. However, currently,
executing `sort` on LintRoller results in the following error:

```console
ArgumentError: comparison of LintRoller::PluginTest::SampleRoller with LintRoller::PluginTest::AnotherRoller failed
```

This PR makes `LintRoller::Plugin` sortable by name. I considered including the version as well,
but I could not come up with any use cases where multiple plugins with the same name would need to be processed simultaneously.
@koic koic force-pushed the make_plugin_class_sortable branch from aecdd2e to 89e7bda Compare February 4, 2025 18:23
@koic koic changed the title Make Plugin class sortable Make LintRoller::Plugin sortable Feb 4, 2025
@jasonkarns
Copy link
Contributor

This looks fine to me. I also like the idea of enhancing to use version as secondary sort (not necessary to land in this PR, IMO)

Would you mind sharing a bit more about the use case for this? I'm curious what scenarios want plugins to be sorted.

Standard itself would likely not want plugins to be sorted for loading, because standard applies a "first-in wins" rule for configurations. Therefore, the order that plugins are listed and included must be preserved per the user's configuration.

But that shouldn't stop this PR.

@koic
Copy link
Contributor Author

koic commented Feb 2, 2026

Thanks for the response. You are right that I should have described the use case.

Currently, the order of plugins shown by rubocop -V depends on the order in which they are listed under plugins: in .rubocop.yml. As a result, depending on that order, the output may appear unsorted, as in the example below:

$ bundle exec rubocop -V
1.84.0 (using Parser 3.3.10.1, rubocop-ast 1.49.0, analyzing as Ruby 2.7, running on ruby 4.1.0) [arm64-darwin24]
  - rubocop-rake 0.7.1
  - rubocop-performance 1.26.1
  - rubocop-rspec 3.9.0

By contrast, with the approach used before the introduction of lint_roller, plugins were always displayed in sorted order.
https://github.com/rubocop/rubocop/blob/v1.84.0/lib/rubocop/version.rb#L85

From a user's perspective, having the list of plugin names shown by rubocop -V in a mechanically sorted order would be easier to understand. However, with the current implementation of lint_roller, a simple sort method call results in an error as described above, which is currently blocking this behavior.


def <=>(other)
about.name <=> other.about.name
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we include Comparable now that this implements the interface?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use case was simply to be able to call sort without raising an error, not to compare objects via comparison operator methods. For that reason, Comparable is not mixed-in, and there isn't a strong preference either way.

Copy link
Contributor

@jasonkarns jasonkarns Feb 10, 2026

Choose a reason for hiding this comment

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

Understood, thank you.

I like the consistency of being a Comparable when implementing the <=> interface, so I've added it to your branch. Merging momentarily.

Thank you for the contribution and your patience with this PR.

In order to be #sort able, plugins must be comparable via #<=>
@jasonkarns jasonkarns merged commit e05e208 into standardrb:main Feb 10, 2026
5 checks passed
@koic koic deleted the make_plugin_class_sortable branch February 10, 2026 02:46
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.

3 participants