mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Handle when the URL has interpolation: use source
not str_content
- We see this a lot in real Casks.
This commit is contained in:
parent
41c35986f8
commit
28f8cbe8da
@ -24,7 +24,7 @@ module RuboCop
|
|||||||
def on_url_stanza(stanza)
|
def on_url_stanza(stanza)
|
||||||
return if stanza.stanza_node.block_type?
|
return if stanza.stanza_node.block_type?
|
||||||
|
|
||||||
url_string = stanza.stanza_node.first_argument.str_content
|
url_stanza = stanza.stanza_node.first_argument
|
||||||
hash_node = stanza.stanza_node.last_argument
|
hash_node = stanza.stanza_node.last_argument
|
||||||
return unless hash_node.hash_type?
|
return unless hash_node.hash_type?
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Skip if the URL and the verified value are the same.
|
# Skip if the URL and the verified value are the same.
|
||||||
next if value_node.str_content == url_string.delete_prefix("https://").delete_prefix("http://")
|
next if value_node.source == url_stanza.source.gsub(%r{^"https?://}, "\"")
|
||||||
# Skip if the verified value ends with a slash.
|
# Skip if the verified value ends with a slash.
|
||||||
next if value_node.str_content.end_with?("/")
|
next if value_node.str_content.end_with?("/")
|
||||||
|
|
||||||
|
@ -175,6 +175,20 @@ describe RuboCop::Cop::Cask::Url do
|
|||||||
include_examples "does not report any offenses"
|
include_examples "does not report any offenses"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when the url has interpolation in it and the verified url ends with a /" do
|
||||||
|
let(:source) do
|
||||||
|
<<~CASK
|
||||||
|
cask "foo" do
|
||||||
|
version "1.2.3"
|
||||||
|
url "https://example.com/download/foo-v\#{version}.dmg",
|
||||||
|
verified: "example.com/download/"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "does not report any offenses"
|
||||||
|
end
|
||||||
|
|
||||||
context "when the url 'verified' value has a path component that doesn't end with a /" do
|
context "when the url 'verified' value has a path component that doesn't end with a /" do
|
||||||
let(:source) do
|
let(:source) do
|
||||||
<<~CASK
|
<<~CASK
|
||||||
|
Loading…
x
Reference in New Issue
Block a user