Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
new chefstyle rules for 0.13.2
Browse files Browse the repository at this point in the history
chef/chefstyle#74

Signed-off-by: Lamont Granquist <[email protected]>
  • Loading branch information
lamont-granquist committed Jul 9, 2019
1 parent d42c4c6 commit b256d74
Show file tree
Hide file tree
Showing 93 changed files with 371 additions and 306 deletions.
4 changes: 3 additions & 1 deletion lib/chef-dk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def show_help
justify_length = subcommands.map(&:length).max + 2
subcommand_specs.each do |name, spec|
next if spec.hidden

msg(" #{"#{name}".ljust(justify_length)}#{spec.description}")
end
end
Expand Down Expand Up @@ -155,7 +156,7 @@ def instantiate_subcommand(name)
private

def normalized_exit_code(maybe_integer)
if maybe_integer.kind_of?(Integer) && (0..255).cover?(maybe_integer)
if maybe_integer.is_a?(Integer) && (0..255).cover?(maybe_integer)
maybe_integer
else
0
Expand Down Expand Up @@ -186,6 +187,7 @@ def env
def sanity_check!
# When installed outside of omnibus, trust the user to configure their PATH
return true unless omnibus_install?

paths = env[path_key].split(File::PATH_SEPARATOR)
paths.map! { |p| drive_upcase(Chef::Util::PathHelper.cleanpath(p)) }
embed_index = paths.index(drive_upcase(Chef::Util::PathHelper.cleanpath(omnibus_embedded_bin_dir)))
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/clean_policy_cookbooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def initialize(*args)

def run(params)
return 1 unless apply_params!(params)

clean_policy_cookbooks_service.run
0
rescue PolicyfileServiceError => e
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/clean_policy_revisions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def initialize(*args)

def run(params)
return 1 unless apply_params!(params)

clean_policies_service.run
0
rescue PolicyfileServiceError => e
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/delete_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def initialize(*args)

def run(params)
return 1 unless apply_params!(params)

rm_policy_service.run
ui.msg("This operation can be reversed by running `#{ChefDK::Dist::EXEC} undelete --last`.")
0
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/delete_policy_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def initialize(*args)

def run(params)
return 1 unless apply_params!(params)

rm_policy_group_service.run
ui.msg("This operation can be reversed by running `#{ChefDK::Dist::EXEC} undelete --last`.")
0
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/describe_cookbook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def initialize(*args)
def run(params = [])
return 1 unless apply_params!(params)
return 1 unless check_cookbook_path

IdDumper.new(ui, cookbook_path).run
end

Expand Down
8 changes: 5 additions & 3 deletions lib/chef-dk/command/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def debug?

def run(params = [])
return 1 unless apply_params!(params)

print_diff
0
rescue PolicyfileServiceError => e
Expand Down Expand Up @@ -153,7 +154,7 @@ def print_diff
end
end

def differ(ui = self.ui())
def differ(ui = self.ui)
Policyfile::Differ.new(old_name: old_base.name,
old_lock: old_lock,
new_name: new_base.name,
Expand All @@ -163,8 +164,8 @@ def differ(ui = self.ui())

def http_client
@http_client ||= Chef::ServerAPI.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

def old_lock
Expand Down Expand Up @@ -290,6 +291,7 @@ def comparing_policy_groups?
def policy_group_comparison?(args)
return false if args.empty?
return true if args.size > 1

!(args.first =~ /\.rb\Z/)
end

Expand Down
12 changes: 6 additions & 6 deletions lib/chef-dk/command/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def initialize(*args)

def run(params)
info = {}
info["#{ChefDK::Dist::PRODUCT}"] = Hash.new.tap do |chefdk_env|
info["#{ChefDK::Dist::PRODUCT}"] = {}.tap do |chefdk_env|
chefdk_env["ChefDK"] = chefdk_info
chefdk_env["Ruby"] = ruby_info
chefdk_env["Path"] = paths
Expand All @@ -46,7 +46,7 @@ def run(params)
end

def chefdk_info
Hash.new.tap do |chefdk|
{}.tap do |chefdk|
chefdk["ChefDK Version"] = ChefDK::VERSION
chefdk["ChefDK Home"] = chefdk_home
chefdk["ChefDK Install Directory"] = omnibus_root
Expand All @@ -55,10 +55,10 @@ def chefdk_info
end

def ruby_info
Hash.new.tap do |ruby|
{}.tap do |ruby|
ruby["Ruby Executable"] = Gem.ruby
ruby["Ruby Version"] = RUBY_VERSION
ruby["RubyGems"] = Hash.new.tap do |rubygems|
ruby["RubyGems"] = {}.tap do |rubygems|
rubygems["RubyGems Version"] = Gem::VERSION
rubygems["RubyGems Platforms"] = Gem.platforms.map(&:to_s)
rubygems["Gem Environment"] = gem_environment
Expand All @@ -67,7 +67,7 @@ def ruby_info
end

def gem_environment
Hash.new.tap do |h|
{}.tap do |h|
h["GEM ROOT"] = omnibus_env["GEM_ROOT"]
h["GEM HOME"] = omnibus_env["GEM_HOME"]
h["GEM PATHS"] = omnibus_env["GEM_PATH"].split(File::PATH_SEPARATOR)
Expand All @@ -79,7 +79,7 @@ def paths
end

def policyfile_config
Hash.new.tap do |h|
{}.tap do |h|
h["Cache Path"] = CookbookOmnifetch.cache_path
h["Storage Path"] = CookbookOmnifetch.storage_path.to_s
end
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def initialize(*args)

def run(params = [])
return 1 unless apply_params!(params)

export_service.run
ui.msg("Exported policy '#{export_service.policyfile_lock.name}' to #{export_target}")
unless archive?
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/generate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def generator_for(arg)
# we delegate the request to the specified generator.
def needs_help?(params)
return false if have_generator?(params[0])

super
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@ class QuieterDocFormatter < Chef::Formatters::Doc
cli_name(:chefdk_doc)

# Called when starting to collect gems from the cookbooks
def cookbook_gem_start(gems)
end
def cookbook_gem_start(gems); end

# Called when cookbook loading starts.
def library_load_start(file_count)
end
def library_load_start(file_count); end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def initialize(*args)

def run
return 1 unless verify_params!

FileUtils.cp_r(source, destination_dir)
update_metadata_rb
ui.msg("Copied built-in generator cookbook to #{created_cookbook_path}")
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def initialize(*args)

def run(params = [])
return 1 unless apply_params!(params)

# Force config file to be loaded. We don't use the configuration
# directly, but the user may have SSL configuration options that they
# need to talk to a private supermarket (e.g., trusted_certs or
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def initialize(*args)

def run(params = [])
return 1 unless apply_params!(params)

push.run
0
rescue PolicyfileServiceError => e
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/command/push_archive.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def push_archive_service
policy_group: policy_group,
ui: ui,
config: chef_config
)
)
end

def archive_file
Expand Down
5 changes: 3 additions & 2 deletions lib/chef-dk/command/shell_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def run(argv)
return 1
elsif !SUPPORTED_SHELLS.include?(shell_name)
err("Shell `#{shell_name}' is not currently supported")
err("Supported shells are: #{SUPPORTED_SHELLS.join(' ')}")
err("Supported shells are: #{SUPPORTED_SHELLS.join(" ")}")
return 1
end

Expand All @@ -116,6 +116,7 @@ def emit_shell_cmd(cmd)

def completion_for(shell)
return "" unless (completion_template_basename = completion_template_for(shell))

completion_template_path = expand_completion_template_path(completion_template_basename)
erb = ERB.new(File.read(completion_template_path), nil, "-")
context_binding = shell_completion_template_context.get_binding
Expand Down Expand Up @@ -165,7 +166,7 @@ def fish_shell_export(var, val)
# /dev/null to avoid Fish's helpful warnings about nonexistent
# PATH elements.
if var == "PATH"
emit_shell_cmd(%Q{set -gx #{var} "#{val.split(':').join('" "')}" 2>/dev/null;})
emit_shell_cmd(%Q{set -gx #{var} "#{val.split(":").join('" "')}" 2>/dev/null;})
else
emit_shell_cmd(%Q{set -gx #{var} "#{val}";})
end
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/show_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def initialize(*args)

def run(params)
return 1 unless apply_params!(params)

show_policy_service.run
0
rescue PolicyfileServiceError => e
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/undelete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def initialize(*args)

def run(params)
return 1 unless apply_params!(params)

if list_undo_records?
undelete_service.list
else
Expand Down
1 change: 1 addition & 0 deletions lib/chef-dk/command/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def initialize(*args)

def run(params = [])
return 1 unless apply_params!(params)

attributes_updater.run
installer.run(@cookbooks_to_update, config[:exclude_deps]) unless update_attributes_only?
0
Expand Down
3 changes: 2 additions & 1 deletion lib/chef-dk/component_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def sh(command, options = {})
# the return value of the test block. For tests that run a lot of commands,
# this is inconvenient so you can use #sh! instead.
def sh!(*args)
sh(*args).tap { |result| result.error! }
sh(*args).tap(&:error!)
end

# Run a command, if the command returns zero, raise an error,
Expand Down Expand Up @@ -197,6 +197,7 @@ def component_path

def gem_base_dir
return nil if @gem_name_for_base_dir.nil?

# There is no way to say "give me the latest prerelease OR normal version of this gem.
# So we first ask if there is a normal version, and if there is not, we ask if there
# is a prerelease version. ">= 0.a" is how we ask for a prerelease version, because a
Expand Down
5 changes: 3 additions & 2 deletions lib/chef-dk/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module Configurable

def chef_config
return @chef_config if @chef_config

config_loader.load
@chef_config = Chef::Config
CookbookOmnifetch.integration.default_chef_server_http_client = default_chef_server_http_client
Expand Down Expand Up @@ -79,8 +80,8 @@ def reset_config!
def default_chef_server_http_client
lambda do
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

Expand Down
3 changes: 1 addition & 2 deletions lib/chef-dk/cookbook_profiler/null_scm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module ChefDK
module CookbookProfiler
class NullSCM

def initialize(cookbook_path)
end
def initialize(cookbook_path); end

def profile_data
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Context
def self.add_attr(name)
@attributes ||= [ ]

if !@attributes.include?(name)
unless @attributes.include?(name)
@attributes << name
attr_accessor(name)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/chef-dk/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def omnibus_env

def omnibus_expand_path(*paths)
dir = File.expand_path(File.join(paths))
raise OmnibusInstallNotFound.new() unless dir && File.directory?(dir)
raise OmnibusInstallNotFound.new unless dir && File.directory?(dir)

dir
end

Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/policyfile/artifactory_cookbook_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def default_source_args
end

def ==(other)
other.kind_of?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks
other.is_a?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks
end

def preferred_for(*cookbook_names)
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/policyfile/attribute_merge_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def check!
def fill!(acc, source_name, path, hash)
hash.each do |(key, val)|
new_path = "#{path}[#{key}]"
if val.kind_of?(Hash)
if val.is_a?(Hash)
acc[key] ||= Mash.new
fill!(acc[key], source_name, new_path, val)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/chef-dk/policyfile/chef_repo_cookbook_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def preferred_source_for?(cookbook_name)
end

def ==(other)
other.kind_of?(self.class) && other.path == path && other.preferred_cookbooks == preferred_cookbooks
other.is_a?(self.class) && other.path == path && other.preferred_cookbooks == preferred_cookbooks
end

# Calls the slurp_metadata! helper once to calculate the @universe_graph
Expand Down
6 changes: 3 additions & 3 deletions lib/chef-dk/policyfile/chef_server_cookbook_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def default_source_args
end

def ==(other)
other.kind_of?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks
other.is_a?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks
end

def preferred_for(*cookbook_names)
Expand Down Expand Up @@ -84,8 +84,8 @@ def desc
def http_connection_for(base_url)
@http_connections[base_url] ||=
ChefServerAPIMulti.new(base_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

def full_chef_server_graph
Expand Down
Loading

0 comments on commit b256d74

Please sign in to comment.