style: don't need require "formula"
This commit is contained in:
parent
1a703a1234
commit
9e52712b08
@ -838,15 +838,10 @@ module Homebrew
|
||||
|
||||
def line_problems(line, _lineno)
|
||||
# Check for string interpolation of single values.
|
||||
if line =~ /(system|inreplace|gsub!|change_make_var!).*[ ,]"#\{([\w.]+)\}"/
|
||||
# TODO: check could be in RuboCop
|
||||
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
|
||||
end
|
||||
|
||||
return unless @strict
|
||||
return unless line =~ /(system|inreplace|gsub!|change_make_var!).*[ ,]"#\{([\w.]+)\}"/
|
||||
|
||||
# TODO: check could be in RuboCop
|
||||
problem "`#{Regexp.last_match(1)}` is now unnecessary" if line =~ /(require ["']formula["'])/
|
||||
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
|
||||
end
|
||||
|
||||
def audit_reverse_migration
|
||||
|
||||
@ -6,7 +6,19 @@ module RuboCop
|
||||
module Cop
|
||||
module FormulaAudit
|
||||
class Text < FormulaCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
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['"]$/)
|
||||
@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"
|
||||
end
|
||||
|
||||
if !find_node_method_by_name(body_node, :plist_options) &&
|
||||
find_method_def(body_node, :plist)
|
||||
problem "Please set plist_options when using a formula-defined plist."
|
||||
|
||||
@ -6,6 +6,17 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula text" do
|
||||
it "with `require \"formula\"` is present" do
|
||||
expect_offense(<<~RUBY)
|
||||
require "formula"
|
||||
^^^^^^^^^^^^^^^^^ `require "formula"` is now unnecessary
|
||||
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
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user