rubocops/uses_from_macos: update list.

Also, provide details on how to update this in future and split it into
two.

Fixes #7396
This commit is contained in:
Mike McQuaid 2020-04-20 10:36:42 +01:00
parent 929d8fccc8
commit cddc67b451
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
2 changed files with 43 additions and 11 deletions

View File

@ -7,42 +7,72 @@ module RuboCop
module FormulaAudit
# This cop audits `uses_from_macos` dependencies in formulae
class UsesFromMacos < FormulaCop
ALLOWED_USES_FROM_MACOS_DEPS = %w[
# Generate with:
# brew ruby -e 'puts Formula.select {|f| f.keg_only_reason&.provided_by_macos? }.map(&:name).sort.join("\n")'
# Not done at runtime as its too slow and RuboCop doesn't have access.
PROVIDED_BY_MACOS_FORMULAE = %w[
apr
bc
bison
bzip2
cups
curl
dyld-headers
expat
expect
file-formula
flex
groff
gcore
gnu-getopt
icu4c
krb5
libarchive
libedit
libffi
libiconv
libpcap
libressl
libxml2
libxslt
llvm
lsof
m4
ncompress
ncurses
net-snmp
openldap
openssl@1.1
perl
php
openlibm
pod2man
rpcgen
ruby
sqlite
ssh-copy-id
swift
tcl-tk
texinfo
unifdef
unzip
vim
xz
zip
zlib
zsh
].freeze
# 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 = (PROVIDED_BY_MACOS_FORMULAE + %w[
bash
expect
groff
openssl
openssl@1.1
perl
php
python
python@3
vim
xz
zsh
]).freeze
def audit_formula(_node, _class_node, _parent_class_node, body_node)
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
dep = if parameters(method).first.class == RuboCop::AST::StrNode

View File

@ -3,8 +3,10 @@
shared_examples "formulae exist" do |array|
array.each do |f|
it "#{f} formula exists" do
formula_path = Pathname("#{HOMEBREW_LIBRARY_PATH}/../Taps/homebrew/homebrew-core/Formula/#{f}.rb")
expect(formula_path.exist?).to be true
core_tap = Pathname("#{HOMEBREW_LIBRARY_PATH}/../Taps/homebrew/homebrew-core")
formula_path = core_tap/"Formula/#{f}.rb"
alias_path = core_tap/"Aliases/#{f}"
expect(formula_path.exist? || alias_path.exist?).to be true
end
end
end