audit: add autocorrect and tests for test checks
This commit is contained in:
parent
5f981a8722
commit
ca59377a90
@ -39,6 +39,17 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autocorrect(node)
|
||||||
|
lambda do |corrector|
|
||||||
|
case node.type
|
||||||
|
when :str, :dstr
|
||||||
|
corrector.replace(node.source_range, node.source.to_s.sub(%r{(/usr/local/(s?bin))}, '#{\2}'))
|
||||||
|
when :int
|
||||||
|
corrector.remove(range_with_surrounding_comma(range_with_surrounding_space(range: node.source_range, side: :left)))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def_node_search :test_calls, <<~EOS
|
def_node_search :test_calls, <<~EOS
|
||||||
(send nil? ${:system :shell_output :pipe_output} $...)
|
(send nil? ${:system :shell_output :pipe_output} $...)
|
||||||
EOS
|
EOS
|
||||||
|
@ -76,6 +76,31 @@ describe RuboCop::Cop::FormulaAudit::TestCalls do
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "supports auto-correcting test calls" do
|
||||||
|
source = <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://example.com/foo-1.0.tgz'
|
||||||
|
|
||||||
|
test do
|
||||||
|
shell_output("/usr/local/sbin/test", 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
corrected_source = <<~RUBY
|
||||||
|
class Foo < Formula
|
||||||
|
url 'https://example.com/foo-1.0.tgz'
|
||||||
|
|
||||||
|
test do
|
||||||
|
shell_output("\#{sbin}/test")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
|
||||||
|
new_source = autocorrect_source(source)
|
||||||
|
expect(new_source).to eq(corrected_source)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe RuboCop::Cop::FormulaAuditStrict::Test do
|
describe RuboCop::Cop::FormulaAuditStrict::Test do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user