Merge pull request #4625 from DomT4/please_stop_evading_the_audit
class_cop: tighten test audit
This commit is contained in:
commit
f1779248de
@ -25,13 +25,24 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
module FormulaAuditStrict
|
module FormulaAuditStrict
|
||||||
# - `test do ..end` should be defined in the formula
|
# - `test do ..end` should be meaningfully defined in the formula
|
||||||
class Test < FormulaCop
|
class Test < FormulaCop
|
||||||
MSG = "A `test do` test block should be added".freeze
|
|
||||||
|
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
return if find_block(body_node, :test)
|
test = find_block(body_node, :test)
|
||||||
problem MSG
|
|
||||||
|
unless test
|
||||||
|
problem "A `test do` test block should be added"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if test.body.nil?
|
||||||
|
problem "`test do` should not be empty"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
return unless test.body.single_line? &&
|
||||||
|
test.body.source.to_s == "true"
|
||||||
|
problem "`test do` should contain a real test"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -59,4 +59,29 @@ describe RuboCop::Cop::FormulaAuditStrict::Test do
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "reports an offense when there is an empty test block" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://example.com/foo-1.0.tgz'
|
||||||
|
|
||||||
|
test do
|
||||||
|
^^^^^^^ `test do` should not be empty
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when test is falsely true" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://example.com/foo-1.0.tgz'
|
||||||
|
|
||||||
|
test do
|
||||||
|
^^^^^^^ `test do` should contain a real test
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user