diff --git a/lib/lint_roller/plugin.rb b/lib/lint_roller/plugin.rb index 6d614dc..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 @@ -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 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