rubocops/lines: move strict cop.
This commit is contained in:
parent
9b5a0767cb
commit
ea77fce409
@ -196,26 +196,6 @@ module RuboCop
|
||||
end
|
||||
|
||||
class Miscellaneous < FormulaCop
|
||||
MAKE_CHECK_WHITELIST = %w[
|
||||
beecrypt
|
||||
ccrypt
|
||||
git
|
||||
gmp
|
||||
gnupg
|
||||
gnupg@1.4
|
||||
google-sparsehash
|
||||
jemalloc
|
||||
jpeg-turbo
|
||||
mpfr
|
||||
nettle
|
||||
open-mpi
|
||||
openssl@1.1
|
||||
pcre
|
||||
protobuf
|
||||
wolfssl
|
||||
xz
|
||||
].freeze
|
||||
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
# FileUtils is included in Formula
|
||||
# encfs modifies a file with this name, so check for some leading characters
|
||||
@ -260,18 +240,18 @@ module RuboCop
|
||||
# Avoid hard-coding compilers
|
||||
find_every_method_call_by_name(body_node, :system).each do |method|
|
||||
param = parameters(method).first
|
||||
if match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
|
||||
if match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)[\s"]?})
|
||||
problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\""
|
||||
elsif match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
|
||||
elsif match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)[\s"]?})
|
||||
problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
|
||||
end
|
||||
end
|
||||
|
||||
find_instance_method_call(body_node, "ENV", :[]=) do |method|
|
||||
param = parameters(method)[1]
|
||||
if match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
|
||||
if match = regex_match_group(param, %r{^(/usr/bin/)?(gcc|llvm-gcc|clang)[\s"]?})
|
||||
problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\""
|
||||
elsif match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
|
||||
elsif match = regex_match_group(param, %r{^(/usr/bin/)?((g|llvm-g|clang)\+\+)[\s"]?})
|
||||
problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
|
||||
end
|
||||
end
|
||||
@ -439,25 +419,6 @@ module RuboCop
|
||||
|
||||
problem "Use the `#{match}` Ruby method instead of `#{method.source}`"
|
||||
end
|
||||
|
||||
return if formula_tap != "homebrew-core"
|
||||
|
||||
# Avoid build-time checks in homebrew/core
|
||||
find_every_method_call_by_name(body_node, :system).each do |method|
|
||||
next if @formula_name.start_with?("lib")
|
||||
next if MAKE_CHECK_WHITELIST.include?(@formula_name)
|
||||
|
||||
params = parameters(method)
|
||||
next unless node_equals?(params[0], "make")
|
||||
|
||||
params[1..].each do |arg|
|
||||
next unless regex_match_group(arg, /^(checks?|tests?)$/)
|
||||
|
||||
offending_node(method)
|
||||
problem "Formulae in homebrew/core (except e.g. cryptography, libraries) " \
|
||||
"should not run build-time checks"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def modifier?(node)
|
||||
@ -493,5 +454,50 @@ module RuboCop
|
||||
EOS
|
||||
end
|
||||
end
|
||||
|
||||
module FormulaAuditStrict
|
||||
class MakeCheck < FormulaCop
|
||||
MAKE_CHECK_WHITELIST = %w[
|
||||
beecrypt
|
||||
ccrypt
|
||||
git
|
||||
gmp
|
||||
gnupg
|
||||
gnupg@1.4
|
||||
google-sparsehash
|
||||
jemalloc
|
||||
jpeg-turbo
|
||||
mpfr
|
||||
nettle
|
||||
open-mpi
|
||||
openssl@1.1
|
||||
pcre
|
||||
protobuf
|
||||
wolfssl
|
||||
xz
|
||||
].freeze
|
||||
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
return if formula_tap != "homebrew-core"
|
||||
|
||||
# Avoid build-time checks in homebrew/core
|
||||
find_every_method_call_by_name(body_node, :system).each do |method|
|
||||
next if @formula_name.start_with?("lib")
|
||||
next if MAKE_CHECK_WHITELIST.include?(@formula_name)
|
||||
|
||||
params = parameters(method)
|
||||
next unless node_equals?(params[0], "make")
|
||||
|
||||
params[1..].each do |arg|
|
||||
next unless regex_match_group(arg, /^(checks?|tests?)$/)
|
||||
|
||||
offending_node(method)
|
||||
problem "Formulae in homebrew/core (except e.g. cryptography, libraries) " \
|
||||
"should not run build-time checks"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -349,17 +349,6 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing formula" do
|
||||
it "build-time checks in homebrew/core" do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/")
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
system "make", "-j1", "test"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core (except e.g. cryptography, libraries) should not run build-time checks
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "FileUtils usage" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
@ -860,6 +849,21 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
it "build-time checks in homebrew/core" do
|
||||
expect_offense(<<~RUBY, "/homebrew-core/")
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
system "make", "-j1", "test"
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core (except e.g. cryptography, libraries) should not run build-time checks
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
include_examples "formulae exist", described_class::MAKE_CHECK_WHITELIST
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user