components_redundancy: audit stable do without a head or devel spec
This commit is contained in:
parent
cbc3184436
commit
4dba9fddf1
@ -8,10 +8,12 @@ module RuboCop
|
|||||||
# - `url|checksum|mirror` should be inside `stable` block
|
# - `url|checksum|mirror` should be inside `stable` block
|
||||||
# - `head` and `head do` should not be simultaneously present
|
# - `head` and `head do` should not be simultaneously present
|
||||||
# - `bottle :unneeded/:disable` and `bottle do` should not be simultaneously present
|
# - `bottle :unneeded/:disable` and `bottle do` should not be simultaneously present
|
||||||
|
# - `stable do` should not be present without a `head` or `devel` spec
|
||||||
|
|
||||||
class ComponentsRedundancy < FormulaCop
|
class ComponentsRedundancy < FormulaCop
|
||||||
HEAD_MSG = "`head` and `head do` should not be simultaneously present".freeze
|
HEAD_MSG = "`head` and `head do` should not be simultaneously present".freeze
|
||||||
BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present".freeze
|
BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present".freeze
|
||||||
|
STABLE_MSG = "`stable do` should not be present without a `head` or `devel` spec".freeze
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
stable_block = find_block(body_node, :stable)
|
stable_block = find_block(body_node, :stable)
|
||||||
@ -26,6 +28,11 @@ module RuboCop
|
|||||||
|
|
||||||
problem BOTTLE_MSG if method_called?(body_node, :bottle) &&
|
problem BOTTLE_MSG if method_called?(body_node, :bottle) &&
|
||||||
find_block(body_node, :bottle)
|
find_block(body_node, :bottle)
|
||||||
|
|
||||||
|
return if method_called?(body_node, :head) ||
|
||||||
|
find_block(body_node, :head) ||
|
||||||
|
find_block(body_node, :devel)
|
||||||
|
problem STABLE_MSG if stable_block
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -12,6 +12,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do
|
|||||||
stable do
|
stable do
|
||||||
# stuff
|
# stuff
|
||||||
end
|
end
|
||||||
|
|
||||||
|
devel do
|
||||||
|
# stuff
|
||||||
|
end
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
@ -40,5 +44,45 @@ describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "When `stable do` is present with a `head` method" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
head "http://example.com/foo.git"
|
||||||
|
|
||||||
|
stable do
|
||||||
|
# stuff
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "When `stable do` is present with a `head do` block" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
stable do
|
||||||
|
# stuff
|
||||||
|
end
|
||||||
|
|
||||||
|
head do
|
||||||
|
# stuff
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "When `stable do` is present with a `devel` block" do
|
||||||
|
expect_no_offenses(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
stable do
|
||||||
|
# stuff
|
||||||
|
end
|
||||||
|
|
||||||
|
devel do
|
||||||
|
# stuff
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user