Skip to content

Commit 1395543

Browse files
committed
Add to_s representation to LintRoller::Plugin`
While developing rubocop/rubocop#13792, I noticed that `LintRoller::Plugin` lacks a string representation. For example, in RuboCop, there is a feature to display a list of plugins using the `rubocop -V` command: ```console $ bundle exec rubocop -V 1.71.2 (using Parser 3.3.7.0, rubocop-ast 1.38.0, analyzing as Ruby 2.7, running on ruby 3.4.1) [x86_64-darwin23] - rubocop-performance 1.23.1 - rubocop-rake 0.6.0 - rubocop-rspec 3.4.0 ``` In cases like this, having a string representation would simplify things. I'm not sure what the best string representation would be, but I have chosen to include the name and version as they provide the minimal and most easily identifiable details.
1 parent 7c1dc26 commit 1395543

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/lint_roller/plugin.rb

+10
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,15 @@ def supported?(context)
1818
def rules(context)
1919
raise Error.new("Please implement `rules(context)` and return an instance of LintRoller::Rules")
2020
end
21+
22+
def to_s
23+
if about.name && about.version
24+
"#{about.name} #{about.version}"
25+
elsif about.name
26+
about.name
27+
else
28+
inspect
29+
end
30+
end
2131
end
2232
end

test/lib/plugin_test.rb

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ def test_sample_roller
5858
assert sample_roller.supported?(Context.new(runner: :standard))
5959
refute sample_roller.supported?(Context.new(runner: :rufo))
6060

61+
assert_equal sample_roller.to_s, 'sample-roller 1.2.3'
62+
6163
assert_equal Rules.new(
6264
type: :path,
6365
config_format: :rubocop,

0 commit comments

Comments
 (0)