summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-09-20 23:57:26 -0700
committerTim Smith <tsmith84@gmail.com>2020-09-20 23:57:26 -0700
commiteb49e6b6b8c160da0cf53f05fefa1c90d7a3a993 (patch)
treeec146beb48dda66abdefe0d0330c71c053498b18
parentcb6ee920847d91b8c6cd8e7cb210b8a4fc730e69 (diff)
downloadchef-requires.tar.gz
Gate requires in chef-utils and chef-config as wellrequires
Update the cop config to handle those as well Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--.rubocop.yml8
-rw-r--r--chef-config/lib/chef-config/config.rb6
-rw-r--r--chef-config/spec/spec_helper.rb2
-rw-r--r--chef-config/spec/unit/fips_spec.rb2
-rw-r--r--chef-config/spec/unit/workstation_config_loader_spec.rb4
-rw-r--r--chef-utils/spec/spec_helper.rb2
-rw-r--r--lib/chef/formatters/indentable_output_stream.rb2
-rw-r--r--lib/chef/knife/core/ui.rb2
8 files changed, 18 insertions, 10 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index b587000ad4..3209f30aba 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -30,3 +30,11 @@ Lint/IneffectiveAccessModifier:
Enabled: false
Lint/ShadowedException:
Enabled: false
+
+# set additional paths
+ChefRuby/UnlessDefinedRequire:
+ Include:
+ - 'lib/**/*'
+ - 'chef-bin/**/*'
+ - 'chef-config/**/*'
+ - 'chef-utils/**/*'
diff --git a/chef-config/lib/chef-config/config.rb b/chef-config/lib/chef-config/config.rb
index 58b60e5295..7451f744a7 100644
--- a/chef-config/lib/chef-config/config.rb
+++ b/chef-config/lib/chef-config/config.rb
@@ -1258,9 +1258,9 @@ module ChefConfig
# @api private
def self.enable_fips_mode
OpenSSL.fips_mode = true
- require "digest"
- require "digest/sha1"
- require "digest/md5"
+ require "digest" unless defined?(Digest)
+ require "digest/sha1" unless defined?(Digest::SHA1)
+ require "digest/md5" unless defined?(Digest::MD5)
# Remove pre-existing constants if they do exist to reduce the
# amount of log spam and warnings.
Digest.send(:remove_const, "SHA1") if Digest.const_defined?("SHA1")
diff --git a/chef-config/spec/spec_helper.rb b/chef-config/spec/spec_helper.rb
index 557f1f6432..fb6e78a6b1 100644
--- a/chef-config/spec/spec_helper.rb
+++ b/chef-config/spec/spec_helper.rb
@@ -1,4 +1,4 @@
-require "chef-utils"
+require "chef-utils" unless defined?(ChefUtils)
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
diff --git a/chef-config/spec/unit/fips_spec.rb b/chef-config/spec/unit/fips_spec.rb
index 5ee62b6c79..4be6f64a2d 100644
--- a/chef-config/spec/unit/fips_spec.rb
+++ b/chef-config/spec/unit/fips_spec.rb
@@ -20,7 +20,7 @@ require "chef-config/fips"
require "spec_helper"
begin
- require "win32/registry"
+ require "win32/registry" unless defined?(Win32::Registry)
rescue LoadError
# not on unix
end
diff --git a/chef-config/spec/unit/workstation_config_loader_spec.rb b/chef-config/spec/unit/workstation_config_loader_spec.rb
index c589b298ae..cffc316240 100644
--- a/chef-config/spec/unit/workstation_config_loader_spec.rb
+++ b/chef-config/spec/unit/workstation_config_loader_spec.rb
@@ -17,10 +17,10 @@
#
require "spec_helper"
-require "tempfile"
+require "tempfile" unless defined?(Tempfile)
require "chef-config/exceptions"
-require "chef-utils"
+require "chef-utils" unless defined?(ChefUtils)
require "chef-config/workstation_config_loader"
RSpec.describe ChefConfig::WorkstationConfigLoader do
diff --git a/chef-utils/spec/spec_helper.rb b/chef-utils/spec/spec_helper.rb
index 0b193e2d9a..b7efd66c4e 100644
--- a/chef-utils/spec/spec_helper.rb
+++ b/chef-utils/spec/spec_helper.rb
@@ -1,4 +1,4 @@
-require "chef-utils"
+require "chef-utils" unless defined?(ChefUtils)
# FIXME: dynamically generate this for accuracy
HELPER_MODULES = [
diff --git a/lib/chef/formatters/indentable_output_stream.rb b/lib/chef/formatters/indentable_output_stream.rb
index d508a32eb0..c2d835d951 100644
--- a/lib/chef/formatters/indentable_output_stream.rb
+++ b/lib/chef/formatters/indentable_output_stream.rb
@@ -20,7 +20,7 @@ class Chef
# pastel.decorate is a lightweight replacement for highline.color
def pastel
@pastel ||= begin
- require "pastel"
+ require "pastel" unless defined?(Pastel)
Pastel.new
end
end
diff --git a/lib/chef/knife/core/ui.rb b/lib/chef/knife/core/ui.rb
index 0d467b69c8..0a7bb2f69d 100644
--- a/lib/chef/knife/core/ui.rb
+++ b/lib/chef/knife/core/ui.rb
@@ -70,7 +70,7 @@ class Chef
# pastel.decorate is a lightweight replacement for highline.color
def pastel
@pastel ||= begin
- require "pastel"
+ require "pastel" unless defined?(Pastel)
Pastel.new
end
end