rubocops/class: rename, move cops, readd strict.
This commit is contained in:
parent
3d9cf83fec
commit
476a61f51c
@ -26,11 +26,18 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestCalls < FormulaCop
|
class Test < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
test = find_block(body_node, :test)
|
test = find_block(body_node, :test)
|
||||||
return unless test
|
return unless test
|
||||||
|
|
||||||
|
if test.body.nil?
|
||||||
|
problem "`test do` should not be empty"
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
problem "`test do` should contain a real test" if test.body.single_line? && test.body.source.to_s == "true"
|
||||||
|
|
||||||
test_calls(test) do |node, params|
|
test_calls(test) do |node, params|
|
||||||
p1, p2 = params
|
p1, p2 = params
|
||||||
if match = string_content(p1).match(%r{(/usr/local/(s?bin))})
|
if match = string_content(p1).match(%r{(/usr/local/(s?bin))})
|
||||||
@ -70,26 +77,13 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module FormulaAudit
|
module FormulaAuditStrict
|
||||||
# - `test do ..end` should be meaningfully defined in the formula.
|
# - `test do ..end` should defined in the formula.
|
||||||
class Test < FormulaCop
|
class TestPresent < FormulaCop
|
||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
test = find_block(body_node, :test)
|
return if find_block(body_node, :test)
|
||||||
|
|
||||||
unless test
|
problem "A `test do` test block should be added"
|
||||||
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?
|
|
||||||
return if test.body.source.to_s != "true"
|
|
||||||
|
|
||||||
problem "`test do` should contain a real test"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -50,7 +50,7 @@ describe RuboCop::Cop::FormulaAudit::ClassName do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe RuboCop::Cop::FormulaAudit::TestCalls do
|
describe RuboCop::Cop::FormulaAudit::Test do
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
it "reports an offense when /usr/local/bin is found in test calls" do
|
it "reports an offense when /usr/local/bin is found in test calls" do
|
||||||
@ -79,6 +79,31 @@ describe RuboCop::Cop::FormulaAudit::TestCalls do
|
|||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "reports an offense when there is an empty test block" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://brew.sh/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://brew.sh/foo-1.0.tgz'
|
||||||
|
|
||||||
|
test do
|
||||||
|
^^^^^^^ `test do` should contain a real test
|
||||||
|
true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
it "supports auto-correcting test calls" do
|
it "supports auto-correcting test calls" do
|
||||||
source = <<~RUBY
|
source = <<~RUBY
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
@ -105,7 +130,7 @@ describe RuboCop::Cop::FormulaAudit::TestCalls do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe RuboCop::Cop::FormulaAudit::Test do
|
describe RuboCop::Cop::FormulaAuditStrict::TestPresent do
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
it "reports an offense when there is no test block" do
|
it "reports an offense when there is no test block" do
|
||||||
@ -116,29 +141,4 @@ describe RuboCop::Cop::FormulaAudit::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://brew.sh/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://brew.sh/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