File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ module FormulaAudit
13
13
# - `bottle :unneeded`/`:disable` and `bottle do` should not be simultaneously present
14
14
# - `stable do` should not be present without a `head` spec
15
15
# - `stable do` should not be present with only `url|checksum|mirror|version`
16
- # - `head do` should not be present with only `url`
16
+ # - `head do` should not be present with only `url|branch `
17
17
class ComponentsRedundancy < FormulaCop
18
18
HEAD_MSG = "`head` and `head do` should not be simultaneously present"
19
19
BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present"
@@ -54,8 +54,9 @@ def audit_formula(formula_nodes)
54
54
head_block = find_block ( body_node , :head )
55
55
if head_block && !head_block . body . nil?
56
56
child_nodes = head_block . body . begin_type? ? head_block . body . child_nodes : [ head_block . body ]
57
- if child_nodes . all? { |n | n . send_type? && n . method_name == :url }
58
- problem "`head do` should not be present with only `url`"
57
+ shorthand_head_methods = [ :url , :branch ]
58
+ if child_nodes . all? { |n | n . send_type? && shorthand_head_methods . include? ( n . method_name ) }
59
+ problem "`head do` should not be present with only #{ shorthand_head_methods . join ( "/" ) } "
59
60
end
60
61
end
61
62
Original file line number Diff line number Diff line change @@ -82,13 +82,38 @@ class Foo < Formula
82
82
end
83
83
84
84
head do
85
- ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only ` url`
85
+ ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch
86
86
url "https://brew.sh/foo.git"
87
87
end
88
88
end
89
89
RUBY
90
90
end
91
91
92
+ it "reports an offense if `head do` is present with only `url` and `branch`" do
93
+ expect_offense ( <<~RUBY )
94
+ class Foo < Formula
95
+ url "https://brew.sh/foo-1.0.tgz"
96
+
97
+ head do
98
+ ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch
99
+ url "https://brew.sh/foo.git"
100
+ branch "develop"
101
+ end
102
+ end
103
+ RUBY
104
+
105
+ expect_offense ( <<~RUBY )
106
+ class Foo < Formula
107
+ url "https://brew.sh/foo-1.0.tgz"
108
+
109
+ head do
110
+ ^^^^^^^ FormulaAudit/ComponentsRedundancy: `head do` should not be present with only url/branch
111
+ url "https://brew.sh/foo.git", branch: "develop"
112
+ end
113
+ end
114
+ RUBY
115
+ end
116
+
92
117
it "reports no offenses if `stable do` is present with `url` and `depends_on`" do
93
118
expect_no_offenses ( <<~RUBY )
94
119
class Foo < Formula
You can’t perform that action at this time.
0 commit comments