Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(CAT-2237) - Update Rubocop #3377

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
inherit_from: .rubocop_todo.yml

require:
- rubocop-rake

Expand Down
7 changes: 6 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ gemspec

group(:bolt_server) do
# Bolt server gems are managed here not in the gemspec
gem "bundler", ">= 2.5.15"
gem "hocon", '>= 1.2.5'
gem "json-schema", '>= 2.8.0'
gem "octokit", ">= 4.0", "< 9"
gem "puma", '>= 3.12.0'
gem "puppetlabs_spec_helper", ">= 5.0", "< 8"
gem "rack", '>= 2.0.5'
gem "rails-auth", '>= 2.1.4'
gem "rake", ">= 12.0", "< 14"
gem "rspec", ">= 3.0", "< 4"
gem "sinatra", '>= 2.0.4'
end

Expand All @@ -27,7 +32,7 @@ group(:test) do
gem "beaker-hostgenerator"
gem "mocha", '~> 1.4.0'
gem "rack-test", '~> 1.0'
gem "rubocop", '~> 1.9.0', require: false
gem "rubocop", '~> 1.72.0', require: false
gem "rubocop-rake", require: false
end

Expand Down
4 changes: 2 additions & 2 deletions acceptance/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rototiller_task :host_config do |task|
task.add_env(name: 'BOLT_CONTROLLER', default: 'debian12-64')
task.add_env(name: 'BOLT_NODES',
default: 'redhat9-64,fedora40-64,windows10ent-64')
ns = [ENV['BOLT_CONTROLLER'], ENV['BOLT_NODES']].join(',')
ns = [ENV.fetch('BOLT_CONTROLLER', nil), ENV.fetch('BOLT_NODES', nil)].join(',')
n = ns.split(',')
n_new = []
n.each_with_index do |node, i|
Expand Down Expand Up @@ -109,7 +109,7 @@ def abs_targets
end
raw_targets = YAML.safe_load(output)
abs_platforms = Hash.new(0)
raw_targets['HOSTS'].each do |_, raw_target|
raw_targets['HOSTS'].each_value do |raw_target|
abs_platforms[raw_target['template']] += 1
end
abs_platforms.map { |platform, num| "#{platform}=#{num}" }.join(' ')
Expand Down
2 changes: 1 addition & 1 deletion acceptance/setup/package/pre-suite/020_install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
end
else
dev_builds_url = ENV['DEV_BUILDS_URL'] || 'http://builds.delivery.puppetlabs.net'
sha_yaml_url = "#{dev_builds_url}/puppet-bolt/#{ENV['SHA']}/artifacts/#{ENV['SHA']}.yaml"
sha_yaml_url = "#{dev_builds_url}/puppet-bolt/#{ENV.fetch('SHA', nil)}/artifacts/#{ENV.fetch('SHA', nil)}.yaml"
install_from_build_data_url('puppet-bolt', sha_yaml_url, bolt)
end
end
2 changes: 1 addition & 1 deletion bolt-modules/boltlib/lib/puppet/functions/apply_prep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run_task(targets, task, args = {}, options = {})
if unsupported_puppet?(result['clientversion'])
Bolt::Logger.deprecate(
"unsupported_puppet",
"Detected unsupported Puppet agent version #{result['clientversion']} on target "\
"Detected unsupported Puppet agent version #{result['clientversion']} on target " \
"#{result.target}. Bolt supports Puppet agent 6.0.0 and higher."
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def puppetdb_command_with_instance(command, version, payload, instance)
# Error if the PDB client does not implement :send_command
unless puppetdb_client.respond_to?(:send_command)
raise Bolt::Error.new(
"PuppetDB client #{puppetdb_client.class} does not implement :send_command, "\
"PuppetDB client #{puppetdb_client.class} does not implement :send_command, " \
"unable to invoke command.",
'bolt/pdb-command'
)
Expand Down
8 changes: 4 additions & 4 deletions bolt-modules/boltlib/lib/puppet/functions/run_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def validate_options(options)
end

if (bad_vs = volumes.reject { |k, v| k.is_a?(String) && v.is_a?(String) }).any?
msg = "Option 'volumes' only accepts strings for keys and values. "\
"Received: #{bad_vs.map(&:inspect).join(', ')}"
msg = "Option 'volumes' only accepts strings for keys and values. " \
"Received: #{bad_vs.map(&:inspect).join(', ')}"
raise Bolt::ValidationError, msg
end
end
Expand All @@ -153,8 +153,8 @@ def validate_options(options)
end

if (bad_ps = ports.reject { |k, v| k.is_a?(Integer) && v.is_a?(Integer) }).any?
msg = "Option 'ports' only accepts integers for keys and values. "\
"Received: #{bad_ps.map(&:inspect).join(', ')}"
msg = "Option 'ports' only accepts integers for keys and values. " \
"Received: #{bad_ps.map(&:inspect).join(', ')}"
raise Bolt::ValidationError, msg
end
end
Expand Down
4 changes: 2 additions & 2 deletions bolt-modules/boltlib/lib/puppet/functions/set_resources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def set_resources(target, resources)

unless resource.target == target
file, line = Puppet::Pops::PuppetStack.top_of_stack
raise Bolt::ValidationError, "Cannot set resource #{resource.reference} for target "\
"#{resource.target} on target #{target}. "\
raise Bolt::ValidationError, "Cannot set resource #{resource.reference} for target " \
"#{resource.target} on target #{target}. " \
"#{Puppet::Util::Errors.error_location(file, line)}"
end

Expand Down
4 changes: 2 additions & 2 deletions bolt-modules/boltlib/lib/puppet/functions/wait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def inner_wait(futures: nil, timeout: nil, options: {})
valid, unknown = options.partition { |k, _v| %w[_catch_errors].include?(k) }.map(&:to_h)
if unknown.any?
file, line = Puppet::Pops::PuppetStack.top_of_stack
msg = "The wait() function call in #{file}#L#{line} received unknown options "\
"#{unknown.keys}. Removing unknown options and continuing..."
msg = "The wait() function call in #{file}#L#{line} received unknown options " \
"#{unknown.keys}. Removing unknown options and continuing..."
Bolt::Logger.warn("plan_function_options", msg)
end

Expand Down
6 changes: 3 additions & 3 deletions bolt-modules/boltlib/spec/functions/run_container_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ def image
end

let(:msg) {
"docker: Error response from daemon: OCI runtime create failed: "\
"container_linux.go:367: starting container process caused: exec: "\
"\"foo\": executable file not found in $PATH: unknown.\n"
"docker: Error response from daemon: OCI runtime create failed: " \
"container_linux.go:367: starting container process caused: exec: " \
"\"foo\": executable file not found in $PATH: unknown.\n"
}
let(:value) do
{ "_error" =>
Expand Down
2 changes: 1 addition & 1 deletion bolt-modules/system/lib/puppet/functions/system/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def env(name)
# Send analytics report
Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)

ENV[name]
ENV.fetch(name, nil)
end
end
2 changes: 1 addition & 1 deletion bolt-modules/system/spec/functions/system/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

describe 'system::env' do
it {
is_expected.to run.with_params('USER').and_return(ENV['USER'])
is_expected.to run.with_params('USER').and_return(ENV.fetch('USER', nil))
}

it "doesn't error for unknown envars" do
Expand Down
6 changes: 1 addition & 5 deletions bolt.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,5 @@ Gem::Specification.new do |spec|
spec.add_dependency "winrm", "~> 2.0"
spec.add_dependency "winrm-fs", "~> 1.3"

spec.add_development_dependency "bundler", ">= 1.14"
spec.add_development_dependency "octokit", ">= 4.0", "< 9"
spec.add_development_dependency "puppetlabs_spec_helper", ">= 5.0", "< 8"
spec.add_development_dependency "rake", ">= 12.0", "< 14"
spec.add_development_dependency "rspec", ">= 3.0", "< 4"
spec.metadata['rubygems_mfa_required'] = 'true'
end
2 changes: 1 addition & 1 deletion developer-docs/examples/bolt_spec_example/tasks/init.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

File.write(ENV['PT_file'], ENV['PT_content'])
File.write(ENV.fetch('PT_file', nil), ENV.fetch('PT_content', nil))
2 changes: 1 addition & 1 deletion lib/bolt/analytics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def self.config_path

if File.exist?(path)
if File.exist?(old_path)
message = "Detected analytics configuration files at '#{old_path}' and '#{path}'. Loading "\
message = "Detected analytics configuration files at '#{old_path}' and '#{path}'. Loading " \
"analytics configuration from '#{path}'."
Bolt::Logger.warn_once('duplicate_analytics', message)
end
Expand Down
26 changes: 13 additions & 13 deletions lib/bolt/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ def apply(manifest, targets, code: '', noop: false)
if defined?(ast.body) &&
(ast.body.is_a?(Puppet::Pops::Model::HostClassDefinition) ||
ast.body.is_a?(Puppet::Pops::Model::ResourceTypeDefinition))
message = "Manifest only contains definitions and will result in no changes on the targets. "\
"Definitions must be declared for their resources to be applied. You can read more "\
"about defining and declaring classes and types in the Puppet documentation at "\
"https://puppet.com/docs/puppet/latest/lang_classes.html and "\
message = "Manifest only contains definitions and will result in no changes on the targets. " \
"Definitions must be declared for their resources to be applied. You can read more " \
"about defining and declaring classes and types in the Puppet documentation at " \
"https://puppet.com/docs/puppet/latest/lang_classes.html and " \
"https://puppet.com/docs/puppet/latest/lang_defined_types.html"
Bolt::Logger.warn("empty_manifest", message)
end
Expand Down Expand Up @@ -281,7 +281,7 @@ def install_modules(outputter, force: false, resolve: true)

if config.project.modules.empty? && resolve
outputter.print_message(
"Project configuration file #{config.project.project_file} does not "\
"Project configuration file #{config.project.project_file} does not " \
"specify any module dependencies. Nothing to do."
)
return true
Expand Down Expand Up @@ -439,8 +439,8 @@ def apply_policies(policies, targets, noop: false)

# CODEREVIEW: Phrasing
raise Bolt::Error.new(
"The following policies are not available to the project: '#{unavailable_policies.join("', '")}'. "\
"You must list policies in a project's 'policies' setting before Bolt can apply them to targets. "\
"The following policies are not available to the project: '#{unavailable_policies.join("', '")}'. " \
"You must list policies in a project's 'policies' setting before Bolt can apply them to targets. " \
"For a list of policies available to the project, run '#{command}'.",
'bolt/unavailable-policy-error'
)
Expand All @@ -460,7 +460,7 @@ def apply_policies(policies, targets, noop: false)
# CODEREVIEW: Phrasing
if unloadable_policies.any?
raise Bolt::Error.new(
"The following policies cannot be loaded: '#{unloadable_policies.join("', '")}'. "\
"The following policies cannot be loaded: '#{unloadable_policies.join("', '")}'. " \
"Policies must be a Puppet class saved to a project's or module's manifests directory.",
'bolt/unloadable-policy-error'
)
Expand Down Expand Up @@ -509,7 +509,7 @@ def new_policy(name)
# Error if name is not namespaced to project
unless prefix == @config.project.name
raise Bolt::ValidationError,
"Policy name '#{name}' must begin with project name '#{@config.project.name}'. Did "\
"Policy name '#{name}' must begin with project name '#{@config.project.name}'. Did " \
"you mean '#{@config.project.name}::#{name}'?"
end

Expand Down Expand Up @@ -578,9 +578,9 @@ def list_policies
command = Bolt::Util.powershell? ? 'New-BoltPolicy -Name <NAME>' : 'bolt policy new <NAME>'

raise Bolt::Error.new(
"Project configuration file #{@config.project.project_file} does not "\
"specify any policies. You can add policies to the project by including "\
"a 'policies' key or creating a new policy using the '#{command}' "\
"Project configuration file #{@config.project.project_file} does not " \
"specify any policies. You can add policies to the project by including " \
"a 'policies' key or creating a new policy using the '#{command}' " \
"command.",
'bolt/no-policies-error'
)
Expand Down Expand Up @@ -719,7 +719,7 @@ def list_tasks(filter: nil)
unless project.project_file?
command = Bolt::Util.powershell? ? 'New-BoltProject' : 'bolt project init'

msg = "Could not find project configuration file #{project.project_file}, unable "\
msg = "Could not find project configuration file #{project.project_file}, unable " \
"to install modules. To create a Bolt project, run '#{command}'."

raise Bolt::Error.new(msg, 'bolt/missing-project-config-error')
Expand Down
2 changes: 1 addition & 1 deletion lib/bolt/applicator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def compile(target, scope)
catalog_request = scope.merge(target: target_data).merge(future: @executor.future || {})

bolt_catalog_exe = File.join(libexec, 'bolt_catalog')
old_path = ENV['PATH']
old_path = ENV.fetch('PATH', nil)
ENV['PATH'] = "#{RbConfig::CONFIG['bindir']}#{File::PATH_SEPARATOR}#{old_path}"
out, err, stat = Open3.capture3('ruby', bolt_catalog_exe, 'compile', stdin_data: catalog_request.to_json)
ENV['PATH'] = old_path
Expand Down
2 changes: 0 additions & 2 deletions lib/bolt/apply_inventory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ def get_target(*_params)
raise InvalidFunctionCall, 'get_target'
end

# rubocop:disable Naming/AccessorMethodName
def set_var(*_params)
raise InvalidFunctionCall, 'set_var'
end

def set_feature(*_params)
raise InvalidFunctionCall, 'set_feature'
end
# rubocop:enable Naming/AccessorMethodName

def vars(target)
@targets[target.name].vars
Expand Down
10 changes: 5 additions & 5 deletions lib/bolt/bolt_option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,8 @@ def initialize(options)
if File.exist?(path) || Pathname.new(path).absolute? ||
!%w[scripts files].include?(path.split(File::SEPARATOR)[1])
raise Bolt::CLIError, "The script must be a detailed Puppet file reference, " \
"for example 'mymodule/scripts/myscript.sh'. See http://pup.pt/bolt-scripts for " \
"more information on detailed Puppet file references."
"for example 'mymodule/scripts/myscript.sh'. See http://pup.pt/bolt-scripts for " \
"more information on detailed Puppet file references."
end

@options[:plan_script] = path
Expand All @@ -1129,8 +1129,8 @@ def initialize(options)
separator "\n#{self.class.colorize(:cyan, 'Display options')}"
define('--filter FILTER', 'Filter tasks and plans by a matching substring.') do |filter|
unless /^[a-z0-9_:]+$/.match(filter)
msg = "Illegal characters in filter string '#{filter}'. Filters can "\
"only include lowercase letters, numbers, underscores, and colons."
msg = "Illegal characters in filter string '#{filter}'. Filters can " \
"only include lowercase letters, numbers, underscores, and colons."
raise Bolt::CLIError, msg
end
@options[:filter] = filter
Expand Down Expand Up @@ -1214,7 +1214,7 @@ def parse_params(params)
end

def permute(args)
super(args)
super
rescue OptionParser::MissingArgument => e
raise Bolt::CLIError, "Option '#{e.args.first}' needs a parameter"
rescue OptionParser::InvalidArgument => e
Expand Down
2 changes: 1 addition & 1 deletion lib/bolt/catalog/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def initialize
# Emits message as a single line of JSON mapping level to message string.
def handle(msg)
str = msg.respond_to?(:multiline) ? msg.multiline : msg.to_s
str = msg.source == "Puppet" ? str : "#{msg.source}: #{str}"
str = "#{msg.source}: #{str}" unless msg.source == "Puppet"
warn({ level: msg.level, message: str }.to_json)
end
end
Loading
Loading