Add to_s representation to LintRoller::Plugin#6
Conversation
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.
1395543 to
59372f3
Compare
to_s representation to LintRoller::Plugin`to_s representation to LintRoller::Plugin
| def to_s | ||
| if about.name && about.version | ||
| "#{about.name} #{about.version}" | ||
| elsif about.name |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
|
I'm planning to merge this in soon, but wanted to float a tweak to the string format. Personally, I would probably like to see Or alternatively, As far as I can tell, either of these forms should probably be fine for rubocop's needs? Is there a preference? (I think I'm leaning towards |
While developing rubocop/rubocop#13792, I noticed that
LintRoller::Pluginlacks a string representation. For example, in RuboCop, there is a feature to display a list of plugins using therubocop -Vcommand: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.