From 0560ee2f2d98cff6ba1a00ea9563e80e07db79d5 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 20 Aug 2020 13:00:01 -0700 Subject: [PATCH] Optimize our requires Avoid requiring things that are already defined. Rubygems is very slow at traversing the filesystem. Signed-off-by: Tim Smith --- Rakefile | 2 +- chef_dsl_metadata/Rakefile | 4 ++-- lib/foodcritic.rb | 6 +++--- lib/foodcritic/api.rb | 2 +- lib/foodcritic/dsl.rb | 4 ++-- lib/foodcritic/linter.rb | 6 +++--- lib/foodcritic/output.rb | 2 +- spec/spec_helper.rb | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Rakefile b/Rakefile index 873acce5..738dbac2 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ require "bundler/setup" -require "mixlib/shellout" +require "mixlib/shellout" unless defined?(Mixlib::ShellOut) require "bundler/gem_tasks" diff --git a/chef_dsl_metadata/Rakefile b/chef_dsl_metadata/Rakefile index b066323e..352aecc9 100644 --- a/chef_dsl_metadata/Rakefile +++ b/chef_dsl_metadata/Rakefile @@ -1,6 +1,6 @@ require "appraisal" -require "fileutils" -require "ffi_yajl" +require "fileutils" unless defined?(FileUtils) +require "ffi_yajl" unless defined?(FFI_Yajl) task :generate_chef_metadata do require_chef diff --git a/lib/foodcritic.rb b/lib/foodcritic.rb index 8d56ec14..e1bf92c4 100644 --- a/lib/foodcritic.rb +++ b/lib/foodcritic.rb @@ -1,11 +1,11 @@ Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 -require "pathname" +require "pathname" unless defined?(Pathname) require "treetop" require "ripper" -require "ffi_yajl" -require "erubis" +require "ffi_yajl" unless defined?(FFI_Yajl) +require "erubis" unless defined?(Erubis) require_relative "foodcritic/chef" require_relative "foodcritic/command_line" diff --git a/lib/foodcritic/api.rb b/lib/foodcritic/api.rb index d39c1ed2..1759497f 100644 --- a/lib/foodcritic/api.rb +++ b/lib/foodcritic/api.rb @@ -1,4 +1,4 @@ -require "nokogiri" +require "nokogiri" unless defined?(Nokogiri) require "rufus-lru" module FoodCritic diff --git a/lib/foodcritic/dsl.rb b/lib/foodcritic/dsl.rb index 6fde3619..d6925eec 100644 --- a/lib/foodcritic/dsl.rb +++ b/lib/foodcritic/dsl.rb @@ -1,5 +1,5 @@ -require "open-uri" -require "pathname" +require "open-uri" unless defined?(OpenURI) +require "pathname" unless defined?(Pathname) module FoodCritic # The DSL methods exposed for defining rules. A minimal example rule: diff --git a/lib/foodcritic/linter.rb b/lib/foodcritic/linter.rb index f3ad401a..fd43653c 100644 --- a/lib/foodcritic/linter.rb +++ b/lib/foodcritic/linter.rb @@ -1,7 +1,7 @@ -require "open-uri" -require "optparse" +require "open-uri" unless defined?(OpenURI) +require "optparse" unless defined?(OptionParser) require "ripper" -require "set" +require "set" unless defined?(Set) module FoodCritic # The main entry point for linting your Chef cookbooks. diff --git a/lib/foodcritic/output.rb b/lib/foodcritic/output.rb index 51d18535..fbdf52fe 100644 --- a/lib/foodcritic/output.rb +++ b/lib/foodcritic/output.rb @@ -1,4 +1,4 @@ -require "set" +require "set" unless defined?(Set) module FoodCritic class Output diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3c7fecb4..bc143c55 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,4 @@ -require "shellwords" +require "shellwords" unless defined?(Shellwords) require "rspec_command" require "simplecov"