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

rubocops/cask: Ensure that "verified" URLs with paths end with "/" #15125

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Apr 2, 2023

  • 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?

- These were being fixed manually[1], so let's make a RuboCop for any
  further occurrences since this is a good rule to enforce[2].

[1] - Homebrew/homebrew-cask#144179 (comment)
[2] - Homebrew/homebrew-cask#80965 (comment)
@reitermarkus
Copy link
Member

I think one test case is missing:

url "https://example.org/download",
    verified: "example.org/download"

In this case, the verified parameter should not end with a slash.

@reitermarkus
Copy link
Member

Also

url "https://example.org/",
    verified: "example.org/"

I think we already have a cop to ensure the slash for the actual URL in this case, but the verified parameter also needs the slash.

@issyl0
Copy link
Member Author

issyl0 commented Apr 2, 2023

I think one test case is missing:

url "https://example.org/download",
    verified: "example.org/download"

In this case, the verified parameter should not end with a slash.

🤔 So the following example does need the slash, but the above should not have one? Or did I misunderstand initially?

url "https://example.com/download/foo-v1.2.0.dmg",
     verified: "example.com/download"

@reitermarkus
Copy link
Member

So the following example does need the slash, but the above should not have one?

Yes, exactly.

Handle good things like:

```ruby
url "https://example.org/download",
    verified: "example.org/download" # This is fine.
```

And bad things like:

```ruby
url "https://example.org/",
    verified: "example.org" # This should end with a slash.
```
@issyl0 issyl0 force-pushed the rubocops-cask-verified-url-with-path-ending-slash branch from d6aa751 to 21da074 Compare April 2, 2023 21:27
Co-authored-by: Markus Reiter <me@reitermark.us>
@issyl0
Copy link
Member Author

issyl0 commented Apr 2, 2023

Thanks for the thorough review @reitermarkus!

@issyl0 issyl0 force-pushed the rubocops-cask-verified-url-with-path-ending-slash branch 2 times, most recently from 4e9d30d to 5cc39fb Compare April 2, 2023 22:39
@issyl0 issyl0 force-pushed the rubocops-cask-verified-url-with-path-ending-slash branch from 5cc39fb to 28f8cbe Compare April 2, 2023 22:40
@issyl0
Copy link
Member Author

issyl0 commented Apr 2, 2023

Right, the real Casks report no offenses now I've fixed the handling for the syntax that I didn't see before. Tricksy Caskes.

@MikeMcQuaid
Copy link
Member

Good with me once tap syntax is 🟢! Great work @issyl0 and thanks for the help here @reitermarkus.

@MikeMcQuaid MikeMcQuaid merged commit 41e7ee7 into Homebrew:master Apr 4, 2023
24 checks passed
@issyl0 issyl0 deleted the rubocops-cask-verified-url-with-path-ending-slash branch April 4, 2023 15:56
# Skip if the URL and the verified value are the same.
next if value_node.source == url_stanza.source.gsub(%r{^"https?://}, "\"")
# Skip if the URL has two path components, eg: `https://github.com/google/fonts.git`.
next if url_stanza.source.gsub(%r{^"https?://}, "\"").count("/") == 2
Copy link
Member

Choose a reason for hiding this comment

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

@issyl0, this only fixes this particular case.

What if this isn't a GitHub URL with this specific format?

url "https://example.org/long/path/app-1.2.3.dmg",
    verified: "example.org/long/path/app"

Granted I don't think we currently have any cask with such a format, but 2 is kinda arbitrary.

Copy link
Member

Choose a reason for hiding this comment

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

I think we are overcomplicating the condition for this cop.

If verified doesn't already end with a slash but the url starts with "#{verified}/", a slash should be added.

Copy link
Member

Choose a reason for hiding this comment

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

@reitermarkus That sounds good, could you open a PR for that?

@github-actions github-actions bot added the outdated PR was locked due to age label May 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 6, 2023
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.

RuboCop for trailing slash in verified url stanza
3 participants