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: Disallow protocol in cask URL verified stanza #14886

Merged

Conversation

issyl0
Copy link
Member

@issyl0 issyl0 commented Mar 4, 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?

  • Fixes rubocop: disallow protocol in cask url verified stanza #14717.
  • Apparently the "verified" parameter in the URL (present when a Cask's download URL is not the same as its homepage) shouldn't have the protocol (https, http) at the front.
  • Removing this has happened manually in the past, so here's an autocorrecting RuboCop for it.

It works!

/home/linuxbrew/.linuxbrew/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/youdaonote.rb:7:19: C: [Correctable] Cask/Url: Verified URL parameter value should not start with https:// or http://.
      verified:   "https://artifact.lx.netease.com/download/ynote-electron/"
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6652 files inspected, 1 offense detected, 1 offense autocorrectable

@BrewTestBot
Copy link
Member

Review period will end on 2023-03-07 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 4, 2023
# typed: true
# frozen_string_literal: true

require "forwardable"
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure what this does, I copied and pasted from other cops. 😳

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

I think it's meaningless without any use of def_delegator(s): https://ruby-doc.org/stdlib-2.5.1/libdoc/forwardable/rdoc/Forwardable.html (which would make a nice cop by itself)

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought so, but it's in a few cops that don't make use of def_delegators either. I guess that's a mistake. One RuboCop at a time for me, though. 😆

@@ -0,0 +1,37 @@
# typed: true
Copy link
Member Author

Choose a reason for hiding this comment

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

Sorbet doesn't run successfully. Need to read up on https://sorbet.org/docs/requires-ancestor.

Copy link
Member Author

@issyl0 issyl0 Mar 4, 2023

Choose a reason for hiding this comment

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

Reading https://blog.appsignal.com/2021/01/13/using-mixins-and-modules-in-your-ruby-on-rails-application.html for a general overview of mixins, and https://sorbet.org/docs/requires-ancestor, I do not understand what it wants me to do. As the person who introduced this requires_ancestor thing, @dduugg can you shed any light (either here or in Slack)? Have I taken a wrong approach here somewhere?

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

module RuboCop::Cop::Cask::OnUrlStanza
  requires_ancestor { RuboCop::Cop::Cask::UrlLegacyCommaSeparators }
end

This code means that any module that includes RuboCop::Cop::Cask::OnUrlStanza must subclass RuboCop::Cop::Cask::UrlLegacyCommaSeparators. This makes the methods defined in the latter available in the former. (In this specific case, OnUrlStanza makes use of on_url_stanza, the lone method defined in UrlLegacyCommaSeparators.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm, so if we now have RuboCop::Cop::Cask::Url and RuboCop::Cop::Cask::UrlLegacyCommaSeparators cops that have the on_url_stanza method , which one should inherit from which? They're separate cops.

Copy link
Member Author

Choose a reason for hiding this comment

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

I figured it out!

@issyl0 issyl0 force-pushed the rubocop-cask-url-verified-disallow-protocol branch from d2bc47c to fb81024 Compare March 4, 2023 22:58
- Apparently the "verified" parameter in the URL (present when a Cask's
  download URL is not the same as its homepage) shouldn't have the
  protocol (`https`, `http`) at the front.
- Removing this has happened manually in the past, so here's an
  autocorrecting RuboCop for it.
@issyl0 issyl0 force-pushed the rubocop-cask-url-verified-disallow-protocol branch from fb81024 to 79db987 Compare March 4, 2023 23:00
- The `on_url_stanza` method is now used in two cops, `Url` and
  `UrlLegacyCommaSeparators`. Make the latter inherit from the former
  to make Sorbet happy.
- The style and typecheck checks now pass fine.
issyl0 added a commit to issyl0/brew that referenced this pull request Mar 5, 2023
- I suspect these were copy-pasted from other cops, like I did in
  Homebrew#14886 (comment).
- The "forwardable" require is unnecesary if the cop doesn't
  `extend Forwardable` and use `def_delegator`.
- The "uri" require is unnecessary if the cop doesn't call `URI` methods.
@issyl0 issyl0 marked this pull request as ready for review March 5, 2023 17:26
issyl0 added a commit to issyl0/homebrew-cask that referenced this pull request Mar 5, 2023
- According to Homebrew/brew#14717 it's wrong
  to have the protocol in the "verified" part of a Cask URL. So there's
  now an autocorrecting RuboCop for it at
  Homebrew/brew#14886. This fixes the singular
  offense.
p-linnane pushed a commit to p-linnane/homebrew-cask that referenced this pull request Mar 5, 2023
- According to Homebrew/brew#14717 it's wrong
  to have the protocol in the "verified" part of a Cask URL. So there's
  now an autocorrecting RuboCop for it at
  Homebrew/brew#14886. This fixes the singular
  offense.
p-linnane added a commit to Homebrew/homebrew-cask that referenced this pull request Mar 5, 2023
* Update youdaonote from 7.2.3 to 7.2.4

* youdaonote: Remove protocol from verified stanza

- According to Homebrew/brew#14717 it's wrong
  to have the protocol in the "verified" part of a Cask URL. So there's
  now an autocorrecting RuboCop for it at
  Homebrew/brew#14886. This fixes the singular
  offense.

---------

Co-authored-by: Issy Long <me@issyl0.co.uk>
@issyl0 issyl0 enabled auto-merge March 6, 2023 08:55
@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label Mar 6, 2023
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Mar 6, 2023
@BrewTestBot
Copy link
Member

Review period skipped due to critical label.

@issyl0 issyl0 merged commit 5a68566 into Homebrew:master Mar 6, 2023
@issyl0 issyl0 deleted the rubocop-cask-url-verified-disallow-protocol branch March 6, 2023 12:22
@MikeMcQuaid
Copy link
Member

Thanks again @issyl0!

@github-actions github-actions bot added the outdated PR was locked due to age label Apr 6, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rubocop: disallow protocol in cask url verified stanza
4 participants