From a2ac654d886198aa14a08e151332be5cbb241446 Mon Sep 17 00:00:00 2001 From: Tim Smith Date: Thu, 17 Sep 2020 12:00:30 -0700 Subject: [PATCH] Enable 7 more cops to simplify our code Signed-off-by: Tim Smith --- bin/chefstyle | 2 +- chefstyle.gemspec | 2 +- config/chefstyle.yml | 28 ++++++++++++++++++++++++++++ lib/chefstyle.rb | 4 ++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/bin/chefstyle b/bin/chefstyle index 49d051b..02ac60e 100755 --- a/bin/chefstyle +++ b/bin/chefstyle @@ -1,6 +1,6 @@ #!/usr/bin/env ruby # frozen_string_literal: true -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), %w{.. lib}) +$LOAD_PATH.unshift File.join(__dir__, %w{.. lib}) require "chefstyle" diff --git a/chefstyle.gemspec b/chefstyle.gemspec index 043f325..709aa22 100644 --- a/chefstyle.gemspec +++ b/chefstyle.gemspec @@ -1,5 +1,5 @@ # frozen_string_literal: true -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "chefstyle/version" diff --git a/config/chefstyle.yml b/config/chefstyle.yml index 8513841..cdb8e79 100644 --- a/config/chefstyle.yml +++ b/config/chefstyle.yml @@ -637,6 +637,34 @@ Lint/DeprecatedOpenSSLConstant: Lint/Syntax: Enabled: true +# remove extra requires like 'thread' +Lint/RedundantRequireStatement: + Enabled: true + +# simplify stripping strings +Style/Strip: + Enabled: true + +# simplify getting min/max +Style/RedundantSort: + Enabled: true + +# no need for .rb in requires +Style/RedundantFileExtensionInRequire: + Enabled: true + +# more code you don't need +Style/RedundantCondition: + Enabled: true + +# Use __dir__ to simplify things +Style/Dir: + Enabled: true + +# Use __FILE__ or __dir__ to simplify expand_paths +Style/ExpandPathArguments: + Enabled: true + ChefRuby/Ruby27KeywordArgumentWarnings: Description: Pass options to shell_out helpers without the brackets to avoid Ruby 2.7 deprecation warnings. Enabled: true diff --git a/lib/chefstyle.rb b/lib/chefstyle.rb index be32937..5d0d8e1 100644 --- a/lib/chefstyle.rb +++ b/lib/chefstyle.rb @@ -9,7 +9,7 @@ module RuboCop class ConfigLoader RUBOCOP_HOME.gsub!( /^.*$/, - File.realpath(File.join(File.dirname(__FILE__), "..")) + File.realpath(File.join(__dir__, "..")) ) DEFAULT_FILE.gsub!( @@ -31,7 +31,7 @@ def self.config require_relative "rubocop/chef" # Chef custom cops -Dir.glob(File.dirname(__FILE__) + "/rubocop/cop/chef/**/*.rb") do |file| +Dir.glob(__dir__ + "/rubocop/cop/chef/**/*.rb") do |file| next if File.directory?(file) require_relative file # not actually relative but require_relative is faster