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

Fix Rubocop trailing / bug #13212

Merged

Conversation

danielbayley
Copy link
Contributor

@danielbayley danielbayley commented Apr 27, 2022

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

@MikeMcQuaid
Copy link
Member

@danielbayley Can you provide a bit more context here? Thanks!

@danielbayley danielbayley changed the title Fix Rubocop trailing / bug Fix Rubocop trailing / bug Apr 27, 2022
@danielbayley
Copy link
Contributor Author

@danielbayley Can you provide a bit more context here? Thanks!

Sure. This particular Rubocop rule keeps throwing errors unrelated to the trailing /… For example, if the homepage has string interpolation.

@MikeMcQuaid
Copy link
Member

Sure. This particular Rubocop rule keeps throwing errors unrelated to the trailing /… For example, if the homepage has string interpolation.

Can you provide some example casks/PRs/homepages/strings?

@Bo98
Copy link
Member

Bo98 commented Apr 27, 2022

I think I can see what you're getting at but I don't understand the regex change given URI::DEFAULT_PARSER.make_regexp matches all URLs rather than just those without a trailing slash?

Surely the fix for interpolation error is to use the url variable (which you can see defined on line 21) in place of url_node.str_content on line 30?

@danielbayley
Copy link
Contributor Author

danielbayley commented Apr 27, 2022

I think I can see what you're getting at but I don't understand the regex change given URI::DEFAULT_PARSER.make_regexp matches all URLs rather than just those without a trailing slash?

Yeah sorry, I misread the regex… That bit was actually unrelated.

Surely the fix for interpolation error is to use the url variable (which you can see defined on line 21) in place of url_node.str_content on line 30?

Yes I thought that was the problem (it should be that anyway), but it’s still throwing undefined method 'metadata' for nil:NilClass errors.

@danielbayley
Copy link
Contributor Author

Sure. This particular Rubocop rule keeps throwing errors unrelated to the trailing /… For example, if the homepage has string interpolation.

Can you provide some example casks/PRs/homepages/strings?

So in a lot of (tap) casks, I have something like:

repo = "github.com/user/repo"
url "https://#{repo}/releases/download/v#{version}/...zip"
# …
homepage "https://#{repo}#readme"

# … Use of `repo` elsewhere…

@Bo98
Copy link
Member

Bo98 commented Apr 27, 2022

Oh right I see the issue. That'll appear as an invalid URI with interpolated strings no matter what (despite it matching URI::DEFAULT_PARSER.make_regexp) so it was indeed correct to use url_node.str_content.

Does this work?

domain = URI(url_node.str_content).host
return if domain.blank?

@danielbayley
Copy link
Contributor Author

danielbayley commented Apr 27, 2022

Oh right I see the issue. That'll appear as an invalid URI with interpolated strings no matter what (despite it matching URI::DEFAULT_PARSER.make_regexp) so it was indeed correct to use url_node.str_content.

Does this work?

domain = URI(url_node.str_content).host
return if domain.blank?

Not quite, but

domain = URI(url_node.str_content).host rescue nil
return if domain.blank?

does…

Copy link
Member

@Bo98 Bo98 left a comment

Choose a reason for hiding this comment

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

LGTM if it works

@MikeMcQuaid MikeMcQuaid merged commit 803444b into Homebrew:master Apr 28, 2022
@MikeMcQuaid
Copy link
Member

Thanks again @danielbayley!

@danielbayley danielbayley deleted the rubocop-url-trailing-slash branch April 28, 2022 08:54
@github-actions github-actions bot added the outdated PR was locked due to age label May 29, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants