Disallow head do blocks with only url and branch
- Since `head` must now specify a url and branch, the `head do` block with only these stanzas can be condensed to the single-line `head "url", branch: "branch"` format.
This commit is contained in:
parent
37eaed5bb7
commit
05b27aa847
@ -13,7 +13,7 @@ module RuboCop
|
||||
# - `bottle :unneeded`/`:disable` and `bottle do` should not be simultaneously present
|
||||
# - `stable do` should not be present without a `head` spec
|
||||
# - `stable do` should not be present with only `url|checksum|mirror|version`
|
||||
# - `head do` should not be present with only `url`
|
||||
# - `head do` should not be present with only `url|branch`
|
||||
class ComponentsRedundancy < FormulaCop
|
||||
HEAD_MSG = "`head` and `head do` should not be simultaneously present"
|
||||
BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present"
|
||||
@ -54,8 +54,9 @@ module RuboCop
|
||||
head_block = find_block(body_node, :head)
|
||||
if head_block && !head_block.body.nil?
|
||||
child_nodes = head_block.body.begin_type? ? head_block.body.child_nodes : [head_block.body]
|
||||
if child_nodes.all? { |n| n.send_type? && n.method_name == :url }
|
||||
problem "`head do` should not be present with only `url`"
|
||||
shorthand_head_methods = [:url, :branch]
|
||||
if child_nodes.all? { |n| n.send_type? && shorthand_head_methods.include?(n.method_name) }
|
||||
problem "`head do` should not be present with only #{shorthand_head_methods.join("/")}"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -82,13 +82,26 @@ RSpec.describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do
|
||||
end
|
||||
|
||||
head do
|
||||
^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only `url`
|
||||
^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch
|
||||
url "https://brew.sh/foo.git"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "reports an offense if `head do` is present with only `url` and `branch`" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
url "https://brew.sh/foo-1.0.tgz"
|
||||
|
||||
head do
|
||||
^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch
|
||||
url "https://brew.sh/foo.git", branch: "develop"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "reports no offenses if `stable do` is present with `url` and `depends_on`" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user