Skip to content

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 <lamont@scriptkiddie.org>
  • Loading branch information
lamont-granquist committed Jul 9, 2019
1 parent 491aef2 commit 1f99599
Show file tree
Hide file tree
Showing 92 changed files with 364 additions and 308 deletions.
11 changes: 1 addition & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
Style/StringLiterals:
AllCops:
Exclude:
- "spec/unit/fixtures/**/*"
- "lib/chef-cli/skeletons/**/*"
Layout/TrailingWhitespace:
Exclude:
- "spec/unit/fixtures/**/*"
Style/PercentLiteralDelimiters:
Exclude:
- "lib/chef-cli/skeletons/**/*"
Layout/TrailingBlankLines:
Exclude:
- "spec/unit/fixtures/**/*"
4 changes: 3 additions & 1 deletion lib/chef-cli/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-cli/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-cli/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-cli/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 `#{ChefCLI::Dist::EXEC} undelete --last`.")
0
Expand Down
1 change: 1 addition & 0 deletions lib/chef-cli/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 `#{ChefCLI::Dist::EXEC} undelete --last`.")
0
Expand Down
1 change: 1 addition & 0 deletions lib/chef-cli/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-cli/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
6 changes: 3 additions & 3 deletions lib/chef-cli/command/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def workstation_info
end

def ruby_info
Hash.new.tap do |ruby|
{}.tap do |ruby|
ruby["Executable"] = Gem.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 Down Expand Up @@ -88,7 +88,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-cli/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-cli/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(:chefcli_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-cli/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-cli/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-cli/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-cli/command/shell_init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,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 @@ -117,6 +117,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 @@ -166,7 +167,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-cli/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-cli/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-cli/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-cli/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-cli/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-cli/cookbook_profiler/null_scm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module ChefCLI
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-cli/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-cli/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,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-cli/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-cli/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-cli/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-cli/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
10 changes: 5 additions & 5 deletions lib/chef-cli/policyfile/chef_server_lock_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def valid?
def errors
error_messages = []

[:server, :policy_name].each do |key|
%i{server policy_name}.each do |key|
error_messages << "include_policy for #{name} is missing key #{key}" unless source_options[key]
end

if [:policy_revision_id, :policy_group].all? { |key| source_options[key].nil? }
if %i{policy_revision_id policy_group}.all? { |key| source_options[key].nil? }
error_messages << "include_policy for #{name} must specify policy_revision_id or policy_group"
end

Expand All @@ -101,7 +101,7 @@ def apply_locked_source_options(options_from_lock)
acc
end
source_options.merge!(options)
raise ChefCLI::InvalidLockfile, "Invalid source_options provided from lock data: #{options_from_lock_file.inspect}" if !valid?
raise ChefCLI::InvalidLockfile, "Invalid source_options provided from lock data: #{options_from_lock_file.inspect}" unless valid?
end

# @return [String] of the policyfile lock data
Expand Down Expand Up @@ -158,8 +158,8 @@ def server
# @return [Hash] Returns a parsed JSON object... I think.
def http_client
@http_client ||= Chef::ServerAPI.new(source_options[:server],
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
Loading

0 comments on commit 1f99599

Please sign in to comment.