From 89e7bda71cac87170e75230b0acdccafc7382940 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 31 Jan 2025 01:10:32 +0900 Subject: [PATCH 1/2] Make `LintRoller::Plugin` sortable 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. --- lib/lint_roller/plugin.rb | 4 ++++ test/lib/plugin_test.rb | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/lint_roller/plugin.rb b/lib/lint_roller/plugin.rb index 6d614dc..75d7d57 100644 --- a/lib/lint_roller/plugin.rb +++ b/lib/lint_roller/plugin.rb @@ -18,5 +18,9 @@ def supported?(context) def rules(context) raise Error.new("Please implement `rules(context)` and return an instance of LintRoller::Rules") end + + def <=>(other) + about.name <=> other.about.name + end end end diff --git a/test/lib/plugin_test.rb b/test/lib/plugin_test.rb index cd0bb2c..b2fd78b 100644 --- a/test/lib/plugin_test.rb +++ b/test/lib/plugin_test.rb @@ -45,6 +45,35 @@ def rules(context) end end + class AnotherRoller < Plugin + ABOUT = About.new( + name: "another-roller", + version: "1.2.3", + homepage: "https://example.com", + description: "A sample lint roller for sort testing" + ).freeze + + def about + ABOUT + end + + def supported?(context) + [:standard, :rubocop].include?(context.runner) + end + + def rules(context) + if @config[:💥] == true + Rules.new(error: Error.new("Unexpected Boom")) + else + Rules.new( + type: :path, + config_format: :rubocop, + value: "/some/path/to/a/place" + ) + end + end + end + def test_sample_roller sample_roller = SampleRoller.new(:some_config) @@ -67,5 +96,12 @@ def test_sample_roller error: Error.new("Unexpected Boom") ), SampleRoller.new({:💥 => true}).rules(Context.new) end + + def test_sort_sample_roller_with_another_roller + sample_roller = SampleRoller.new(:some_config) + another_roller = AnotherRoller.new(:some_config) + + assert_equal [another_roller, sample_roller], [sample_roller, another_roller].sort + end end end From ff33f9e0634d361f1a572bc5613d79d0186efc01 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Mon, 9 Feb 2026 21:22:59 -0500 Subject: [PATCH 2/2] Declare Plugin as comparable to other plugins In order to be #sort able, plugins must be comparable via #<=> --- lib/lint_roller/plugin.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/lint_roller/plugin.rb b/lib/lint_roller/plugin.rb index 75d7d57..7893319 100644 --- a/lib/lint_roller/plugin.rb +++ b/lib/lint_roller/plugin.rb @@ -1,5 +1,7 @@ module LintRoller class Plugin + include Comparable + # `config' is a Hash of options passed to the plugin by the user def initialize(config = {}) @config = config