2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2020-04-05 15:22:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rubocops/extend/formula"
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module FormulaAudit
|
2020-11-27 13:13:09 -05:00
|
|
|
# This cop audits formulae that are keg-only because they are provided by macos.
|
|
|
|
class ProvidedByMacos < FormulaCop
|
2020-12-02 20:47:53 -05:00
|
|
|
PROVIDED_BY_MACOS_FORMULAE = %w[
|
|
|
|
apr
|
|
|
|
bc
|
|
|
|
bison
|
|
|
|
bzip2
|
|
|
|
cups
|
|
|
|
curl
|
|
|
|
dyld-headers
|
|
|
|
ed
|
|
|
|
expat
|
|
|
|
file-formula
|
|
|
|
flex
|
|
|
|
gcore
|
|
|
|
gnu-getopt
|
|
|
|
icu4c
|
|
|
|
krb5
|
|
|
|
libarchive
|
|
|
|
libedit
|
|
|
|
libffi
|
|
|
|
libiconv
|
|
|
|
libpcap
|
|
|
|
libressl
|
|
|
|
libxml2
|
|
|
|
libxslt
|
|
|
|
llvm
|
|
|
|
lsof
|
|
|
|
m4
|
|
|
|
ncompress
|
|
|
|
ncurses
|
|
|
|
net-snmp
|
|
|
|
openldap
|
|
|
|
openlibm
|
|
|
|
pod2man
|
|
|
|
rpcgen
|
|
|
|
ruby
|
|
|
|
sqlite
|
|
|
|
ssh-copy-id
|
|
|
|
swift
|
|
|
|
tcl-tk
|
|
|
|
texinfo
|
|
|
|
unifdef
|
|
|
|
unzip
|
2020-12-03 14:30:34 -05:00
|
|
|
whois
|
2020-12-02 20:47:53 -05:00
|
|
|
zip
|
|
|
|
zlib
|
|
|
|
].freeze
|
|
|
|
|
2020-11-27 13:13:09 -05:00
|
|
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
|
|
|
find_method_with_args(body_node, :keg_only, :provided_by_macos) do
|
2020-12-02 20:47:53 -05:00
|
|
|
return if PROVIDED_BY_MACOS_FORMULAE.include? @formula_name
|
|
|
|
|
2020-12-03 14:30:34 -05:00
|
|
|
problem "Formulae that are `keg_only :provided_by_macos` should be "\
|
|
|
|
"added to the `PROVIDED_BY_MACOS_FORMULAE` list (in the Homebrew/brew repo)"
|
2020-11-27 13:13:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-11-05 17:17:03 -05:00
|
|
|
# This cop audits `uses_from_macos` dependencies in formulae.
|
2020-04-05 15:22:06 +01:00
|
|
|
class UsesFromMacos < FormulaCop
|
2020-12-02 20:47:53 -05:00
|
|
|
# These formulae aren't `keg_only :provided_by_macos` but are provided by
|
|
|
|
# macOS (or very similarly, e.g. OpenSSL where system provides LibreSSL).
|
|
|
|
# TODO: consider making some of these keg-only.
|
|
|
|
ALLOWED_USES_FROM_MACOS_DEPS = %w[
|
|
|
|
bash
|
|
|
|
cpio
|
|
|
|
expect
|
|
|
|
groff
|
|
|
|
gzip
|
|
|
|
openssl
|
|
|
|
openssl@1.1
|
|
|
|
perl
|
|
|
|
php
|
|
|
|
python
|
|
|
|
python@3
|
|
|
|
rsync
|
|
|
|
vim
|
|
|
|
xz
|
|
|
|
zsh
|
|
|
|
].freeze
|
|
|
|
|
2020-04-05 15:22:06 +01:00
|
|
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
|
|
|
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
2020-10-09 11:12:06 +02:00
|
|
|
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
|
2020-04-05 15:22:06 +01:00
|
|
|
parameters(method).first
|
2020-10-09 11:12:06 +02:00
|
|
|
elsif parameters(method).first.instance_of?(RuboCop::AST::HashNode)
|
2020-04-05 15:22:06 +01:00
|
|
|
parameters(method).first.keys.first
|
|
|
|
end
|
|
|
|
|
2020-12-02 20:47:53 -05:00
|
|
|
dep_name = string_content(dep)
|
|
|
|
next if ALLOWED_USES_FROM_MACOS_DEPS.include? dep_name
|
|
|
|
next if ProvidedByMacos::PROVIDED_BY_MACOS_FORMULAE.include? dep_name
|
2020-04-05 15:22:06 +01:00
|
|
|
|
2020-12-02 20:47:53 -05:00
|
|
|
problem "`uses_from_macos` should only be used for macOS dependencies, not #{dep_name}."
|
2020-04-05 15:22:06 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|