From 7bb20a3b83ac4978c1e1d2b4a7c8d30f3e928860 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 4 Apr 2023 16:11:44 +0100 Subject: [PATCH] Skip if the URL stanza has only two path components https://github.com/Homebrew/homebrew-cask-fonts/pull/7336#discussion_r1156325651 --- Library/Homebrew/rubocops/cask/url.rb | 2 ++ .../Homebrew/test/rubocops/cask/url_spec.rb | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Library/Homebrew/rubocops/cask/url.rb b/Library/Homebrew/rubocops/cask/url.rb index ac20d2c275..2d3882d938 100644 --- a/Library/Homebrew/rubocops/cask/url.rb +++ b/Library/Homebrew/rubocops/cask/url.rb @@ -43,6 +43,8 @@ module RuboCop # 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 # Skip if the verified value ends with a slash. next if value_node.str_content.end_with?("/") diff --git a/Library/Homebrew/test/rubocops/cask/url_spec.rb b/Library/Homebrew/test/rubocops/cask/url_spec.rb index 1b768231dc..4698bd94a4 100644 --- a/Library/Homebrew/test/rubocops/cask/url_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/url_spec.rb @@ -104,16 +104,31 @@ describe RuboCop::Cop::Cask::Url do end context "when the URL does not end with a slash" do - let(:source) do - <<~CASK - cask "foo" do - url "https://github.com/Foo", - verified: "github.com/Foo" - end - CASK + describe "and it has one path component" do + let(:source) do + <<~CASK + cask "foo" do + url "https://github.com/Foo", + verified: "github.com/Foo" + end + CASK + end + + include_examples "does not report any offenses" end - include_examples "does not report any offenses" + describe "and it has two path components" do + let(:source) do + <<~CASK + cask "foo" do + url "https://github.com/foo/foo.git", + verified: "github.com/foo/foo" + end + CASK + end + + include_examples "does not report any offenses" + end end context "when the url ends with a / and the verified value does too" do