Merge pull request #7863 from iMichka/single-resource
on_os resources: allow linux-only or mac-only resources
This commit is contained in:
commit
2cd72908bc
@ -104,6 +104,27 @@ module RuboCop
|
|||||||
@offensive_node = resource_block
|
@offensive_node = resource_block
|
||||||
@offense_source_range = resource_block.source_range
|
@offense_source_range = resource_block.source_range
|
||||||
|
|
||||||
|
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_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 > 1
|
if on_macos_blocks.length > 1
|
||||||
problem "there can only be one `on_macos` block in a resource block."
|
problem "there can only be one `on_macos` block in a resource block."
|
||||||
next
|
next
|
||||||
@ -113,32 +134,6 @@ module RuboCop
|
|||||||
problem "there can only be one `on_linux` block in a resource block."
|
problem "there can only be one `on_linux` block in a resource block."
|
||||||
next
|
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
|
|
||||||
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."
|
|
||||||
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."
|
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -447,12 +447,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "there is a on_macos block but no on_linux block" do
|
it "there is a on_macos block but no on_linux block" do
|
||||||
expect_offense(<<~RUBY)
|
expect_no_offenses(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
resource do
|
resource do
|
||||||
^^^^^^^^^^^ you need to define an `on_linux` block within your resource block.
|
|
||||||
on_macos do
|
on_macos do
|
||||||
url "https://brew.sh/resource1.tar.gz"
|
url "https://brew.sh/resource1.tar.gz"
|
||||||
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
@ -463,12 +461,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "there is a on_linux block but no on_macos block" do
|
it "there is a on_linux block but no on_macos block" do
|
||||||
expect_offense(<<~RUBY)
|
expect_no_offenses(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
resource do
|
resource do
|
||||||
^^^^^^^^^^^ you need to define an `on_macos` block within your resource block.
|
|
||||||
on_linux do
|
on_linux do
|
||||||
url "https://brew.sh/resource1.tar.gz"
|
url "https://brew.sh/resource1.tar.gz"
|
||||||
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user