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

Adopt standard for linting #90

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

rossta
Copy link
Contributor

@rossta rossta commented Apr 6, 2023

This PR adds standard for Ruby linting.

I can see that a branch started for rubocop several years old but that also included quite a bit of refactoring. I took a conservative approach to avoid rewriting library code if possible. Standard is a wrapper around Rubocop so the lint changes are "in the spirit" of the original PR.

For review, it may make sense to review by commit; commit 24bd6b8 is one where I used standardrb --fix, the other lint errors I fixed by hand.

Copy link
Collaborator

@metavida metavida left a comment

Choose a reason for hiding this comment

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

I love the idea of adopting a linter to help ease the developer experience and avoid code style bikeshedding. And it's always an ambitious project to make happen in an existing repo. And honestly I don't have strong feelings about the specific linting rules at this point, so picking an opinionated framework like standard ruby makes sense to me.

At the moment these are the blockers in this PR:

  • Must: Update the README so that the "Lend a Hand" section includes information about using the linter.
  • Must: Fix merge conflicts with the master branch (Not sure if it's easier to re-apply linter fixes vs resolving the many merge conflicts.

Other would-like changes:

  • Integrate the linter with rake guard since that's already an option for unit tests
  • After I fix the CI pipeline, we/I should integrate the linter as a step in CI.

Hope this helps! Let me know what you're thinking.


gemspec

gem 'coveralls', require: false
gem "coveralls", require: false
gem "standard"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps doesn't matter, but it surprised me that the standard gem wasn't within the :test group like the Standard README shows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honest question: how do you use bundle groups for gem development?

I tend to think of gems as having only direct dependencies and development dependencies. Any gem in the Gemfile is effectively a "non-direct" dependency. I could imagine a use case, maybe CI?, where one to filter out a certain subset of dependencies but I couldn't find a place where this gem might be doing that now.

For app development, the use cases are more clear since frameworks (in other words, Rails) bake in the notion of separate environments.

Copy link
Collaborator

@metavida metavida May 9, 2023

Choose a reason for hiding this comment

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

Honest answer, I have no clue! My Ruby background is primarily from working on Rails SaaS apps so I'm not sure about library development requirements/best practices. Also my day job has taken me away from Ruby a bit so I'm feeling rusty.

Thinking about this a bit more deeply, I suppose it's the ruby-oembed.gemspec file that specifies the peer dependencies that apps consuming this gem will be installing.

Meanwhile the Gemfile I suppose is only used for local development.

So if anything I'd lean towards removing the groups from the Gemfile (since they don't currently appear to be in use) in an attempt to avoid future confusion.

@rossta
Copy link
Contributor Author

rossta commented Apr 28, 2023

After I fix the CI pipeline, we/I should integrate the linter as a step in CI.

Currently the lint check is appended to the default rake task. That means it should already be integrated into CI since you're using the default task in the new GH action.
https://github.com/ruby-oembed/ruby-oembed/pull/90/files#diff-2cfbee5050623614c2e390deead7c5d978b7d53feb447ae8fd6493aa8356ba67R6

I chose to disable the linting rule for this case because it is test
assertion on a generated regexp whereas I believe the spirit of the rule
is intended more for hand-written regexps.
Seems to read better when disabling this rule inline
From the Rubocop docs:

In Ruby 2.3 or later, use unary plus operator to unfreeze a string
literal instead of `String#dup` and `String.new`. Unary plus operator is
faster than `String#dup`.

Note: `String.new` (without operator) is not exactly the same as `+''`.
These differ in encoding. `String.new.encoding` is always `ASCII-8BIT`.
However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`).
So, if you expect `ASCII-8BIT` encoding, disable this cop.
@metavida
Copy link
Collaborator

metavida commented May 9, 2023

Oh my! The output from the standard.rb linting is very subtle!

For the test runs where I first added GitHub Actions I noticed that the test passed despite the coverall data submission failing so I just kinda left it as-is & decided to try & fix that later.

However, because the standard.rb output is currently only shown in grey text it's really blends in with the rest of the text, and is currently entirely over-powered by the coveralls errors.

subtle linting output

Of course I need to fix the coveralls issue separately from this PR (maybe even disabling it for now), but/and it would still be awesome if the linting output was more prominent somehow.

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.

None yet

2 participants