Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .expeditor/verify.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ steps:
docker:
image: ruby:3.4

- label: chefstyle-tests-ruby-3.1
- label: cookstyle-chefstyle-tests-ruby-3.1
command:
- .expeditor/run_linux_tests.sh "rake style:chefstyle"
expeditor:
executor:
docker:
image: ruby:3.1

- label: chefstyle-tests-ruby-3.4
- label: cookstyle-chefstyle-tests-ruby-3.4
command:
- .expeditor/run_linux_tests.sh "rake style:chefstyle"
expeditor:
Expand Down
24 changes: 17 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
---
require:
- chefstyle
- cookstyle

AllCops:
TargetRubyVersion: 3.1
Include:
- "**/*.rb"
- "**/*.rb"
Exclude:
- "vendor/**/*"
- "spec/**/*"
- "vendor/**/*"
- "spec/**/*"
- "lib/chef-cli/skeletons/code_generator"
- "spec/unit/fixtures/chef-runner-cookbooks"
- "spec/unit/fixtures/cookbook_cache"
- "spec/unit/fixtures/example_cookbook"
- "spec/unit/fixtures/example_cookbook_metadata_json_only"
- "spec/unit/fixtures/example_cookbook_no_metadata"
- "spec/unit/fixtures/local_path_cookbooks"

# Disable string literal style check to reduce changes when migrating from chefstyle
Style/StringLiterals:
Exclude:
- "spec/unit/fixtures/**/*"
- "lib/chef-cli/skeletons/**/*"
Enabled: false

Style/StringLiteralsInInterpolation:
Enabled: false
Layout/TrailingWhitespace:
Exclude:
- "spec/unit/fixtures/**/*"
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ group :test do
gem "rspec", "=3.12.0"
gem "rspec-expectations", "~> 3.8"
gem "rspec-mocks", "~> 3.8"
gem "cookstyle"
gem "chefstyle"
gem "cookstyle", ">= 7.32"
gem "faraday_middleware"
gem "chef-test-kitchen-enterprise", git: "https://github.com/chef/chef-test-kitchen-enterprise", branch: "main"
gem "simplecov", require: false
Expand Down
25 changes: 9 additions & 16 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,17 @@ namespace :style do
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV["CI"]
end

begin
desc "Run Chef Ruby style checks"
task :chefstyle do
require "rubocop/rake_task"
require "cookstyle/chefstyle"

ignore_dirs = Regexp.union(%w{
lib/chef-cli/skeletons/code_generator
spec/unit/fixtures/chef-runner-cookbooks
spec/unit/fixtures/cookbook_cache
spec/unit/fixtures/example_cookbook
spec/unit/fixtures/example_cookbook_metadata_json_only
spec/unit/fixtures/example_cookbook_no_metadata
spec/unit/fixtures/local_path_cookbooks
})

desc "Run Chef Ruby style checks"
RuboCop::RakeTask.new(:chefstyle) do |t|
t.requires = ["chefstyle"]
t.patterns = `rubocop --list-target-files`.split("\n").reject { |f| f =~ ignore_dirs }
t.options = ["--display-cop-names"]
if RbConfig::CONFIG["host_os"] =~ /mswin|mingw|cygwin/
# Windows-specific command, rubocop erroneously reports the CRLF in each file which is removed when your PR is uploaded to GitHub.
# This is a workaround to ignore the CRLF from the files before running cookstyle.
sh "cookstyle --chefstyle -c .rubocop.yml --except Layout/EndOfLine --display-cop-names"
else
sh "cookstyle --chefstyle -c .rubocop.yml --display-cop-names"
end
rescue LoadError => e
puts ">>> Gem load error: #{e}, omitting #{task.name}" unless ENV["CI"]
Expand Down
11 changes: 5 additions & 6 deletions lib/chef-cli/builtin_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

ChefCLI.commands do |c|
c.builtin "exec", :Exec, require_path: "chef-cli/command/exec",
desc: "Runs the command in context of the embedded ruby"
desc: "Runs the command in context of the embedded ruby"

c.builtin "env", :Env, require_path: "chef-cli/command/env",
desc: "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}"
desc: "Prints environment variables used by #{ChefCLI::Dist::PRODUCT}"

c.builtin "gem", :GemForwarder, require_path: "chef-cli/command/gem",
desc: "Runs the `gem` command in context of the embedded Ruby"

desc: "Runs the `gem` command in context of the embedded Ruby"
c.builtin "generate", :Generate, desc: "Generate a new repository, cookbook, or other component"

c.builtin "shell-init", :ShellInit, desc: "Initialize your shell to use #{ChefCLI::Dist::PRODUCT} as your primary Ruby"
Expand Down Expand Up @@ -56,7 +55,7 @@
c.builtin "undelete", :Undelete, desc: "Undo a delete command"

c.builtin "describe-cookbook", :DescribeCookbook, require_path: "chef-cli/command/describe_cookbook",
desc: "Prints cookbook checksum information used for cookbook identifier"
desc: "Prints cookbook checksum information used for cookbook identifier"
c.builtin "license", :License, require_path: "chef-cli/command/license",
desc: "Create & install a new license on the system or view installed license(s)."
desc: "Create & install a new license on the system or view installed license(s)."
end
4 changes: 2 additions & 2 deletions lib/chef-cli/command/delete_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def run(params)
def rm_policy_service
@rm_policy_service ||=
PolicyfileServices::RmPolicy.new(config: chef_config,
ui:,
policy_name:)
ui:,
policy_name:)
end

def debug?
Expand Down
4 changes: 2 additions & 2 deletions lib/chef-cli/command/delete_policy_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def run(params)
def rm_policy_group_service
@rm_policy_group_service ||=
PolicyfileServices::RmPolicyGroup.new(config: chef_config,
ui:,
policy_group:)
ui:,
policy_group:)
end

def debug?
Expand Down
8 changes: 4 additions & 4 deletions lib/chef-cli/command/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ def print_diff

def differ(ui = self.ui)
Policyfile::Differ.new(old_name: old_base.name,
old_lock:,
new_name: new_base.name,
new_lock:,
ui:)
old_lock:,
new_name: new_base.name,
new_lock:,
ui:)
end

def http_client
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-cli/command/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class GemForwarder < ChefCLI::Command::Base

def run(params)
retval = Gem::GemRunner.new.run( params.clone )
retval.nil? ? true : retval
retval.nil? || retval
rescue Gem::SystemExitException => e
exit( e.exit_code )
end
Expand Down
8 changes: 4 additions & 4 deletions lib/chef-cli/command/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ def debug?

def push
@push ||= PolicyfileServices::Push.new(policyfile: policyfile_relative_path,
ui:,
policy_group:,
config: chef_config,
root_dir: Dir.pwd)
ui:,
policy_group:,
config: chef_config,
root_dir: Dir.pwd)
end

def handle_error(error)
Expand Down
12 changes: 6 additions & 6 deletions lib/chef-cli/command/show_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ def run(params)
def show_policy_service
@policy_list_service ||=
PolicyfileServices::ShowPolicy.new(config: chef_config,
ui:,
policy_name:,
policy_group:,
show_orphans: show_orphans?,
summary_diff: show_summary_diff?,
pager: enable_pager?)
ui:,
policy_name:,
policy_group:,
show_orphans: show_orphans?,
summary_diff: show_summary_diff?,
pager: enable_pager?)
end

def debug?
Expand Down
4 changes: 2 additions & 2 deletions lib/chef-cli/command/undelete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def run(params)
def undelete_service
@undelete_service ||=
PolicyfileServices::Undelete.new(config: chef_config,
ui:,
undo_record_id:)
ui:,
undo_record_id:)
end

def debug?
Expand Down
4 changes: 2 additions & 2 deletions lib/chef-cli/cookbook_omnifetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
end

ChefCLI::ChefServerAPIMulti.new(Chef::Config.chef_server_url,
signing_key_filename: Chef::Config.client_key,
client_name: Chef::Config.node_name)
signing_key_filename: Chef::Config.client_key,
client_name: Chef::Config.node_name)
end
end
3 changes: 1 addition & 2 deletions lib/chef-cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ def git_windows_bin_dir
# environment vars for habitat
#
def habitat_env(show_warning: false)
@habitat_env ||=
begin
@habitat_env ||= begin
if habitat_chef_dke?
bin_pkg_prefix = get_pkg_prefix(ChefCLI::Dist::CHEF_DKE_PKG_NAME)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-cli/policyfile/git_lock_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def lock_data
opt["tag"] = tag unless opt.key?("tag") || branch.nil?
opt["ref"] = ref unless opt.key?("ref") || ref.nil?

path_keys = %w{path rel}.map { |path_key| path_key if opt.key?(path_key) }.compact
path_keys = %w{path rel}.select { |path_key| opt.key?(path_key) }

path_keys.each do |name|
# We can safely grab the entire cookbook when the Policyfile defines a cookbook path of itself (".")
Expand Down
10 changes: 5 additions & 5 deletions lib/chef-cli/skeletons/code_generator/recipes/cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,11 @@

file "#{cookbook_dir}/.vscode/extensions.json" do
content <<~CONTENT
{
"recommendations": [
"chef-software.chef"
]
}
{
"recommendations": [
"chef-software.chef"
]
}
CONTENT
end
end
2 changes: 1 addition & 1 deletion lib/chef-cli/skeletons/code_generator/recipes/profile.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
context = ChefCLI::Generator.context
cookbook_dir = File.join(context.cookbook_root, context.cookbook_name)
profile_dir = File.join(cookbook_dir, 'compliance', 'profiles', "#{context.new_file_basename}")
profile_dir = File.join(cookbook_dir, 'compliance', 'profiles', context.new_file_basename.to_s)
control_dir = File.join(profile_dir, 'controls')

directory control_dir do
Expand Down
2 changes: 1 addition & 1 deletion lib/kitchen/provisioner/chef_zero_capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def create_sandbox
def default_config_rb
cfg = super
# Need to tell chef-zero about our additional config.
root = config[:root_path].gsub("$env:TEMP", "\#{ENV['TEMP']\}")
root = config[:root_path].gsub("$env:TEMP", "#{ENV['TEMP']}")
cfg[:policies_path] = remote_path_join(root, config[:policies_path])
cfg[:policy_groups_path] = remote_path_join(root, config[:policy_groups_path])
cfg[:cookbook_artifacts_path] = remote_path_join(root, config[:cookbook_artifacts_path])
Expand Down
4 changes: 2 additions & 2 deletions lib/kitchen/provisioner/policyfile_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def policy_exporter
# Must force this because TK by default copies the current cookbook to the sandbox
# See ChefCLI::PolicyfileServices::ExportRepo#assert_export_dir_clean!
@policy_exporter ||= ChefCLI::PolicyfileServices::ExportRepo.new(policyfile: config[:policyfile],
export_dir: sandbox_path,
force: true)
export_dir: sandbox_path,
force: true)
end

# Writes a fake (but valid) validation.pem into the sandbox directory.
Expand Down
Loading