Merge pull request #4414 from commitay/stable-block

components_redundancy: audit `stable do` without a head or devel spec
This commit is contained in:
Mike McQuaid 2018-07-03 08:29:52 +01:00 committed by GitHub
commit c81806543f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 51 additions and 0 deletions

View File

@ -8,10 +8,12 @@ module RuboCop
# - `url|checksum|mirror` should be inside `stable` block
# - `head` and `head 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
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
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)
stable_block = find_block(body_node, :stable)
@ -26,6 +28,11 @@ module RuboCop
problem BOTTLE_MSG if method_called?(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

View File

@ -12,6 +12,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do
stable do
# stuff
end
devel do
# stuff
end
end
RUBY
end
@ -40,5 +44,45 @@ describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do
end
RUBY
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