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 rubocop linter for Truncate #2200

Merged
merged 5 commits into from
Aug 14, 2023
Merged

Conversation

TylerJDev
Copy link
Contributor

@TylerJDev TylerJDev commented Aug 9, 2023

What are you trying to accomplish?

Builds off the work done in #2182.

Introduces a linter for Truncate, while also autocorrecting some instances.

Integration

N/A

List the issues that this change affects.

https://github.com/github/primer/issues/2342

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2023

🦋 Changeset detected

Latest commit: ddb0cac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/view-components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@TylerJDev TylerJDev temporarily deployed to preview August 9, 2023 17:46 — with GitHub Actions Inactive
@TylerJDev TylerJDev temporarily deployed to preview August 9, 2023 18:48 — with GitHub Actions Inactive
@TylerJDev TylerJDev marked this pull request as ready for review August 9, 2023 18:51
@TylerJDev TylerJDev requested review from a team, camertron, jonrohan and keithamus August 9, 2023 18:51
Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

This looks good overall, but I have one comment I'd like to discuss further.

return if hash_with_inline_value?(node.arguments.first)

lambda do |corrector|
corrector.replace(node.children.first, "Primer::Beta::Truncate")
Copy link
Member

Choose a reason for hiding this comment

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

This won't be a totally safe transform, as Primer::Truncate used to return a <div> (which is display: block) where Primer::Beta::Truncate returns a <span> (which is display: inline). This could cause styling issues. Some options:

  1. Try it and see if it works. There's 67 instances in gh/gh so not an overwhelming amount to check
  2. Rewrite to always include tag: :div in the arguments hash. Then we can look at writing a separate linter for Primer::Beta::Truncate(tag: :div).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point! I'll adjust to include the tag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added tag: :div by default, as long as there isn't one already present.

Primer::Truncate.new(tag: :span) will turn into Primer::Beta::Truncate.new(tag: :span)

Whereas Primer::Truncate.new() should turn into Primer::Beta::Truncate.new(tag: :div).

Not too sure if this is the right way to go about it, I'd love some eyes on the way I implemented this!

Copy link
Member

@keithamus keithamus left a comment

Choose a reason for hiding this comment

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

Nice work!

@TylerJDev TylerJDev merged commit 1b770f9 into main Aug 14, 2023
28 checks passed
@TylerJDev TylerJDev deleted the tylerjdev/truncate-robocop-linter branch August 14, 2023 18:56
@primer primer bot mentioned this pull request Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants