2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2020-04-05 15:22:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2023-02-20 10:22:39 -08:00
|
|
|
require "rubocops/extend/formula_cop"
|
2020-04-05 15:22:06 +01:00
|
|
|
|
|
|
|
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.
|
2023-02-20 18:10:59 -08:00
|
|
|
class ProvidedByMacos < FormulaCop
|
2020-12-02 20:47:53 -05:00
|
|
|
PROVIDED_BY_MACOS_FORMULAE = %w[
|
|
|
|
apr
|
|
|
|
bc
|
2022-03-30 14:24:10 +01:00
|
|
|
berkeley-db
|
2020-12-02 20:47:53 -05:00
|
|
|
bison
|
|
|
|
bzip2
|
|
|
|
cups
|
|
|
|
curl
|
2021-03-08 15:12:17 -08:00
|
|
|
cyrus-sasl
|
2020-12-02 20:47:53 -05:00
|
|
|
dyld-headers
|
|
|
|
ed
|
|
|
|
expat
|
|
|
|
file-formula
|
|
|
|
flex
|
|
|
|
gnu-getopt
|
2021-01-02 23:21:14 +01:00
|
|
|
gperf
|
2020-12-02 20:47:53 -05:00
|
|
|
icu4c
|
|
|
|
krb5
|
|
|
|
libarchive
|
|
|
|
libedit
|
|
|
|
libffi
|
|
|
|
libiconv
|
|
|
|
libpcap
|
|
|
|
libressl
|
2022-04-18 17:54:20 +01:00
|
|
|
libxcrypt
|
2020-12-02 20:47:53 -05:00
|
|
|
libxml2
|
|
|
|
libxslt
|
|
|
|
llvm
|
|
|
|
lsof
|
|
|
|
m4
|
|
|
|
ncompress
|
|
|
|
ncurses
|
|
|
|
net-snmp
|
2021-01-07 22:27:15 +01:00
|
|
|
netcat
|
2020-12-02 20:47:53 -05:00
|
|
|
openldap
|
2022-06-29 09:55:54 -07:00
|
|
|
pax
|
2021-03-08 23:40:29 -08:00
|
|
|
pcsc-lite
|
2020-12-02 20:47:53 -05:00
|
|
|
pod2man
|
|
|
|
rpcgen
|
|
|
|
ruby
|
|
|
|
sqlite
|
|
|
|
ssh-copy-id
|
|
|
|
swift
|
|
|
|
tcl-tk
|
|
|
|
unifdef
|
|
|
|
unzip
|
2020-12-03 14:30:34 -05:00
|
|
|
whois
|
2020-12-02 20:47:53 -05:00
|
|
|
zip
|
|
|
|
zlib
|
|
|
|
].freeze
|
|
|
|
|
2024-07-07 15:18:29 -04:00
|
|
|
sig { override.params(formula_nodes: FormulaNodes).void }
|
|
|
|
def audit_formula(formula_nodes)
|
|
|
|
return if (body_node = formula_nodes.body_node).nil?
|
2022-11-05 04:17:50 +00:00
|
|
|
|
2020-11-27 13:13:09 -05:00
|
|
|
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
|
|
|
|
|
2022-06-28 10:09:59 +01:00
|
|
|
problem "Formulae that are `keg_only :provided_by_macos` should be " \
|
2020-12-03 14:30:34 -05:00
|
|
|
"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.
|
2023-02-20 18:10:59 -08: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
|
2021-06-08 13:03:25 +01:00
|
|
|
git
|
2020-12-02 20:47:53 -05:00
|
|
|
groff
|
|
|
|
gzip
|
2022-07-11 22:13:11 -07:00
|
|
|
less
|
2022-11-10 21:56:23 -08:00
|
|
|
mandoc
|
2020-12-02 20:47:53 -05:00
|
|
|
openssl
|
|
|
|
perl
|
|
|
|
php
|
|
|
|
python
|
|
|
|
rsync
|
|
|
|
vim
|
|
|
|
xz
|
|
|
|
zsh
|
|
|
|
].freeze
|
|
|
|
|
2024-07-07 15:18:29 -04:00
|
|
|
sig { override.params(formula_nodes: FormulaNodes).void }
|
|
|
|
def audit_formula(formula_nodes)
|
|
|
|
return if (body_node = formula_nodes.body_node).nil?
|
2022-11-05 04:17:50 +00:00
|
|
|
|
2023-12-21 14:05:29 -05:00
|
|
|
depends_on_linux = depends_on?(:linux)
|
|
|
|
|
2020-04-05 15:22:06 +01:00
|
|
|
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
2023-12-21 14:05:29 -05:00
|
|
|
@offensive_node = method
|
|
|
|
problem "`uses_from_macos` should not be used when Linux is required." if depends_on_linux
|
|
|
|
|
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
|