From 626c232be56e1b83d23da5baf26ad4ee47f31b94 Mon Sep 17 00:00:00 2001 From: dcrosby Date: Tue, 30 Jan 2024 11:56:27 -0800 Subject: [PATCH] Add chefstyle library file for Rake backwards compatibility There's a decent amount of Rake code that uses `require "chefstyle"` to set the defaults for RuboCop (eg https://github.com/chef/ohai/blob/6d64237f9987c3bf51805e19884e6e710c3a40f6/Rakefile#L19), and rather than doing surgery on each repo's Rakefile, it'd be easier to keep that same behavior for loading the configuration and cops. With this change a migration involving Rake should only involve a Gemfile update and changing `require "chefstyle"` to `require "cookstyle/chefstyle"`. Signed-off-by: David Crosby --- bin/cookstyle | 13 ++++++------- lib/cookstyle/chefstyle.rb | 4 ++++ 2 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 lib/cookstyle/chefstyle.rb diff --git a/bin/cookstyle b/bin/cookstyle index 93b5ebc4..54da192a 100755 --- a/bin/cookstyle +++ b/bin/cookstyle @@ -1,16 +1,15 @@ #!/usr/bin/env ruby # frozen_string_literal: true -if ARGV.include?('--chefstyle') - ARGV.delete('--chefstyle') - module Cookstyle - CHEFSTYLE_CONFIG = true - end -end $LOAD_PATH.unshift File.join(__dir__, %w(.. lib)) -require 'cookstyle' +if ARGV.include?('--chefstyle') + ARGV.delete('--chefstyle') + require 'cookstyle/chefstyle' +else + require 'cookstyle' +end # force the fail level to :convention so that we can set all our new rules to # the lowest level of :refactor without failing everyone's CI jobs diff --git a/lib/cookstyle/chefstyle.rb b/lib/cookstyle/chefstyle.rb new file mode 100644 index 00000000..135815c9 --- /dev/null +++ b/lib/cookstyle/chefstyle.rb @@ -0,0 +1,4 @@ +module Cookstyle + CHEFSTYLE_CONFIG = true +end +require_relative '../cookstyle'