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

Make LintRoller::Plugin sortable #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions lib/lint_roller/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
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