Skip to content

Add to_s representation to LintRoller::Plugin #6

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

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
10 changes: 10 additions & 0 deletions lib/lint_roller/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,15 @@ def supported?(context)
def rules(context)
raise Error.new("Please implement `rules(context)` and return an instance of LintRoller::Rules")
end

def to_s
if about.name && about.version
"#{about.name} #{about.version}"
elsif about.name
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if the version should be optional, because even for built-in plugins you still have the version of the containing library. But I guess some people will have RuboCop or Standard plugins in their Rails apps as well. Kind of weird for me, but I've seen this in wild...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's mostly the reason. More practically, this implementation is based on the fact that the attributes in About are not required. Ideally, both the "name and version" should be present, but when they are not, the decision is to display only the "name" instead of the result of inspect.

about.name
else
inspect
end
end
end
end
2 changes: 2 additions & 0 deletions test/lib/plugin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def test_sample_roller
assert sample_roller.supported?(Context.new(runner: :standard))
refute sample_roller.supported?(Context.new(runner: :rufo))

assert_equal sample_roller.to_s, 'sample-roller 1.2.3'

assert_equal Rules.new(
type: :path,
config_format: :rubocop,
Expand Down