Skip to content
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

Add to_s representation to LintRoller::Plugin #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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.

2 participants