Skip to content
Snippets Groups Projects
Unverified Commit 2cd72908 authored by Dawid Dziurla's avatar Dawid Dziurla Committed by GitHub
Browse files

Merge pull request #7863 from iMichka/single-resource

on_os resources: allow linux-only or mac-only resources
parents 84e4e1b4 edd1685d
No related branches found
No related tags found
No related merge requests found
......@@ -104,41 +104,36 @@ module RuboCop
@offensive_node = resource_block
@offense_source_range = resource_block.source_range
if on_macos_blocks.length > 1
problem "there can only be one `on_macos` block in a resource block."
next
end
if on_linux_blocks.length > 1
problem "there can only be one `on_linux` block in a resource block."
next
next if on_macos_blocks.length.zero? && on_linux_blocks.length.zero?
if on_macos_blocks.length == 1
on_macos_block = on_macos_blocks.first
child_nodes = on_macos_block.body.child_nodes
if child_nodes[0].method_name.to_s != "url" && child_nodes[1].method_name.to_s != "sha256"
problem "only an url and a sha256 (in the right order) are allowed in a `on_macos` " \
"block within a resource block."
next
end
end
if on_macos_blocks.length == 1 && on_linux_blocks.length.zero?
problem "you need to define an `on_linux` block within your resource block."
next
if on_linux_blocks.length == 1
on_linux_block = on_linux_blocks.first
child_nodes = on_linux_block.body.child_nodes
if child_nodes[0].method_name.to_s != "url" && child_nodes[1].method_name.to_s != "sha256"
problem "only an url and a sha256 (in the right order) are allowed in a `on_linux` " \
"block within a resource block."
end
end
if on_macos_blocks.length.zero? && on_linux_blocks.length == 1
problem "you need to define an `on_macos` block within your resource block."
if on_macos_blocks.length > 1
problem "there can only be one `on_macos` block in a resource block."
next
end
on_macos_block = on_macos_blocks.first
on_linux_block = on_linux_blocks.first
child_nodes = on_macos_block.body.child_nodes
if child_nodes[0].method_name.to_s != "url" && child_nodes[1].method_name.to_s != "sha256"
problem "only an url and a sha256 (in the right order) are allowed in a `on_macos` " \
"block within a resource block."
if on_linux_blocks.length > 1
problem "there can only be one `on_linux` block in a resource block."
next
end
child_nodes = on_linux_block.body.child_nodes
if child_nodes[0].method_name.to_s != "url" && child_nodes[1].method_name.to_s != "sha256"
problem "only an url and a sha256 (in the right order) are allowed in a `on_linux` " \
"block within a resource block."
end
end
end
......
......@@ -447,12 +447,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
end
it "there is a on_macos block but no on_linux block" do
expect_offense(<<~RUBY)
expect_no_offenses(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
resource do
^^^^^^^^^^^ you need to define an `on_linux` block within your resource block.
on_macos do
url "https://brew.sh/resource1.tar.gz"
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
......@@ -463,12 +461,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
end
it "there is a on_linux block but no on_macos block" do
expect_offense(<<~RUBY)
expect_no_offenses(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
resource do
^^^^^^^^^^^ you need to define an `on_macos` block within your resource block.
on_linux do
url "https://brew.sh/resource1.tar.gz"
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment