Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/lint_roller/plugin.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,5 +20,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
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.

end
end
36 changes: 36 additions & 0 deletions test/lib/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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