rubocops/text: use rubocop v1 API

This commit is contained in:
Jonathan Chang 2021-01-12 12:01:29 +11:00
parent c18ffa84ca
commit 3bda457478
2 changed files with 16 additions and 10 deletions

View File

@ -10,17 +10,16 @@ module RuboCop
#
# @api private
class Text < FormulaCop
def audit_formula(node, _class_node, _parent_class_node, body_node)
@full_source_content = source_buffer(node).source
extend AutoCorrector
if match = @full_source_content.match(/^require ['"]formula['"]$/)
@offensive_node = node
@source_buf = source_buffer(node)
@line_no = match.pre_match.count("\n") + 1
@column = 0
@length = match[0].length
@offense_source_range = source_range(@source_buf, @line_no, @column, @length)
problem "`#{match}` is now unnecessary"
def audit_formula(node, _class_node, _parent_class_node, body_node)
full_source_content = source_buffer(node).source
if match = full_source_content.match(/^require ['"]formula['"]$/)
range = source_range(source_buffer(node), match.pre_match.count("\n") + 1, 0, match[0].length)
add_offense(range, message: "`#{match}` is now unnecessary") do |corrector|
corrector.remove(range_with_surrounding_space(range: range))
end
end
if !find_node_method_by_name(body_node, :plist_options) &&

View File

@ -16,6 +16,13 @@ describe RuboCop::Cop::FormulaAudit::Text do
homepage "https://brew.sh"
end
RUBY
expect_correction(<<~RUBY)
class Foo < Formula
url "https://brew.sh/foo-1.0.tgz"
homepage "https://brew.sh"
end
RUBY
end
it "with both openssl and libressl optional dependencies" do