Skip to content
Snippets Groups Projects
Commit ca59377a authored by Jonathan Chang's avatar Jonathan Chang
Browse files

audit: add autocorrect and tests for test checks

parent 5f981a87
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,17 @@ module RuboCop
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
(send nil? ${:system :shell_output :pipe_output} $...)
EOS
......
......@@ -76,6 +76,31 @@ describe RuboCop::Cop::FormulaAudit::TestCalls do
end
RUBY
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
describe RuboCop::Cop::FormulaAuditStrict::Test do
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment