rubocops: permit mirror in OS-specific resources
This commit is contained in:
parent
663b972f44
commit
641afdd2de
@ -75,17 +75,20 @@ module RuboCop
|
|||||||
message = nil
|
message = nil
|
||||||
allowed_methods = [
|
allowed_methods = [
|
||||||
[:url, :sha256],
|
[:url, :sha256],
|
||||||
|
[:url, :mirror, :sha256],
|
||||||
[:url, :version, :sha256],
|
[:url, :version, :sha256],
|
||||||
|
[:url, :mirror, :version, :sha256],
|
||||||
]
|
]
|
||||||
|
|
||||||
|
# TODO: Refactor this to point to the actual offending methods rather than the entire block.
|
||||||
on_os_bodies.each do |method_name, on_os_body|
|
on_os_bodies.each do |method_name, on_os_body|
|
||||||
child_nodes = on_os_body.begin_type? ? on_os_body.child_nodes : [on_os_body]
|
child_nodes = on_os_body.begin_type? ? on_os_body.child_nodes : [on_os_body]
|
||||||
if child_nodes.all? { |n| n.send_type? || n.block_type? }
|
if child_nodes.all? { |n| n.send_type? || n.block_type? }
|
||||||
method_names = child_nodes.map(&:method_name)
|
method_names = child_nodes.map(&:method_name)
|
||||||
next if allowed_methods.include? method_names
|
next if allowed_methods.include? method_names
|
||||||
end
|
end
|
||||||
message = "`#{method_name}` blocks within resource blocks must contain only a " \
|
message = "`#{method_name}` blocks within `resource` blocks must contain at least "\
|
||||||
"url and sha256 or a url, version, and sha256 (in those orders)."
|
"`url` and `mirror` and at most `url`, `mirror`, `version`, `sha256` (in order)."
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -614,7 +614,7 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
resource do
|
resource do
|
||||||
^^^^^^^^^^^ `on_macos` blocks within resource blocks must contain only a url and sha256 or a url, version, and sha256 (in those orders).
|
^^^^^^^^^^^ `on_macos` blocks within `resource` blocks must contain at least `url` and `mirror` and at most `url`, `mirror`, `version`, `sha256` (in order).
|
||||||
on_macos do
|
on_macos do
|
||||||
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
url "https://brew.sh/resource2.tar.gz"
|
url "https://brew.sh/resource2.tar.gz"
|
||||||
@ -629,6 +629,27 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "reports no offenses if the content of an `on_macos` block in a resource contains a mirror" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
|
resource do
|
||||||
|
on_macos do
|
||||||
|
url "https://brew.sh/resource2.tar.gz"
|
||||||
|
mirror "https://brew.sh/mirror/resource2.tar.gz"
|
||||||
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
|
end
|
||||||
|
|
||||||
|
on_linux do
|
||||||
|
url "https://brew.sh/resource2.tar.gz"
|
||||||
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "reports no offenses if an `on_macos` block has if-else branches that are properly formatted" do
|
it "reports no offenses if an `on_macos` block has if-else branches that are properly formatted" do
|
||||||
expect_no_offenses(<<~RUBY)
|
expect_no_offenses(<<~RUBY)
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -660,7 +681,7 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
resource do
|
resource do
|
||||||
^^^^^^^^^^^ `on_macos` blocks within resource blocks must contain only a url and sha256 or a url, version, and sha256 (in those orders).
|
^^^^^^^^^^^ `on_macos` blocks within `resource` blocks must contain at least `url` and `mirror` and at most `url`, `mirror`, `version`, `sha256` (in order).
|
||||||
on_macos do
|
on_macos do
|
||||||
if foo == :bar
|
if foo == :bar
|
||||||
url "https://brew.sh/resource2.tar.gz"
|
url "https://brew.sh/resource2.tar.gz"
|
||||||
@ -686,7 +707,7 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
resource do
|
resource do
|
||||||
^^^^^^^^^^^ `on_linux` blocks within resource blocks must contain only a url and sha256 or a url, version, and sha256 (in those orders).
|
^^^^^^^^^^^ `on_linux` blocks within `resource` blocks must contain at least `url` and `mirror` and at most `url`, `mirror`, `version`, `sha256` (in order).
|
||||||
on_macos do
|
on_macos do
|
||||||
url "https://brew.sh/resource2.tar.gz"
|
url "https://brew.sh/resource2.tar.gz"
|
||||||
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
@ -732,7 +753,7 @@ describe RuboCop::Cop::FormulaAudit::ComponentsOrder do
|
|||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
|
||||||
resource do
|
resource do
|
||||||
^^^^^^^^^^^ `on_linux` blocks within resource blocks must contain only a url and sha256 or a url, version, and sha256 (in those orders).
|
^^^^^^^^^^^ `on_linux` blocks within `resource` blocks must contain at least `url` and `mirror` and at most `url`, `mirror`, `version`, `sha256` (in order).
|
||||||
on_macos do
|
on_macos do
|
||||||
url "https://brew.sh/resource2.tar.gz"
|
url "https://brew.sh/resource2.tar.gz"
|
||||||
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
sha256 "586372eb92059873e29eba4f9dec8381541b4d3834660707faf8ba59146dfc35"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user