Merge pull request #17228 from Homebrew/replace-formula-text-audits-with-rubocops
Replace `FormulaTextAuditor` usage
This commit is contained in:
commit
82c2e743a5
@ -2,7 +2,6 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "deprecate_disable"
|
require "deprecate_disable"
|
||||||
require "formula_text_auditor"
|
|
||||||
require "formula_versions"
|
require "formula_versions"
|
||||||
require "resource_auditor"
|
require "resource_auditor"
|
||||||
require "utils/shared_audits"
|
require "utils/shared_audits"
|
||||||
@ -32,7 +31,7 @@ module Homebrew
|
|||||||
@core_tap = formula.tap&.core_tap? || options[:core_tap]
|
@core_tap = formula.tap&.core_tap? || options[:core_tap]
|
||||||
@problems = []
|
@problems = []
|
||||||
@new_formula_problems = []
|
@new_formula_problems = []
|
||||||
@text = FormulaTextAuditor.new(formula.path)
|
@text = formula.path.open("rb", &:read)
|
||||||
@specs = %w[stable head].filter_map { |s| formula.send(s) }
|
@specs = %w[stable head].filter_map { |s| formula.send(s) }
|
||||||
@spdx_license_data = options[:spdx_license_data]
|
@spdx_license_data = options[:spdx_license_data]
|
||||||
@spdx_exception_data = options[:spdx_exception_data]
|
@spdx_exception_data = options[:spdx_exception_data]
|
||||||
@ -510,16 +509,6 @@ module Homebrew
|
|||||||
"It must not be upgraded to version #{relicensed_version} or newer."
|
"It must not be upgraded to version #{relicensed_version} or newer."
|
||||||
end
|
end
|
||||||
|
|
||||||
def audit_keg_only_reason
|
|
||||||
return unless @core_tap
|
|
||||||
return unless formula.keg_only?
|
|
||||||
|
|
||||||
keg_only_message = text.to_s.match(/keg_only\s+["'](.*)["']/)&.captures&.first
|
|
||||||
return unless keg_only_message&.include?("HOMEBREW_PREFIX")
|
|
||||||
|
|
||||||
problem "`keg_only` reason should not include `HOMEBREW_PREFIX` as it creates confusing `brew info` output."
|
|
||||||
end
|
|
||||||
|
|
||||||
def audit_versioned_keg_only
|
def audit_versioned_keg_only
|
||||||
return unless @versioned_formula
|
return unless @versioned_formula
|
||||||
return unless @core_tap
|
return unless @core_tap
|
||||||
|
|||||||
@ -1,43 +0,0 @@
|
|||||||
# typed: true
|
|
||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
module Homebrew
|
|
||||||
# Auditor for checking common violations in {Formula} text content.
|
|
||||||
class FormulaTextAuditor
|
|
||||||
def initialize(path)
|
|
||||||
@text = path.open("rb", &:read)
|
|
||||||
@lines = @text.lines.to_a
|
|
||||||
end
|
|
||||||
|
|
||||||
def without_patch
|
|
||||||
@text.split("\n__END__").first
|
|
||||||
end
|
|
||||||
|
|
||||||
def trailing_newline?
|
|
||||||
/\Z\n/.match?(@text)
|
|
||||||
end
|
|
||||||
|
|
||||||
def =~(other)
|
|
||||||
other =~ @text
|
|
||||||
end
|
|
||||||
|
|
||||||
def include?(string)
|
|
||||||
@text.include? string
|
|
||||||
end
|
|
||||||
|
|
||||||
sig { returns(String) }
|
|
||||||
def to_s
|
|
||||||
@text
|
|
||||||
end
|
|
||||||
|
|
||||||
def line_number(regex, skip = 0)
|
|
||||||
index = @lines.drop(skip).index { |line| line.match?(regex) }
|
|
||||||
index ? index + 1 : nil
|
|
||||||
end
|
|
||||||
|
|
||||||
def reverse_line_number(regex)
|
|
||||||
index = @lines.reverse.index { |line| line.match?(regex) }
|
|
||||||
index ? @lines.count - index : nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -30,8 +30,15 @@ module RuboCop
|
|||||||
problem "Formulae should not depend on both OpenSSL and LibreSSL (even optionally)."
|
problem "Formulae should not depend on both OpenSSL and LibreSSL (even optionally)."
|
||||||
end
|
end
|
||||||
|
|
||||||
if formula_tap == "homebrew-core" && (depends_on?("veclibfort") || depends_on?("lapack"))
|
if formula_tap == "homebrew-core"
|
||||||
problem "Formulae in homebrew/core should use OpenBLAS as the default serial linear algebra library."
|
if depends_on?("veclibfort") || depends_on?("lapack")
|
||||||
|
problem "Formulae in homebrew/core should use OpenBLAS as the default serial linear algebra library."
|
||||||
|
end
|
||||||
|
|
||||||
|
if find_node_method_by_name(body_node, :keg_only)&.source&.include?("HOMEBREW_PREFIX")
|
||||||
|
problem "`keg_only` reason should not include `HOMEBREW_PREFIX` " \
|
||||||
|
"as it creates confusing `brew info` output."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
unless method_called_ever?(body_node, :go_resource)
|
unless method_called_ever?(body_node, :go_resource)
|
||||||
|
|||||||
@ -1238,7 +1238,7 @@ RSpec.describe Homebrew::FormulaAuditor do
|
|||||||
|
|
||||||
describe "#audit_conflicts" do
|
describe "#audit_conflicts" do
|
||||||
before do
|
before do
|
||||||
# We don't really test FormulaTextAuditor here
|
# We don't really test the formula text retrieval here
|
||||||
allow(File).to receive(:open).and_return("")
|
allow(File).to receive(:open).and_return("")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
# frozen_string_literal: true
|
|
||||||
|
|
||||||
require "formula_text_auditor"
|
|
||||||
|
|
||||||
RSpec.describe Homebrew::FormulaTextAuditor do
|
|
||||||
alias_matcher :have_trailing_newline, :be_trailing_newline
|
|
||||||
|
|
||||||
let(:dir) { mktmpdir }
|
|
||||||
|
|
||||||
def formula_text(name, body = nil)
|
|
||||||
path = dir/"#{name}.rb"
|
|
||||||
|
|
||||||
path.write <<~RUBY
|
|
||||||
class #{Formulary.class_s(name)} < Formula
|
|
||||||
#{body}
|
|
||||||
end
|
|
||||||
RUBY
|
|
||||||
|
|
||||||
described_class.new(path)
|
|
||||||
end
|
|
||||||
|
|
||||||
specify "simple valid Formula" do
|
|
||||||
ft = formula_text "valid", <<~RUBY
|
|
||||||
url "https://www.brew.sh/valid-1.0.tar.gz"
|
|
||||||
RUBY
|
|
||||||
|
|
||||||
expect(ft).to have_trailing_newline
|
|
||||||
|
|
||||||
expect(ft =~ /\burl\b/).to be_truthy
|
|
||||||
expect(ft.line_number(/desc/)).to be_nil
|
|
||||||
expect(ft.line_number(/\burl\b/)).to eq(2)
|
|
||||||
expect(ft).to include("Valid")
|
|
||||||
end
|
|
||||||
|
|
||||||
specify "#trailing_newline?" do
|
|
||||||
ft = formula_text "newline"
|
|
||||||
expect(ft).to have_trailing_newline
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Loading…
x
Reference in New Issue
Block a user