rubocops/cask: Ignore livecheck blocks within on_* blocks
- The Cask `sip`, to give a random example, was failing this RuboCop because it has a `livecheck` block within an `on_*` block and the livecheck block and the top-level Cask both have `url` stanzas. This is a legitimate use of `livecheck` blocks because the cask software download URL and the livecheck version check URL are not the same thing, so let's skip over `livecheck` blocks and their contents.
This commit is contained in:
parent
794cd37dbb
commit
8091e603df
@ -40,6 +40,10 @@ module RuboCop
|
||||
|
||||
node.child_nodes.each do |child|
|
||||
child.each_node(:send) do |send_node|
|
||||
# Skip (nested) livecheck blocks as its `url` is different to a download `url`.
|
||||
next if send_node.method_name == :livecheck
|
||||
next if send_node.parent.block_type? && send_node.parent.method_name == :livecheck
|
||||
|
||||
# Skip string interpolations (`:begin` inside `:dstr`).
|
||||
next if send_node.begin_type? && send_node.parent_node.dstr_type?
|
||||
next if ON_SYSTEM_METHODS.include?(send_node.method_name)
|
||||
|
||||
@ -38,6 +38,29 @@ describe RuboCop::Cop::Cask::NoOverrides do
|
||||
include_examples "does not report any offenses"
|
||||
end
|
||||
|
||||
context "when there are livecheck blocks within `on_*` blocks, ignore their contents" do
|
||||
let(:source) do
|
||||
<<~CASK
|
||||
cask 'foo' do
|
||||
on_intel do
|
||||
livecheck do
|
||||
url 'https://brew.sh/foo' # Livecheck should be allowed since it's a different "kind" of URL.
|
||||
end
|
||||
version '1.2.3'
|
||||
end
|
||||
|
||||
on_arm do
|
||||
version '2.3.4'
|
||||
end
|
||||
|
||||
url 'https://brew.sh/foo.pkg'
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
include_examples "does not report any offenses"
|
||||
end
|
||||
|
||||
context "when there's only one difference between the `on_*` blocks" do
|
||||
let(:source) do
|
||||
<<~CASK
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user