Merge pull request #23236 from timhillgit/binary-audit-filename-only

rubocops/urls: Ignore GitHub username and repo in binary URL check
This commit is contained in:
Mike McQuaid
2026-07-29 07:42:42 +00:00
committed by GitHub
2 changed files with 27 additions and 1 deletions
+10 -1
View File
@@ -37,9 +37,18 @@ module RuboCop
return if formula_tap != "homebrew-core"
# Check for binary URLs
audit_urls(urls, /(darwin|macos|osx)/i) do |match, url|
binary_package_pattern = /(darwin|macos|osx)/i
github_pattern = %r{^https://github\.com/[\w-]+/[\w.-]+/(.*)$}i
audit_urls(urls, binary_package_pattern) do |match, url|
next if T.must(@formula_name).include?(match.to_s.downcase)
next if url.match?(/.(patch|diff)(\?full_index=1)?$/)
next if url.match(github_pattern)&.then do |match_data|
# For GitHub URLs, the username and repository name have no
# bearing on whether a file is a binary package. We'll extract the
# remainder of the URL and match against the binary pattern.
# See: https://github.com/Homebrew/brew/pull/23236
!match_data[1].match?(binary_package_pattern)
end
next if tap_style_exception? :not_a_binary_url_prefix_allowlist
next if tap_style_exception? :binary_bootstrap_formula_urls_allowlist
@@ -159,6 +159,12 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Urls do
"not a source archive; homebrew/core is source-only.",
"col" => 2,
"formula_tap" => "homebrew-core",
}, {
"url" => "https://github.com/foo/bar/archive/refs/tags/darwin.tar.gz",
"msg" => "https://github.com/foo/bar/archive/refs/tags/darwin.tar.gz looks like a binary package, " \
"not a source archive; homebrew/core is source-only.",
"col" => 2,
"formula_tap" => "homebrew-core",
}, {
"url" => "cvs://brew.sh/foo/bar",
"msg" => "Use of the \"cvs://\" scheme is deprecated, pass `using: :cvs` instead",
@@ -302,6 +308,17 @@ RSpec.describe RuboCop::Cop::FormulaAudit::Urls do
expect(inspect_source(source)).to eq([])
end
it "does not report an offense based on the username or repo name of a GitHub URL" do
source = <<~RUBY
class Foo < Formula
desc "foo"
url "https://github.com/scriptingosx/cool-darwin-app/archive/refs/tags/v0.1.1.tar.gz"
end
RUBY
expect(inspect_source(source)).to eq([])
end
end
context "when auditing Apache URLs" do