Skip to content

Add to_s representation to LintRoller::Plugin#6

Open
koic wants to merge 1 commit intostandardrb:mainfrom
koic:support_puglin_to_s_representation
Open

Add to_s representation to LintRoller::Plugin#6
koic wants to merge 1 commit intostandardrb:mainfrom
koic:support_puglin_to_s_representation

Conversation

@koic
Copy link
Contributor

@koic koic commented Feb 4, 2025

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:

$ 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.

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.
@koic koic force-pushed the support_puglin_to_s_representation branch from 1395543 to 59372f3 Compare February 4, 2025 18:04
@koic koic changed the title Add to_s representation to LintRoller::Plugin` Add to_s representation to LintRoller::Plugin Feb 4, 2025
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.

@jasonkarns
Copy link
Contributor

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 foo@1.2.3 as the full string when version is present. This in some views, this would help when printing a collection of Plugins (allowing whitespace alone to delimit each plugin).

Or alternatively, foo (1.2.3). This format is less parser friendly, but has the benefit of being the format that both gem and bundler use when printing gem + version information.

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 name (version) for consistency with ruby ecosystem.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants