2020-04-05 15:22:06 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rubocops/extend/formula"
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module FormulaAudit
|
|
|
|
# This cop audits `uses_from_macos` dependencies in formulae
|
|
|
|
class UsesFromMacos < FormulaCop
|
|
|
|
ALLOWED_USES_FROM_MACOS_DEPS = %w[
|
|
|
|
bison
|
|
|
|
bzip2
|
|
|
|
curl
|
|
|
|
expat
|
|
|
|
expect
|
|
|
|
flex
|
|
|
|
groff
|
2020-04-07 12:16:17 +01:00
|
|
|
icu4c
|
|
|
|
krb5
|
|
|
|
libedit
|
2020-04-05 15:22:06 +01:00
|
|
|
libffi
|
2020-04-07 12:16:17 +01:00
|
|
|
libpcap
|
2020-04-05 15:22:06 +01:00
|
|
|
libxml2
|
|
|
|
libxslt
|
2020-04-07 12:16:17 +01:00
|
|
|
llvm
|
2020-04-05 15:22:06 +01:00
|
|
|
m4
|
2020-04-07 15:04:23 +01:00
|
|
|
ncurses
|
2020-04-07 12:16:17 +01:00
|
|
|
openldap
|
2020-04-11 14:21:57 +01:00
|
|
|
openssl@1.1
|
2020-04-05 15:22:06 +01:00
|
|
|
perl
|
|
|
|
php
|
|
|
|
ruby
|
|
|
|
sqlite
|
2020-04-07 15:04:23 +01:00
|
|
|
ssh-copy-id
|
2020-04-07 12:16:17 +01:00
|
|
|
tcl-tk
|
2020-04-05 15:22:06 +01:00
|
|
|
texinfo
|
|
|
|
unzip
|
|
|
|
vim
|
|
|
|
xz
|
2020-04-07 12:16:17 +01:00
|
|
|
zip
|
2020-04-07 15:04:23 +01:00
|
|
|
zlib
|
2020-04-05 15:22:06 +01:00
|
|
|
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
|
|
|
|
parameters(method).first
|
|
|
|
elsif parameters(method).first.class == RuboCop::AST::HashNode
|
|
|
|
parameters(method).first.keys.first
|
|
|
|
end
|
|
|
|
|
|
|
|
next if ALLOWED_USES_FROM_MACOS_DEPS.include?(string_content(dep))
|
|
|
|
|
|
|
|
problem "`uses_from_macos` should only be used for macOS dependencies, not #{string_content(dep)}."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|