diff --git a/.rubocop.yml b/.rubocop.yml index 29fcedbd5..8f782e741 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -71,7 +71,6 @@ Style/TrailingCommaInArrayLiteral: Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets -inherit_from: ".rubocop_todo.yml" RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 198402c84..c3fb6926b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,10 +1,26 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2020-12-17 20:35:36 UTC using RuboCop version 1.6.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 6 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'lib/facter/facter_dot_d.rb' + - 'lib/puppet/functions/merge.rb' + - 'lib/puppet/parser/functions/getvar.rb' + - 'lib/puppet/parser/functions/has_interface_with.rb' + +# Offense count: 62 +# Configuration parameters: IgnoreSharedExamples. RSpec/NamedSubject: Enabled: false -Lint/ScriptPermission: - Enabled: false -Style/HashSyntax: + +# Offense count: 2 +RSpec/SubjectStub: Exclude: - - spec/spec_helper.rb - EnforcedStyle: hash_rockets -Layout/IndentHeredoc: - Enabled: false + - 'spec/unit/facter/facter_dot_d_spec.rb' diff --git a/.sync.yml b/.sync.yml index 01c24d807..2fe796248 100644 --- a/.sync.yml +++ b/.sync.yml @@ -2,8 +2,7 @@ ".gitlab-ci.yml": delete: true ".rubocop.yml": - default_configs: - inherit_from: ".rubocop_todo.yml" + include_todos: true ".travis.yml": global_env: - HONEYCOMB_WRITEKEY="7f3c63a70eecc61d635917de46bea4e6",HONEYCOMB_DATASET="litmus tests" @@ -46,16 +45,9 @@ appveyor.yml: APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 simplecov: true Gemfile: - use_litmus: true optional: ":development": - gem: github_changelog_generator - git: https://github.com/skywinder/github-changelog-generator - ref: 20ee04ba1234e9e83eb2ffb5056e23d641c7a018 - condition: Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.2.2') -Rakefile: - requires: - - puppet-lint/tasks/puppet-lint spec/spec_helper.rb: mock_with: ":rspec" coverage_report: true diff --git a/Rakefile b/Rakefile index a4f1b1d3e..2906c15ba 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,6 @@ require 'puppet-syntax/tasks/puppet-syntax' require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? -require 'puppet-lint/tasks/puppet-lint' def changelog_user return unless Rake.application.top_level_tasks.include? "changelog" diff --git a/lib/facter/package_provider.rb b/lib/facter/package_provider.rb index d993e79ef..02a1724cb 100644 --- a/lib/facter/package_provider.rb +++ b/lib/facter/package_provider.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Fact: package_provider # # Purpose: Returns the default provider Puppet will choose to manage packages @@ -15,9 +17,9 @@ # Instantiates a dummy package resource and return the provider setcode do if defined? Gem && Gem::Version.new(Facter.value(:puppetversion).split(' ')[0]) >= Gem::Version.new('3.6') - Puppet::Type.type(:package).newpackage(:name => 'dummy', :allow_virtual => 'true')[:provider].to_s + Puppet::Type.type(:package).newpackage(name: 'dummy', allow_virtual: 'true')[:provider].to_s else - Puppet::Type.type(:package).newpackage(:name => 'dummy')[:provider].to_s + Puppet::Type.type(:package).newpackage(name: 'dummy')[:provider].to_s end end end diff --git a/lib/facter/pe_version.rb b/lib/facter/pe_version.rb index 81cd1fd02..9f514316e 100644 --- a/lib/facter/pe_version.rb +++ b/lib/facter/pe_version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version # # Purpose: Return various facts about the PE state of the system @@ -38,7 +40,7 @@ # Fact: pe_major_version Facter.add('pe_major_version') do - confine :is_pe => true + confine is_pe: true setcode do pe_version = Facter.value(:pe_version) if pe_version @@ -49,7 +51,7 @@ # Fact: pe_minor_version Facter.add('pe_minor_version') do - confine :is_pe => true + confine is_pe: true setcode do pe_version = Facter.value(:pe_version) if pe_version @@ -60,7 +62,7 @@ # Fact: pe_patch_version Facter.add('pe_patch_version') do - confine :is_pe => true + confine is_pe: true setcode do pe_version = Facter.value(:pe_version) if pe_version diff --git a/lib/facter/puppet_settings.rb b/lib/facter/puppet_settings.rb index 97deaad7e..951b2eb7c 100644 --- a/lib/facter/puppet_settings.rb +++ b/lib/facter/puppet_settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # These facter facts return the value of the Puppet vardir and environment path # settings for the node running puppet or puppet agent. The intent is to # enable Puppet modules to automatically have insight into a place where they diff --git a/lib/facter/root_home.rb b/lib/facter/root_home.rb index 7544dd09e..257a18217 100644 --- a/lib/facter/root_home.rb +++ b/lib/facter/root_home.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # root_home.rb module Facter::Util::RootHome # @summary @@ -5,14 +7,14 @@ module Facter::Util::RootHome # This varies on PE supported platforms and may be # reconfigured by the end user. class << self - # determines the root home directory - def returnt_root_home - root_ent = Facter::Util::Resolution.exec('getent passwd root') - # The home directory is the sixth element in the passwd entry - # If the platform doesn't have getent, root_ent will be nil and we should - # return it straight away. - root_ent && root_ent.split(':')[5] - end + # determines the root home directory + def returnt_root_home + root_ent = Facter::Util::Resolution.exec('getent passwd root') + # The home directory is the sixth element in the passwd entry + # If the platform doesn't have getent, root_ent will be nil and we should + # return it straight away. + root_ent && root_ent.split(':')[5] + end end end @@ -21,7 +23,7 @@ def returnt_root_home end Facter.add(:root_home) do - confine :kernel => :darwin + confine kernel: :darwin setcode do str = Facter::Util::Resolution.exec('dscacheutil -q user -a name root') hash = {} @@ -34,12 +36,12 @@ def returnt_root_home end Facter.add(:root_home) do - confine :kernel => :aix + confine kernel: :aix root_home = nil setcode do str = Facter::Util::Resolution.exec('lsuser -c -a home root') - str && str.split("\n").each do |line| - next if line =~ %r{^#} + str&.split("\n")&.each do |line| + next if %r{^#}.match?(line) root_home = line.split(%r{:})[1] end root_home diff --git a/lib/facter/service_provider.rb b/lib/facter/service_provider.rb index a11792115..3d4e44a57 100644 --- a/lib/facter/service_provider.rb +++ b/lib/facter/service_provider.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Fact: service_provider # # Purpose: Returns the default provider Puppet will choose to manage services @@ -12,6 +14,6 @@ Facter.add(:service_provider) do setcode do - Puppet::Type.type(:service).newservice(:name => 'dummy')[:provider].to_s + Puppet::Type.type(:service).newservice(name: 'dummy')[:provider].to_s end end diff --git a/lib/facter/util/puppet_settings.rb b/lib/facter/util/puppet_settings.rb index d12e92c97..df2ed5963 100644 --- a/lib/facter/util/puppet_settings.rb +++ b/lib/facter/util/puppet_settings.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A method to evaluate a Facter code block if puppet is loaded. module Facter::Util::PuppetSettings # This method is intended to provide a convenient way to evaluate a diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb index 2f6b0c0ed..f71924fd9 100644 --- a/lib/puppet/functions/deprecation.rb +++ b/lib/puppet/functions/deprecation.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Function to print deprecation warnings, Logs a warning once for a given key. # # The uniqueness key - can appear once. @@ -25,7 +27,7 @@ def deprecation(key, message) end # depending on configuration setting of strict case Puppet.settings[:strict] - when :off # rubocop:disable Lint/EmptyWhen : Is required to prevent false errors + when :off # do nothing when :error raise("deprecation. #{key}. #{message}") diff --git a/lib/puppet/functions/fact.rb b/lib/puppet/functions/fact.rb index c963d1665..c450436ca 100644 --- a/lib/puppet/functions/fact.rb +++ b/lib/puppet/functions/fact.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Digs into the facts hash using dot-notation # diff --git a/lib/puppet/functions/is_a.rb b/lib/puppet/functions/is_a.rb index 0302df92d..275d21815 100644 --- a/lib/puppet/functions/is_a.rb +++ b/lib/puppet/functions/is_a.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Boolean check to determine whether a variable is of a given data type. # This is equivalent to the `=~` type checks. @@ -35,7 +37,7 @@ param 'Type', :type end - def is_a(value, type) # rubocop:disable Style/PredicateName : Used in to many other places to rename at this time, attempting to refactor caused Rubocop to crash. + def is_a(value, type) # rubocop:disable Naming/PredicateName : Used in to many other places to rename at this time, attempting to refactor caused Rubocop to crash. # See puppet's lib/puppet/pops/evaluator/evaluator_impl.rb eval_MatchExpression Puppet::Pops::Types::TypeCalculator.instance?(type, value) end diff --git a/lib/puppet/functions/is_absolute_path.rb b/lib/puppet/functions/is_absolute_path.rb index ea8383e35..b801ecb61 100644 --- a/lib/puppet/functions/is_absolute_path.rb +++ b/lib/puppet/functions/is_absolute_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_absolute_path) do diff --git a/lib/puppet/functions/is_array.rb b/lib/puppet/functions/is_array.rb index 8f17782b1..0a53e07e2 100644 --- a/lib/puppet/functions/is_array.rb +++ b/lib/puppet/functions/is_array.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_array) do diff --git a/lib/puppet/functions/is_bool.rb b/lib/puppet/functions/is_bool.rb index bc243f185..fa8170933 100644 --- a/lib/puppet/functions/is_bool.rb +++ b/lib/puppet/functions/is_bool.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_bool) do diff --git a/lib/puppet/functions/is_float.rb b/lib/puppet/functions/is_float.rb index f6ea472d5..408970b25 100644 --- a/lib/puppet/functions/is_float.rb +++ b/lib/puppet/functions/is_float.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_float) do diff --git a/lib/puppet/functions/is_ip_address.rb b/lib/puppet/functions/is_ip_address.rb index 1f2409d35..3e1e015ca 100644 --- a/lib/puppet/functions/is_ip_address.rb +++ b/lib/puppet/functions/is_ip_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_ip_address) do diff --git a/lib/puppet/functions/is_ipv4_address.rb b/lib/puppet/functions/is_ipv4_address.rb index c9d5aa8e2..8a79a16dc 100644 --- a/lib/puppet/functions/is_ipv4_address.rb +++ b/lib/puppet/functions/is_ipv4_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_ipv4_address) do diff --git a/lib/puppet/functions/is_ipv6_address.rb b/lib/puppet/functions/is_ipv6_address.rb index 02cb58d6a..7833960f6 100644 --- a/lib/puppet/functions/is_ipv6_address.rb +++ b/lib/puppet/functions/is_ipv6_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_ipv6_address) do diff --git a/lib/puppet/functions/is_numeric.rb b/lib/puppet/functions/is_numeric.rb index 1dcf576a7..06fcacc91 100644 --- a/lib/puppet/functions/is_numeric.rb +++ b/lib/puppet/functions/is_numeric.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_numeric) do diff --git a/lib/puppet/functions/is_string.rb b/lib/puppet/functions/is_string.rb index 1cbb146ff..b36796164 100644 --- a/lib/puppet/functions/is_string.rb +++ b/lib/puppet/functions/is_string.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Wrapper that calls the Puppet 3.x function of the same name. Puppet::Functions.create_function(:is_string) do diff --git a/lib/puppet/functions/length.rb b/lib/puppet/functions/length.rb index 9a163deaf..d2e356ca6 100644 --- a/lib/puppet/functions/length.rb +++ b/lib/puppet/functions/length.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # **Deprecated:** A function to eventually replace the old size() function for stdlib # diff --git a/lib/puppet/functions/merge.rb b/lib/puppet/functions/merge.rb index dd65cbc4c..d94a7936d 100644 --- a/lib/puppet/functions/merge.rb +++ b/lib/puppet/functions/merge.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Merges two or more hashes together or hashes resulting from iteration, and returns # the resulting hash. @@ -102,7 +104,7 @@ def merge_iterable3(iterable) accumulator.merge!(r) if r.is_a?(Hash) index += 1 end - rescue StopIteration # rubocop:disable Lint/HandleExceptions + rescue StopIteration end end accumulator diff --git a/lib/puppet/functions/os_version_gte.rb b/lib/puppet/functions/os_version_gte.rb index 7ab095e82..c0e004322 100644 --- a/lib/puppet/functions/os_version_gte.rb +++ b/lib/puppet/functions/os_version_gte.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Checks if the OS version is at least a certain version. # > *Note:* diff --git a/lib/puppet/functions/seeded_rand_string.rb b/lib/puppet/functions/seeded_rand_string.rb index 63cb2f83c..e9dee5cae 100644 --- a/lib/puppet/functions/seeded_rand_string.rb +++ b/lib/puppet/functions/seeded_rand_string.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Generates a consistent random string of specific length based on provided seed. # diff --git a/lib/puppet/functions/sprintf_hash.rb b/lib/puppet/functions/sprintf_hash.rb index ddf82b55b..42d27403a 100644 --- a/lib/puppet/functions/sprintf_hash.rb +++ b/lib/puppet/functions/sprintf_hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Uses sprintf with named references. # diff --git a/lib/puppet/functions/stdlib/end_with.rb b/lib/puppet/functions/stdlib/end_with.rb index fc83f70aa..6c640890c 100644 --- a/lib/puppet/functions/stdlib/end_with.rb +++ b/lib/puppet/functions/stdlib/end_with.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Returns true if str ends with one of the prefixes given. Each of the prefixes should be a String. # diff --git a/lib/puppet/functions/stdlib/extname.rb b/lib/puppet/functions/stdlib/extname.rb index 120b46b22..7de9d50a6 100644 --- a/lib/puppet/functions/stdlib/extname.rb +++ b/lib/puppet/functions/stdlib/extname.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Returns the Extension (the Portion of Filename in Path starting from the # last Period). diff --git a/lib/puppet/functions/stdlib/ip_in_range.rb b/lib/puppet/functions/stdlib/ip_in_range.rb index 46fc44548..eed5c0b2e 100644 --- a/lib/puppet/functions/stdlib/ip_in_range.rb +++ b/lib/puppet/functions/stdlib/ip_in_range.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Returns true if the ipaddress is within the given CIDRs # diff --git a/lib/puppet/functions/stdlib/start_with.rb b/lib/puppet/functions/stdlib/start_with.rb index 28f01bbd5..5203baf4f 100644 --- a/lib/puppet/functions/stdlib/start_with.rb +++ b/lib/puppet/functions/stdlib/start_with.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Returns true if str starts with one of the prefixes given. Each of the prefixes should be a String. # diff --git a/lib/puppet/functions/to_json.rb b/lib/puppet/functions/to_json.rb index 20d39e76f..7ff605d21 100644 --- a/lib/puppet/functions/to_json.rb +++ b/lib/puppet/functions/to_json.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' # @summary # Convert a data structure and output to JSON diff --git a/lib/puppet/functions/to_json_pretty.rb b/lib/puppet/functions/to_json_pretty.rb index 8a63f697d..7d46fc2dc 100644 --- a/lib/puppet/functions/to_json_pretty.rb +++ b/lib/puppet/functions/to_json_pretty.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' # @summary diff --git a/lib/puppet/functions/to_yaml.rb b/lib/puppet/functions/to_yaml.rb index fe8ec5036..781ea3334 100644 --- a/lib/puppet/functions/to_yaml.rb +++ b/lib/puppet/functions/to_yaml.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'yaml' # @summary # Convert a data structure and output it as YAML diff --git a/lib/puppet/functions/type_of.rb b/lib/puppet/functions/type_of.rb index e74565932..a05eeeb8d 100644 --- a/lib/puppet/functions/type_of.rb +++ b/lib/puppet/functions/type_of.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Returns the type of the passed value. # diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb index ed7f07004..9121cbbb6 100644 --- a/lib/puppet/functions/validate_absolute_path.rb +++ b/lib/puppet/functions/validate_absolute_path.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the string represents an absolute path in the filesystem. Puppet::Functions.create_function(:validate_absolute_path) do diff --git a/lib/puppet/functions/validate_array.rb b/lib/puppet/functions/validate_array.rb index 217df762f..4287aa8c5 100644 --- a/lib/puppet/functions/validate_array.rb +++ b/lib/puppet/functions/validate_array.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents an array. Puppet::Functions.create_function(:validate_array) do diff --git a/lib/puppet/functions/validate_bool.rb b/lib/puppet/functions/validate_bool.rb index 85892ddad..a080a4112 100644 --- a/lib/puppet/functions/validate_bool.rb +++ b/lib/puppet/functions/validate_bool.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents a boolean. Puppet::Functions.create_function(:validate_bool) do diff --git a/lib/puppet/functions/validate_hash.rb b/lib/puppet/functions/validate_hash.rb index 5efa25fe7..77370e20b 100644 --- a/lib/puppet/functions/validate_hash.rb +++ b/lib/puppet/functions/validate_hash.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents a hash. Puppet::Functions.create_function(:validate_hash) do diff --git a/lib/puppet/functions/validate_integer.rb b/lib/puppet/functions/validate_integer.rb index 7de789ece..ae8e90f3f 100644 --- a/lib/puppet/functions/validate_integer.rb +++ b/lib/puppet/functions/validate_integer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents an integer. Puppet::Functions.create_function(:validate_integer) do diff --git a/lib/puppet/functions/validate_ip_address.rb b/lib/puppet/functions/validate_ip_address.rb index 233f083d4..706405262 100644 --- a/lib/puppet/functions/validate_ip_address.rb +++ b/lib/puppet/functions/validate_ip_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents an ip_address. Puppet::Functions.create_function(:validate_ip_address) do diff --git a/lib/puppet/functions/validate_ipv4_address.rb b/lib/puppet/functions/validate_ipv4_address.rb index 799f60894..090292b10 100644 --- a/lib/puppet/functions/validate_ipv4_address.rb +++ b/lib/puppet/functions/validate_ipv4_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents an ipv4_address. Puppet::Functions.create_function(:validate_ipv4_address) do diff --git a/lib/puppet/functions/validate_ipv6_address.rb b/lib/puppet/functions/validate_ipv6_address.rb index b51464254..540842b48 100644 --- a/lib/puppet/functions/validate_ipv6_address.rb +++ b/lib/puppet/functions/validate_ipv6_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents an ipv6_address. Puppet::Functions.create_function(:validate_ipv6_address) do diff --git a/lib/puppet/functions/validate_legacy.rb b/lib/puppet/functions/validate_legacy.rb index 1e1621924..44335fb6f 100644 --- a/lib/puppet/functions/validate_legacy.rb +++ b/lib/puppet/functions/validate_legacy.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate a value against both the target_type (new) and the previous_validation function (old). Puppet::Functions.create_function(:validate_legacy) do diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb index f98fa7463..c9daa75bc 100644 --- a/lib/puppet/functions/validate_numeric.rb +++ b/lib/puppet/functions/validate_numeric.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate the passed value represents a numeric value. Puppet::Functions.create_function(:validate_numeric) do diff --git a/lib/puppet/functions/validate_re.rb b/lib/puppet/functions/validate_re.rb index d1695df56..eaea9b6d8 100644 --- a/lib/puppet/functions/validate_re.rb +++ b/lib/puppet/functions/validate_re.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Perform validation of a string against one or more regular # expressions. diff --git a/lib/puppet/functions/validate_slength.rb b/lib/puppet/functions/validate_slength.rb index aa4143ba9..f34e705b9 100644 --- a/lib/puppet/functions/validate_slength.rb +++ b/lib/puppet/functions/validate_slength.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Validate that a passed string has length less/equal with the passed value Puppet::Functions.create_function(:validate_slength) do # @param scope diff --git a/lib/puppet/functions/validate_string.rb b/lib/puppet/functions/validate_string.rb index 50b1dafbc..a946da94a 100644 --- a/lib/puppet/functions/validate_string.rb +++ b/lib/puppet/functions/validate_string.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # @summary # Validate that all passed values are string data structures. Puppet::Functions.create_function(:validate_string) do diff --git a/lib/puppet/parser/functions/abs.rb b/lib/puppet/parser/functions/abs.rb index 5625b984c..822bc5dbb 100644 --- a/lib/puppet/parser/functions/abs.rb +++ b/lib/puppet/parser/functions/abs.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # abs.rb # module Puppet::Parser::Functions - newfunction(:abs, :type => :rvalue, :doc => <<-DOC + newfunction(:abs, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns the absolute value of a number @@ -16,17 +18,16 @@ module Puppet::Parser::Functions @return The absolute value of the given number if it was an Integer DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "abs(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] # Numbers in Puppet are often string-encoded which is troublesome ... if value.is_a?(String) - if value =~ %r{^-?(?:\d+)(?:\.\d+){1}$} + if %r{^-?(?:\d+)(?:\.\d+){1}$}.match?(value) value = value.to_f - elsif value =~ %r{^-?\d+$} + elsif %r{^-?\d+$}.match?(value) value = value.to_i else raise(Puppet::ParseError, 'abs(): Requires float or integer to work with') diff --git a/lib/puppet/parser/functions/any2array.rb b/lib/puppet/parser/functions/any2array.rb index b45e5b50b..107c11dce 100644 --- a/lib/puppet/parser/functions/any2array.rb +++ b/lib/puppet/parser/functions/any2array.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # any2array.rb # module Puppet::Parser::Functions - newfunction(:any2array, :type => :rvalue, :doc => <<-DOC + newfunction(:any2array, type: :rvalue, doc: <<-DOC @summary This converts any object to an array containing that object. @@ -33,8 +35,7 @@ module Puppet::Parser::Functions @return [Array] The new array containing the given object DOC - ) do |arguments| - + ) do |arguments| if arguments.empty? return [] end diff --git a/lib/puppet/parser/functions/any2bool.rb b/lib/puppet/parser/functions/any2bool.rb index c4b20d674..0215d19bc 100644 --- a/lib/puppet/parser/functions/any2bool.rb +++ b/lib/puppet/parser/functions/any2bool.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # any2bool.rb # module Puppet::Parser::Functions - newfunction(:any2bool, :type => :rvalue, :doc => <<-DOC + newfunction(:any2bool, type: :rvalue, doc: <<-DOC @summary Converts 'anything' to a boolean. @@ -19,8 +21,7 @@ module Puppet::Parser::Functions @return [Boolean] The boolean value of the object that was given DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "any2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? # If argument is already Boolean, return it diff --git a/lib/puppet/parser/functions/assert_private.rb b/lib/puppet/parser/functions/assert_private.rb index 4f1a5e26c..0e64bd67a 100644 --- a/lib/puppet/parser/functions/assert_private.rb +++ b/lib/puppet/parser/functions/assert_private.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # assert_private.rb # module Puppet::Parser::Functions - newfunction(:assert_private, :doc => <<-DOC + newfunction(:assert_private, doc: <<-DOC @summary Sets the current class or definition as private. @@ -11,14 +13,13 @@ module Puppet::Parser::Functions Calling the class or definition from outside the current module will fail. DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, "assert_private(): Wrong number of arguments given (#{args.size}}) for 0 or 1)") if args.size > 1 scope = self if scope.lookupvar('module_name') != scope.lookupvar('caller_module_name') message = nil - if args[0] && args[0].is_a?(String) + if args[0]&.is_a?(String) message = args[0] else manifest_name = scope.source.name diff --git a/lib/puppet/parser/functions/base64.rb b/lib/puppet/parser/functions/base64.rb index 45e1fdbc5..1fe2751b2 100644 --- a/lib/puppet/parser/functions/base64.rb +++ b/lib/puppet/parser/functions/base64.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. module Puppet::Parser::Functions - newfunction(:base64, :type => :rvalue, :doc => <<-DOC) do |args| + newfunction(:base64, type: :rvalue, doc: <<-DOC) do |args| @summary Base64 encode or decode a string based on the command and the string submitted diff --git a/lib/puppet/parser/functions/basename.rb b/lib/puppet/parser/functions/basename.rb index e247e566a..176182122 100644 --- a/lib/puppet/parser/functions/basename.rb +++ b/lib/puppet/parser/functions/basename.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true + # # basename.rb # module Puppet::Parser::Functions - newfunction(:basename, :type => :rvalue, :doc => <<-DOC + newfunction(:basename, type: :rvalue, doc: <<-DOC @summary Strips directory (and optional suffix) from a filename @return [String] The stripped filename DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, 'basename(): No arguments given') if arguments.empty? raise(Puppet::ParseError, "basename(): Too many arguments given (#{arguments.size})") if arguments.size > 2 raise(Puppet::ParseError, 'basename(): Requires string as first argument') unless arguments[0].is_a?(String) diff --git a/lib/puppet/parser/functions/bool2num.rb b/lib/puppet/parser/functions/bool2num.rb index bafe0bd43..a55e5cc3f 100644 --- a/lib/puppet/parser/functions/bool2num.rb +++ b/lib/puppet/parser/functions/bool2num.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # bool2num.rb # module Puppet::Parser::Functions - newfunction(:bool2num, :type => :rvalue, :doc => <<-DOC + newfunction(:bool2num, type: :rvalue, doc: <<-DOC @summary Converts a boolean to a number. @@ -27,8 +29,7 @@ module Puppet::Parser::Functions @return [Integer] The converted value as a number DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "bool2num(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = function_str2bool([arguments[0]]) diff --git a/lib/puppet/parser/functions/bool2str.rb b/lib/puppet/parser/functions/bool2str.rb index f55fcd835..03d53d4f2 100644 --- a/lib/puppet/parser/functions/bool2str.rb +++ b/lib/puppet/parser/functions/bool2str.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # bool2str.rb # module Puppet::Parser::Functions - newfunction(:bool2str, :type => :rvalue, :doc => <<-DOC + newfunction(:bool2str, type: :rvalue, doc: <<-DOC @summary Converts a boolean to a string using optionally supplied arguments. @@ -36,8 +38,7 @@ module Puppet::Parser::Functions notice(String(true, '%y')) # Notices 'no' ``` DOC - ) do |arguments| - + ) do |arguments| unless arguments.size == 1 || arguments.size == 3 raise(Puppet::ParseError, "bool2str(): Wrong number of arguments given (#{arguments.size} for 3)") end diff --git a/lib/puppet/parser/functions/camelcase.rb b/lib/puppet/parser/functions/camelcase.rb index ad1068b3f..4e6330cbd 100644 --- a/lib/puppet/parser/functions/camelcase.rb +++ b/lib/puppet/parser/functions/camelcase.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # camelcase.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:camelcase, :type => :rvalue, :doc => <<-DOC + newfunction(:camelcase, type: :rvalue, doc: <<-DOC @summary **Deprecated** Converts the case of a string or all strings in an array to camel case. @@ -15,8 +17,7 @@ module Puppet::Parser::Functions @return [String] The converted String, if it was a String that was given @return [Array[String]] The converted Array, if it was a Array that was given DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "camelcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/capitalize.rb b/lib/puppet/parser/functions/capitalize.rb index ffc4d1386..fef44937b 100644 --- a/lib/puppet/parser/functions/capitalize.rb +++ b/lib/puppet/parser/functions/capitalize.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # capitalize.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:capitalize, :type => :rvalue, :doc => <<-DOC + newfunction(:capitalize, type: :rvalue, doc: <<-DOC @summary **Deprecated** Capitalizes the first letter of a string or array of strings. @@ -17,8 +19,7 @@ module Puppet::Parser::Functions @return [String] The converted String, if it was a String that was given @return [Array[String]] The converted Array, if it was a Array that was given DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "capitalize(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/ceiling.rb b/lib/puppet/parser/functions/ceiling.rb index ea50e880c..b8012356d 100644 --- a/lib/puppet/parser/functions/ceiling.rb +++ b/lib/puppet/parser/functions/ceiling.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # ceiling.rb # module Puppet::Parser::Functions - newfunction(:ceiling, :type => :rvalue, :doc => <<-DOC + newfunction(:ceiling, type: :rvalue, doc: <<-DOC @summary **Deprecated** Returns the smallest integer greater or equal to the argument. Takes a single numeric value as an argument. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions @return [Integer] The rounded value DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "ceiling(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 begin diff --git a/lib/puppet/parser/functions/chomp.rb b/lib/puppet/parser/functions/chomp.rb index c917d580a..84aeaf1e9 100644 --- a/lib/puppet/parser/functions/chomp.rb +++ b/lib/puppet/parser/functions/chomp.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # chomp.rb # module Puppet::Parser::Functions - newfunction(:chomp, :type => :rvalue, :doc => <<-DOC + newfunction(:chomp, type: :rvalue, doc: <<-DOC @summary **Deprecated** Removes the record separator from the end of a string or an array of strings. @@ -16,8 +18,7 @@ module Puppet::Parser::Functions @return [String] The converted String, if it was a String that was given @return [Array[String]] The converted Array, if it was a Array that was given DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "chomp(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/chop.rb b/lib/puppet/parser/functions/chop.rb index 69b5f3ffc..2e4b0543d 100644 --- a/lib/puppet/parser/functions/chop.rb +++ b/lib/puppet/parser/functions/chop.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # chop.rb # module Puppet::Parser::Functions - newfunction(:chop, :type => :rvalue, :doc => <<-DOC + newfunction(:chop, type: :rvalue, doc: <<-DOC @summary **Deprecated** Returns a new string with the last character removed. @@ -16,8 +18,7 @@ module Puppet::Parser::Functions @return [String] The given String, sans the last character. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "chop(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/clamp.rb b/lib/puppet/parser/functions/clamp.rb index 1b6e2d292..c05688498 100644 --- a/lib/puppet/parser/functions/clamp.rb +++ b/lib/puppet/parser/functions/clamp.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # clamp.rb # module Puppet::Parser::Functions - newfunction(:clamp, :type => :rvalue, :arity => -2, :doc => <<-DOC + newfunction(:clamp, type: :rvalue, arity: -2, doc: <<-DOC @summary Keeps value within the range [Min, X, Max] by sort based on integer value (parameter order doesn't matter). @@ -22,8 +24,7 @@ module Puppet::Parser::Functions @return [Array[Integer]] The sorted Array DOC - ) do |args| - + ) do |args| args.flatten! raise(Puppet::ParseError, 'clamp(): Wrong number of arguments, need three to clamp') if args.size != 3 @@ -32,7 +33,7 @@ module Puppet::Parser::Functions args.each do |value| case [value.class] when [String] - raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless value =~ %r{^\d+$} + raise(Puppet::ParseError, "clamp(): Required explicit numeric (#{value}:String)") unless %r{^\d+$}.match?(value) when [Hash] raise(Puppet::ParseError, "clamp(): The Hash type is not allowed (#{value})") end diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index d3c2e2433..2ee1c2ab4 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # concat.rb # module Puppet::Parser::Functions - newfunction(:concat, :type => :rvalue, :doc => <<-DOC + newfunction(:concat, type: :rvalue, doc: <<-DOC @summary Appends the contents of multiple arrays into array 1. @@ -21,8 +23,7 @@ module Puppet::Parser::Functions @return [Array] The single concatenated array DOC - ) do |arguments| - + ) do |arguments| # Check that more than 2 arguments have been given ... raise(Puppet::ParseError, "concat(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2 diff --git a/lib/puppet/parser/functions/convert_base.rb b/lib/puppet/parser/functions/convert_base.rb index 3e4c89fa8..d6554192d 100644 --- a/lib/puppet/parser/functions/convert_base.rb +++ b/lib/puppet/parser/functions/convert_base.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # convert_base.rb # module Puppet::Parser::Functions - newfunction(:convert_base, :type => :rvalue, :arity => 2, :doc => <<-'DOC') do |args| + newfunction(:convert_base, type: :rvalue, arity: 2, doc: <<-'DOC') do |args| @summary Converts a given integer or base 10 string representing an integer to a specified base, as a string. @@ -31,11 +33,11 @@ module Puppet::Parser::Functions raise Puppet::ParseError, 'convert_base(): Second argument must be either a string or an integer' unless args[1].is_a?(Integer) || args[1].is_a?(String) if args[0].is_a?(String) - raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless args[0] =~ %r{^[0-9]+$} + raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless %r{^[0-9]+$}.match?(args[0]) end if args[1].is_a?(String) - raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless args[1] =~ %r{^[0-9]+$} + raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless %r{^[0-9]+$}.match?(args[1]) end number_to_convert = args[0] diff --git a/lib/puppet/parser/functions/count.rb b/lib/puppet/parser/functions/count.rb index c302aa196..b2bd89a3e 100644 --- a/lib/puppet/parser/functions/count.rb +++ b/lib/puppet/parser/functions/count.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # count.rb # module Puppet::Parser::Functions - newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-DOC + newfunction(:count, type: :rvalue, arity: -2, doc: <<-DOC @summary Counts the number of elements in array. @@ -24,8 +26,7 @@ module Puppet::Parser::Functions @return [Integer] The amount of elements counted within the array DOC - ) do |args| - + ) do |args| if args.size > 2 raise(ArgumentError, "count(): Wrong number of arguments given #{args.size} for 1 or 2.") end diff --git a/lib/puppet/parser/functions/deep_merge.rb b/lib/puppet/parser/functions/deep_merge.rb index bf62576cf..bd796ec63 100644 --- a/lib/puppet/parser/functions/deep_merge.rb +++ b/lib/puppet/parser/functions/deep_merge.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # deep_merge.rb # module Puppet::Parser::Functions - newfunction(:deep_merge, :type => :rvalue, :doc => <<-'DOC') do |args| + newfunction(:deep_merge, type: :rvalue, doc: <<-'DOC') do |args| @summary Recursively merges two or more hashes together and returns the resulting hash. diff --git a/lib/puppet/parser/functions/defined_with_params.rb b/lib/puppet/parser/functions/defined_with_params.rb index daac56799..74fc67a6e 100644 --- a/lib/puppet/parser/functions/defined_with_params.rb +++ b/lib/puppet/parser/functions/defined_with_params.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # Test whether a given class or definition is defined require 'puppet/parser/functions' Puppet::Parser::Functions.newfunction(:defined_with_params, - :type => :rvalue, - :doc => <<-DOC + type: :rvalue, + doc: <<-DOC, @summary Takes a resource reference and an optional hash of attributes. diff --git a/lib/puppet/parser/functions/delete.rb b/lib/puppet/parser/functions/delete.rb index bf614f773..e66b3c4c8 100644 --- a/lib/puppet/parser/functions/delete.rb +++ b/lib/puppet/parser/functions/delete.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # delete.rb # module Puppet::Parser::Functions - newfunction(:delete, :type => :rvalue, :doc => <<-DOC + newfunction(:delete, type: :rvalue, doc: <<-DOC @summary Deletes all instances of a given element from an array, substring from a string, or key from a hash. @@ -45,8 +47,7 @@ module Puppet::Parser::Functions @return [Hash] The filtered Hash, if one was given. @return [Array] The filtered Array, if one was given. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "delete(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2 collection = arguments[0].dup diff --git a/lib/puppet/parser/functions/delete_at.rb b/lib/puppet/parser/functions/delete_at.rb index 992d7d8d6..12cba08d2 100644 --- a/lib/puppet/parser/functions/delete_at.rb +++ b/lib/puppet/parser/functions/delete_at.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # delete_at.rb # module Puppet::Parser::Functions - newfunction(:delete_at, :type => :rvalue, :doc => <<-DOC) do |arguments| + newfunction(:delete_at, type: :rvalue, doc: <<-DOC) do |arguments| @summary Deletes a determined indexed value from an array. diff --git a/lib/puppet/parser/functions/delete_regex.rb b/lib/puppet/parser/functions/delete_regex.rb index 36451919d..0f1417751 100644 --- a/lib/puppet/parser/functions/delete_regex.rb +++ b/lib/puppet/parser/functions/delete_regex.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # delete_regex.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:delete_regex, :type => :rvalue, :doc => <<-DOC + newfunction(:delete_regex, type: :rvalue, doc: <<-DOC @summary Deletes all instances of a given element that match a regular expression from an array or key from a hash. @@ -32,8 +34,7 @@ module Puppet::Parser::Functions @return [Array] The given array now missing all targeted values. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "delete_regex(): Wrong number of arguments given #{arguments.size} for 2") unless arguments.size == 2 collection = arguments[0].dup diff --git a/lib/puppet/parser/functions/delete_undef_values.rb b/lib/puppet/parser/functions/delete_undef_values.rb index b00f5e4d4..e537e9ae8 100644 --- a/lib/puppet/parser/functions/delete_undef_values.rb +++ b/lib/puppet/parser/functions/delete_undef_values.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # delete_undef_values.rb # module Puppet::Parser::Functions - newfunction(:delete_undef_values, :type => :rvalue, :doc => <<-DOC + newfunction(:delete_undef_values, type: :rvalue, doc: <<-DOC @summary Returns a copy of input hash or array with all undefs deleted. @@ -23,8 +25,7 @@ module Puppet::Parser::Functions @return [Array] The given array now issing of undefined values. DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, "delete_undef_values(): Wrong number of arguments given (#{args.size})") if args.empty? unless args[0].is_a?(Array) || args[0].is_a?(Hash) diff --git a/lib/puppet/parser/functions/delete_values.rb b/lib/puppet/parser/functions/delete_values.rb index f1625228a..3aa8be724 100644 --- a/lib/puppet/parser/functions/delete_values.rb +++ b/lib/puppet/parser/functions/delete_values.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # delete_values.rb # module Puppet::Parser::Functions - newfunction(:delete_values, :type => :rvalue, :doc => <<-DOC + newfunction(:delete_values, type: :rvalue, doc: <<-DOC @summary Deletes all instances of a given value from a hash. @@ -19,8 +21,7 @@ module Puppet::Parser::Functions @return [Hash] The given hash now missing all instances of the targeted value DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "delete_values(): Wrong number of arguments given (#{arguments.size} of 2)") if arguments.size != 2 hash, item = arguments diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb index 2a39cc379..1633723a5 100644 --- a/lib/puppet/parser/functions/deprecation.rb +++ b/lib/puppet/parser/functions/deprecation.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # deprecation.rb # module Puppet::Parser::Functions - newfunction(:deprecation, :doc => <<-DOC + newfunction(:deprecation, doc: <<-DOC @summary Function to print deprecation warnings (this is the 3.X version of it). @@ -12,8 +14,7 @@ module Puppet::Parser::Functions @return [String] return deprecation warnings DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "deprecation: Wrong number of arguments given (#{arguments.size} for 2)") unless arguments.size == 2 key = arguments[0] diff --git a/lib/puppet/parser/functions/difference.rb b/lib/puppet/parser/functions/difference.rb index 49e867371..3c4461028 100644 --- a/lib/puppet/parser/functions/difference.rb +++ b/lib/puppet/parser/functions/difference.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # difference.rb # module Puppet::Parser::Functions - newfunction(:difference, :type => :rvalue, :doc => <<-DOC + newfunction(:difference, type: :rvalue, doc: <<-DOC @summary This function returns the difference between two arrays. @@ -23,8 +25,7 @@ module Puppet::Parser::Functions The difference between the two given arrays DOC - ) do |arguments| - + ) do |arguments| # Two arguments are required raise(Puppet::ParseError, "difference(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2 diff --git a/lib/puppet/parser/functions/dig.rb b/lib/puppet/parser/functions/dig.rb index b6addb40f..81b58e1b9 100644 --- a/lib/puppet/parser/functions/dig.rb +++ b/lib/puppet/parser/functions/dig.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # dig.rb # module Puppet::Parser::Functions - newfunction(:dig, :type => :rvalue, :doc => <<-DOC + newfunction(:dig, type: :rvalue, doc: <<-DOC @summary **DEPRECATED** Retrieves a value within multiple layers of hashes and arrays via an array of keys containing a path. @@ -47,7 +49,7 @@ module Puppet::Parser::Functions [`dig`](https://puppet.com/docs/puppet/latest/function.html#dig) function as of Puppet 4.5.0. Use [`dig44()`](#dig44) for backwards compatibility or use the new version. DOC - ) do |arguments| + ) do |arguments| warning('dig() DEPRECATED: This function has been replaced in Puppet 4.5.0, please use dig44() for backwards compatibility or use the new version.') unless Puppet::Parser::Functions.autoloader.loaded?(:dig44) Puppet::Parser::Functions.autoloader.load(:dig44) diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb index ff1d9df65..7b58c226f 100644 --- a/lib/puppet/parser/functions/dig44.rb +++ b/lib/puppet/parser/functions/dig44.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + # # dig44.rb # module Puppet::Parser::Functions newfunction( :dig44, - :type => :rvalue, - :arity => -2, - :doc => <<-DOC + type: :rvalue, + arity: -2, + doc: <<-DOC, @summary **DEPRECATED**: Looks up into a complex structure of arrays and hashes and returns a value or the default value if nothing was found. diff --git a/lib/puppet/parser/functions/dirname.rb b/lib/puppet/parser/functions/dirname.rb index ae579e20e..4a07a299d 100644 --- a/lib/puppet/parser/functions/dirname.rb +++ b/lib/puppet/parser/functions/dirname.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true + # # dirname.rb # module Puppet::Parser::Functions - newfunction(:dirname, :type => :rvalue, :doc => <<-DOC + newfunction(:dirname, type: :rvalue, doc: <<-DOC @summary Returns the dirname of a path. @return [String] the given path's dirname DOC - ) do |arguments| - + ) do |arguments| if arguments.empty? raise(Puppet::ParseError, 'dirname(): No arguments given') end diff --git a/lib/puppet/parser/functions/dos2unix.rb b/lib/puppet/parser/functions/dos2unix.rb index e741aa8dd..0e2b2b6a8 100644 --- a/lib/puppet/parser/functions/dos2unix.rb +++ b/lib/puppet/parser/functions/dos2unix.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Custom Puppet function to convert dos to unix format module Puppet::Parser::Functions - newfunction(:dos2unix, :type => :rvalue, :arity => 1, :doc => <<-DOC + newfunction(:dos2unix, type: :rvalue, arity: 1, doc: <<-DOC @summary Returns the Unix version of the given string. @@ -8,8 +10,7 @@ module Puppet::Parser::Functions @return The retrieved version DOC - ) do |arguments| - + ) do |arguments| unless arguments[0].is_a?(String) raise(Puppet::ParseError, 'dos2unix(): Requires string as argument') end diff --git a/lib/puppet/parser/functions/downcase.rb b/lib/puppet/parser/functions/downcase.rb index a0717ff61..32e338c8a 100644 --- a/lib/puppet/parser/functions/downcase.rb +++ b/lib/puppet/parser/functions/downcase.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # downcase.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:downcase, :type => :rvalue, :doc => <<-DOC + newfunction(:downcase, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Converts the case of a string or all strings in an array to lower case. @@ -16,8 +18,7 @@ module Puppet::Parser::Functions @return [String] The converted String, if it was a String that was given @return [Array[String]] The converted Array, if it was a Array that was given DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "downcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb index 907ecb196..ee1dabca2 100644 --- a/lib/puppet/parser/functions/empty.rb +++ b/lib/puppet/parser/functions/empty.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # empty.rb # module Puppet::Parser::Functions - newfunction(:empty, :type => :rvalue, :doc => <<-DOC + newfunction(:empty, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable is empty. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions > *Note*: **Deprecated** from Puppet 5.5.0, the built-in [`empty`](https://puppet.com/docs/puppet/6.4/function.html#empty) function will be used instead. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "empty(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/enclose_ipv6.rb b/lib/puppet/parser/functions/enclose_ipv6.rb index b55f76b30..cfa174b1c 100644 --- a/lib/puppet/parser/functions/enclose_ipv6.rb +++ b/lib/puppet/parser/functions/enclose_ipv6.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # enclose_ipv6.rb # module Puppet::Parser::Functions - newfunction(:enclose_ipv6, :type => :rvalue, :doc => <<-DOC + newfunction(:enclose_ipv6, type: :rvalue, doc: <<-DOC @summary Takes an array of ip addresses and encloses the ipv6 addresses with square brackets. @@ -10,8 +12,7 @@ module Puppet::Parser::Functions encloses the ipv6 addresses with square brackets. DOC - ) do |arguments| - + ) do |arguments| require 'ipaddr' rescuable_exceptions = [ArgumentError] diff --git a/lib/puppet/parser/functions/ensure_packages.rb b/lib/puppet/parser/functions/ensure_packages.rb index f255c036e..3cd2b2014 100644 --- a/lib/puppet/parser/functions/ensure_packages.rb +++ b/lib/puppet/parser/functions/ensure_packages.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # ensure_packages.rb # module Puppet::Parser::Functions - newfunction(:ensure_packages, :type => :statement, :doc => <<-DOC + newfunction(:ensure_packages, type: :statement, doc: <<-DOC @summary Takes a list of packages and only installs them if they don't already exist. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions @return install the passed packages DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments given (#{arguments.size} for 1 or 2)") if arguments.size > 2 || arguments.empty? raise(Puppet::ParseError, 'ensure_packages(): Requires second argument to be a Hash') if arguments.size == 2 && !arguments[1].is_a?(Hash) diff --git a/lib/puppet/parser/functions/ensure_resource.rb b/lib/puppet/parser/functions/ensure_resource.rb index e4fa771f2..e606360c8 100644 --- a/lib/puppet/parser/functions/ensure_resource.rb +++ b/lib/puppet/parser/functions/ensure_resource.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # Test whether a given class or definition is defined require 'puppet/parser/functions' Puppet::Parser::Functions.newfunction(:ensure_resource, - :type => :statement, - :doc => <<-DOC + type: :statement, + doc: <<-DOC, @summary Takes a resource type, title, and a list of attributes that describe a resource. diff --git a/lib/puppet/parser/functions/ensure_resources.rb b/lib/puppet/parser/functions/ensure_resources.rb index c7032caa2..ed82b2338 100644 --- a/lib/puppet/parser/functions/ensure_resources.rb +++ b/lib/puppet/parser/functions/ensure_resources.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'puppet/parser/functions' Puppet::Parser::Functions.newfunction(:ensure_resources, - :type => :statement, - :doc => <<-DOC + type: :statement, + doc: <<-DOC, @summary Takes a resource type, title (only hash), and a list of attributes that describe a resource. diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb index 7344201fd..a544d33fd 100644 --- a/lib/puppet/parser/functions/flatten.rb +++ b/lib/puppet/parser/functions/flatten.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # flatten.rb # module Puppet::Parser::Functions - newfunction(:flatten, :type => :rvalue, :doc => <<-DOC + newfunction(:flatten, type: :rvalue, doc: <<-DOC @summary This function flattens any deeply nested arrays and returns a single flat array as a result. @@ -17,8 +19,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 5.5.0, this function has been replaced with a built-in [`flatten`](https://puppet.com/docs/puppet/latest/function.html#flatten) function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "flatten(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 array = arguments[0] diff --git a/lib/puppet/parser/functions/floor.rb b/lib/puppet/parser/functions/floor.rb index 3a6f3c805..1d59963ad 100644 --- a/lib/puppet/parser/functions/floor.rb +++ b/lib/puppet/parser/functions/floor.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # floor.rb # module Puppet::Parser::Functions - newfunction(:floor, :type => :rvalue, :doc => <<-DOC + newfunction(:floor, type: :rvalue, doc: <<-DOC @summary Returns the largest integer less or equal to the argument. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a built-in [`floor`](https://puppet.com/docs/puppet/latest/function.html#floor) function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "floor(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 begin diff --git a/lib/puppet/parser/functions/fqdn_rand_string.rb b/lib/puppet/parser/functions/fqdn_rand_string.rb index 9bfba73d6..e9636c24f 100644 --- a/lib/puppet/parser/functions/fqdn_rand_string.rb +++ b/lib/puppet/parser/functions/fqdn_rand_string.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + Puppet::Parser::Functions.newfunction( :fqdn_rand_string, - :arity => -2, - :type => :rvalue, - :doc => <<-DOC + arity: -2, + type: :rvalue, + doc: <<-DOC, @summary Generates a random alphanumeric string. Combining the `$fqdn` fact and an optional seed for repeatable randomness. @@ -36,7 +38,7 @@ rand_string = '' for current in 1..length # rubocop:disable Style/For : An each loop would not work correctly in this circumstance - rand_string << charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i] + rand_string += charset[function_fqdn_rand([charset.size, (args + [current.to_s]).join(':')]).to_i] end rand_string diff --git a/lib/puppet/parser/functions/fqdn_rotate.rb b/lib/puppet/parser/functions/fqdn_rotate.rb index c86ea6829..603c57ca6 100644 --- a/lib/puppet/parser/functions/fqdn_rotate.rb +++ b/lib/puppet/parser/functions/fqdn_rotate.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # # fqdn_rotate.rb # Puppet::Parser::Functions.newfunction( :fqdn_rotate, - :type => :rvalue, - :doc => <<-DOC + type: :rvalue, + doc: <<-DOC, @summary Rotates an array or string a random number of times, combining the `$fqdn` fact and an optional seed for repeatable randomness. @@ -18,7 +20,6 @@ fqdn_rotate([1, 2, 3], 'custom seed') DOC ) do |args| - raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments given (#{args.size} for 1)") if args.empty? value = args.shift diff --git a/lib/puppet/parser/functions/fqdn_uuid.rb b/lib/puppet/parser/functions/fqdn_uuid.rb index e325fe732..b3141c8f5 100644 --- a/lib/puppet/parser/functions/fqdn_uuid.rb +++ b/lib/puppet/parser/functions/fqdn_uuid.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'digest/sha1' # # fqdn_uuid.rb # module Puppet::Parser::Functions - newfunction(:fqdn_uuid, :type => :rvalue, :doc => <<-DOC) do |args| + newfunction(:fqdn_uuid, type: :rvalue, doc: <<-DOC) do |args| @summary Returns a [RFC 4122](https://tools.ietf.org/html/rfc4122) valid version 5 UUID based on an FQDN string under the DNS namespace diff --git a/lib/puppet/parser/functions/get_module_path.rb b/lib/puppet/parser/functions/get_module_path.rb index ac787c652..3595d5377 100644 --- a/lib/puppet/parser/functions/get_module_path.rb +++ b/lib/puppet/parser/functions/get_module_path.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # get_module_path.rb # module Puppet::Parser::Functions - newfunction(:get_module_path, :type => :rvalue, :doc => <<-DOC + newfunction(:get_module_path, type: :rvalue, doc: <<-DOC @summary Returns the absolute path of the specified module for the current environment. @@ -20,7 +22,7 @@ module Puppet::Parser::Functions function in Puppet does the same thing and will return the path to the first found module if given multiple values or an array. DOC - ) do |args| + ) do |args| raise(Puppet::ParseError, 'get_module_path(): Wrong number of arguments, expects one') unless args.size == 1 module_path = Puppet::Module.find(args[0], compiler.environment.to_s) raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}") unless module_path diff --git a/lib/puppet/parser/functions/getparam.rb b/lib/puppet/parser/functions/getparam.rb index 59ef7691a..18b7b51e1 100644 --- a/lib/puppet/parser/functions/getparam.rb +++ b/lib/puppet/parser/functions/getparam.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # Test whether a given class or definition is defined require 'puppet/parser/functions' Puppet::Parser::Functions.newfunction(:getparam, - :type => :rvalue, - :doc => <<-'DOC' + type: :rvalue, + doc: <<-'DOC', @summary Returns the value of a resource's parameter. @@ -46,7 +48,7 @@ ) do |vals| reference, param = vals raise(ArgumentError, 'Must specify a reference') unless reference - raise(ArgumentError, 'Must specify name of a parameter') unless param && param.instance_of?(String) + raise(ArgumentError, 'Must specify name of a parameter') unless param&.instance_of?(String) return '' if param.empty? diff --git a/lib/puppet/parser/functions/getvar.rb b/lib/puppet/parser/functions/getvar.rb index 41d3c4f41..4ecd8324e 100644 --- a/lib/puppet/parser/functions/getvar.rb +++ b/lib/puppet/parser/functions/getvar.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # getvar.rb # module Puppet::Parser::Functions - newfunction(:getvar, :type => :rvalue, :doc => <<-'DOC') do |args| + newfunction(:getvar, type: :rvalue, doc: <<-'DOC') do |args| @summary Lookup a variable in a given namespace. @@ -34,7 +36,7 @@ module Puppet::Parser::Functions # avoid relying on inconsistent behaviour around ruby return values from catch result - rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set + rescue Puppet::ParseError end end end diff --git a/lib/puppet/parser/functions/glob.rb b/lib/puppet/parser/functions/glob.rb index 5475b74b3..be4e0d2cc 100644 --- a/lib/puppet/parser/functions/glob.rb +++ b/lib/puppet/parser/functions/glob.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # glob.rb # module Puppet::Parser::Functions - newfunction(:glob, :type => :rvalue, :doc => <<-DOC + newfunction(:glob, type: :rvalue, doc: <<-DOC @summary Uses same patterns as Dir#glob. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions @example Example Usage: $confs = glob(['/etc/**/*.conf', '/opt/**/*.conf']) DOC - ) do |arguments| - + ) do |arguments| unless arguments.size == 1 raise(Puppet::ParseError, 'glob(): Wrong number of arguments given ' \ "(#{arguments.size} for 1)") diff --git a/lib/puppet/parser/functions/grep.rb b/lib/puppet/parser/functions/grep.rb index 2d274838e..6ef3ee457 100644 --- a/lib/puppet/parser/functions/grep.rb +++ b/lib/puppet/parser/functions/grep.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # grep.rb # module Puppet::Parser::Functions - newfunction(:grep, :type => :rvalue, :doc => <<-DOC + newfunction(:grep, type: :rvalue, doc: <<-DOC @summary This function searches through an array and returns any elements that match the provided regular expression. @@ -17,8 +19,7 @@ module Puppet::Parser::Functions the "same" - as any logic can be used to filter, as opposed to just regular expressions: ```['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' }``` DOC - ) do |arguments| - + ) do |arguments| if arguments.size != 2 raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2") end diff --git a/lib/puppet/parser/functions/has_interface_with.rb b/lib/puppet/parser/functions/has_interface_with.rb index fb9af42eb..0404217b2 100644 --- a/lib/puppet/parser/functions/has_interface_with.rb +++ b/lib/puppet/parser/functions/has_interface_with.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # has_interface_with # module Puppet::Parser::Functions - newfunction(:has_interface_with, :type => :rvalue, :doc => <<-DOC + newfunction(:has_interface_with, type: :rvalue, doc: <<-DOC @summary Returns boolean based on kind and value. @@ -18,8 +20,7 @@ module Puppet::Parser::Functions @example If no "kind" is given, then the presence of the interface is checked: has_interface_with("lo") # Returns `true` DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments given (#{args.size} for 1 or 2)") if args.empty? || args.size > 2 interfaces = lookupvar('interfaces') @@ -42,7 +43,7 @@ module Puppet::Parser::Functions catch :undefined_variable do factval = lookupvar(kind) end - rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set + rescue Puppet::ParseError end if factval == value return true @@ -58,7 +59,7 @@ module Puppet::Parser::Functions catch :undefined_variable do factval = lookupvar("#{kind}_#{iface}") end - rescue Puppet::ParseError # rubocop:disable Lint/HandleExceptions : Eat the exception if strict_variables = true is set + rescue Puppet::ParseError end if value == factval result = true diff --git a/lib/puppet/parser/functions/has_ip_address.rb b/lib/puppet/parser/functions/has_ip_address.rb index 4004681ca..0cea4a7da 100644 --- a/lib/puppet/parser/functions/has_ip_address.rb +++ b/lib/puppet/parser/functions/has_ip_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # has_ip_address # module Puppet::Parser::Functions - newfunction(:has_ip_address, :type => :rvalue, :doc => <<-DOC + newfunction(:has_ip_address, type: :rvalue, doc: <<-DOC @summary Returns true if the client has the requested IP address on some interface. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions This function iterates through the 'interfaces' fact and checks the 'ipaddress_IFACE' facts, performing a simple string comparison. DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ diff --git a/lib/puppet/parser/functions/has_ip_network.rb b/lib/puppet/parser/functions/has_ip_network.rb index b4a3bad25..7406ed522 100644 --- a/lib/puppet/parser/functions/has_ip_network.rb +++ b/lib/puppet/parser/functions/has_ip_network.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # has_ip_network # module Puppet::Parser::Functions - newfunction(:has_ip_network, :type => :rvalue, :doc => <<-DOC + newfunction(:has_ip_network, type: :rvalue, doc: <<-DOC @summary Returns true if the client has an IP address within the requested network. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions This function iterates through the 'interfaces' fact and checks the 'network_IFACE' facts, performing a simple string comparision. DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments given (#{args.size} for 1)") if args.size != 1 Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ diff --git a/lib/puppet/parser/functions/has_key.rb b/lib/puppet/parser/functions/has_key.rb index 50dde53e3..334b849f0 100644 --- a/lib/puppet/parser/functions/has_key.rb +++ b/lib/puppet/parser/functions/has_key.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # has_key.rb # module Puppet::Parser::Functions - newfunction(:has_key, :type => :rvalue, :doc => <<-'DOC') do |args| + newfunction(:has_key, type: :rvalue, doc: <<-'DOC') do |args| @summary **Deprecated:** Determine if a hash has a certain key value. diff --git a/lib/puppet/parser/functions/hash.rb b/lib/puppet/parser/functions/hash.rb index 484cb59bf..029089ec4 100644 --- a/lib/puppet/parser/functions/hash.rb +++ b/lib/puppet/parser/functions/hash.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # hash.rb # module Puppet::Parser::Functions - newfunction(:hash, :type => :rvalue, :doc => <<-DOC + newfunction(:hash, type: :rvalue, doc: <<-DOC @summary **Deprecated:** This function converts an array into a hash. @@ -20,8 +22,7 @@ module Puppet::Parser::Functions Hash([['a',1],['b',2],['c',3]]) ``` DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? array = arguments[0] diff --git a/lib/puppet/parser/functions/intersection.rb b/lib/puppet/parser/functions/intersection.rb index 6d9d104eb..ead75807a 100644 --- a/lib/puppet/parser/functions/intersection.rb +++ b/lib/puppet/parser/functions/intersection.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # intersection.rb # module Puppet::Parser::Functions - newfunction(:intersection, :type => :rvalue, :doc => <<-DOC + newfunction(:intersection, type: :rvalue, doc: <<-DOC @summary This function returns an array of the intersection of two. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions intersection(["a","b","c"],["b","c","d"]) # returns ["b","c"] intersection(["a","b","c"],[1,2,3,4]) # returns [] (true, when evaluated as a Boolean) DOC - ) do |arguments| - + ) do |arguments| # Two arguments are required raise(Puppet::ParseError, "intersection(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size != 2 diff --git a/lib/puppet/parser/functions/is_absolute_path.rb b/lib/puppet/parser/functions/is_absolute_path.rb index f30991347..c464afa46 100644 --- a/lib/puppet/parser/functions/is_absolute_path.rb +++ b/lib/puppet/parser/functions/is_absolute_path.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_absolute_path.rb # module Puppet::Parser::Functions - newfunction(:is_absolute_path, :type => :rvalue, :arity => 1, :doc => <<-'DOC') do |args| + newfunction(:is_absolute_path, type: :rvalue, arity: 1, doc: <<-'DOC') do |args| @summary **Deprecated:** Returns boolean true if the string represents an absolute path in the filesystem. @@ -49,8 +51,8 @@ module Puppet::Parser::Functions slash = '[\\\\/]' name = '[^\\\\/]+' regexes = { - :windows => %r{^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))}i, - :posix => %r{^/}, + windows: %r{^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))}i, + posix: %r{^/}, } value = !!(path =~ regexes[:posix]) || !!(path =~ regexes[:windows]) # rubocop:disable Style/DoubleNegation : No alternative known end diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb index 1df57b2fa..e4e7b8102 100644 --- a/lib/puppet/parser/functions/is_array.rb +++ b/lib/puppet/parser/functions/is_array.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_array.rb # module Puppet::Parser::Functions - newfunction(:is_array, :type => :rvalue, :doc => <<-DOC + newfunction(:is_array, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable passed to this function is an array. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_array, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb index cf5cb32c0..96cb2172e 100644 --- a/lib/puppet/parser/functions/is_bool.rb +++ b/lib/puppet/parser/functions/is_bool.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_bool.rb # module Puppet::Parser::Functions - newfunction(:is_bool, :type => :rvalue, :doc => <<-DOC + newfunction(:is_bool, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable passed to this function is a boolean. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_bool, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/is_domain_name.rb b/lib/puppet/parser/functions/is_domain_name.rb index 390a86894..32b94816c 100644 --- a/lib/puppet/parser/functions/is_domain_name.rb +++ b/lib/puppet/parser/functions/is_domain_name.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_domain_name.rb # module Puppet::Parser::Functions - newfunction(:is_domain_name, :type => :rvalue, :doc => <<-DOC + newfunction(:is_domain_name, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the string passed to this function is a syntactically correct domain name. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| if arguments.size != 1 raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments given #{arguments.size} for 1") end @@ -50,7 +51,7 @@ module Puppet::Parser::Functions break if label.length > label_max_length break if label[-1..-1] == '-' break if label[0..0] == '-' - break unless %r{^[a-z\d-]+$}i =~ label + break unless %r{^[a-z\d-]+$}i.match?(label) end return vlabels == labels end diff --git a/lib/puppet/parser/functions/is_email_address.rb b/lib/puppet/parser/functions/is_email_address.rb index 1c41b86be..5a9594c04 100644 --- a/lib/puppet/parser/functions/is_email_address.rb +++ b/lib/puppet/parser/functions/is_email_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_email_address.rb # module Puppet::Parser::Functions - newfunction(:is_email_address, :type => :rvalue, :doc => <<-DOC + newfunction(:is_email_address, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the string passed to this function is a valid email address. @@ -12,14 +14,14 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| + ) do |arguments| if arguments.size != 1 raise(Puppet::ParseError, "is_email_address(): Wrong number of arguments given #{arguments.size} for 1") end # Taken from http://emailregex.com/ (simpler regex) valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z} - return (arguments[0] =~ valid_email_regex) == 0 # rubocop:disable Style/NumericPredicate : Changing to '.zero?' breaks the code + return (arguments[0] =~ valid_email_regex) == 0 end end diff --git a/lib/puppet/parser/functions/is_float.rb b/lib/puppet/parser/functions/is_float.rb index 583793d01..c44746b5e 100644 --- a/lib/puppet/parser/functions/is_float.rb +++ b/lib/puppet/parser/functions/is_float.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_float.rb # module Puppet::Parser::Functions - newfunction(:is_float, :type => :rvalue, :doc => <<-DOC + newfunction(:is_float, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable passed to this function is a float. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/is_function_available.rb b/lib/puppet/parser/functions/is_function_available.rb index e931225c4..d6f666fb4 100644 --- a/lib/puppet/parser/functions/is_function_available.rb +++ b/lib/puppet/parser/functions/is_function_available.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_function_available.rb # module Puppet::Parser::Functions - newfunction(:is_function_available, :type => :rvalue, :doc => <<-DOC + newfunction(:is_function_available, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Determines whether the Puppet runtime has access to a function by that name. @@ -14,8 +16,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| if arguments.size != 1 raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments given #{arguments.size} for 1") end diff --git a/lib/puppet/parser/functions/is_hash.rb b/lib/puppet/parser/functions/is_hash.rb index f85b9eeaa..812ff8844 100644 --- a/lib/puppet/parser/functions/is_hash.rb +++ b/lib/puppet/parser/functions/is_hash.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_hash.rb # module Puppet::Parser::Functions - newfunction(:is_hash, :type => :rvalue, :doc => <<-DOC + newfunction(:is_hash, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable passed to this function is a hash. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "is_hash(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 type = arguments[0] diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb index a86b5cddc..cdb57719b 100644 --- a/lib/puppet/parser/functions/is_integer.rb +++ b/lib/puppet/parser/functions/is_integer.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_integer.rb # module Puppet::Parser::Functions - newfunction(:is_integer, :type => :rvalue, :doc => <<-DOC + newfunction(:is_integer, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable passed to this function is an Integer or a decimal (base 10) integer in String form. @@ -18,8 +20,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_integer, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb index 61f84a13e..506244fc6 100644 --- a/lib/puppet/parser/functions/is_ip_address.rb +++ b/lib/puppet/parser/functions/is_ip_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_ip_address.rb # module Puppet::Parser::Functions - newfunction(:is_ip_address, :type => :rvalue, :doc => <<-DOC + newfunction(:is_ip_address, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the string passed to this function is a valid IP address. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| require 'ipaddr' function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, diff --git a/lib/puppet/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb index 5064f4890..4610805f5 100644 --- a/lib/puppet/parser/functions/is_ipv4_address.rb +++ b/lib/puppet/parser/functions/is_ipv4_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_ipv4_address.rb # module Puppet::Parser::Functions - newfunction(:is_ipv4_address, :type => :rvalue, :doc => <<-DOC + newfunction(:is_ipv4_address, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the string passed to this function is a valid IPv4 address. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| require 'ipaddr' function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, diff --git a/lib/puppet/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb index a4de14fd2..abb79df58 100644 --- a/lib/puppet/parser/functions/is_ipv6_address.rb +++ b/lib/puppet/parser/functions/is_ipv6_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_ipv6_address.rb # module Puppet::Parser::Functions - newfunction(:is_ipv6_address, :type => :rvalue, :doc => <<-DOC + newfunction(:is_ipv6_address, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the string passed to this function is a valid IPv6 address. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/is_mac_address.rb b/lib/puppet/parser/functions/is_mac_address.rb index ef1fc2059..67a269c4a 100644 --- a/lib/puppet/parser/functions/is_mac_address.rb +++ b/lib/puppet/parser/functions/is_mac_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_mac_address.rb # module Puppet::Parser::Functions - newfunction(:is_mac_address, :type => :rvalue, :doc => <<-DOC + newfunction(:is_mac_address, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the string passed to this function is a valid mac address. @@ -12,16 +14,15 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| if arguments.size != 1 raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments given #{arguments.size} for 1") end mac = arguments[0] - return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$}i =~ mac - return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){19}$}i =~ mac + return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){5}$}i.match?(mac) + return true if %r{^[a-f0-9]{1,2}(:[a-f0-9]{1,2}){19}$}i.match?(mac) return false end end diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb index 8b42119ae..a949557a9 100644 --- a/lib/puppet/parser/functions/is_numeric.rb +++ b/lib/puppet/parser/functions/is_numeric.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_numeric.rb # module Puppet::Parser::Functions - newfunction(:is_numeric, :type => :rvalue, :doc => <<-DOC + newfunction(:is_numeric, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the given value is numeric. @@ -22,8 +24,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb index 7410d32a4..5b4627a45 100644 --- a/lib/puppet/parser/functions/is_string.rb +++ b/lib/puppet/parser/functions/is_string.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # is_string.rb # module Puppet::Parser::Functions - newfunction(:is_string, :type => :rvalue, :doc => <<-DOC + newfunction(:is_string, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns true if the variable passed to this function is a string. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:* **Deprecated** Will be removed in a future version of stdlib. See [`validate_legacy`](#validate_legacy). DOC - ) do |arguments| - + ) do |arguments| function_deprecation([:is_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb index 266ad65b9..f1e4bc141 100644 --- a/lib/puppet/parser/functions/join.rb +++ b/lib/puppet/parser/functions/join.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # join.rb # module Puppet::Parser::Functions - newfunction(:join, :type => :rvalue, :doc => <<-DOC + newfunction(:join, type: :rvalue, doc: <<-DOC @summary **Deprecated:** This function joins an array into a string using a separator. @@ -15,8 +17,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 5.4.0 this function has been replaced with a built-in [`join`](https://puppet.com/docs/puppet/latest/function.html#join) function. DOC - ) do |arguments| - + ) do |arguments| # Technically we support two arguments but only first is mandatory ... raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? diff --git a/lib/puppet/parser/functions/join_keys_to_values.rb b/lib/puppet/parser/functions/join_keys_to_values.rb index 73d4a1ff0..3e709cb9c 100644 --- a/lib/puppet/parser/functions/join_keys_to_values.rb +++ b/lib/puppet/parser/functions/join_keys_to_values.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # join_keys_to_values.rb # module Puppet::Parser::Functions - newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-DOC + newfunction(:join_keys_to_values, type: :rvalue, doc: <<-DOC @summary This function joins each key of a hash to that key's corresponding value with a separator. @@ -23,8 +25,7 @@ module Puppet::Parser::Functions formatting of values in the array) - see the `new` function for `String` and its formatting options for `Array` and `Hash`. DOC - ) do |arguments| - + ) do |arguments| # Validate the number of arguments. if arguments.size != 2 raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two arguments, but #{arguments.size} given.") diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb index 80d080c65..10a85477d 100644 --- a/lib/puppet/parser/functions/keys.rb +++ b/lib/puppet/parser/functions/keys.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # keys.rb # module Puppet::Parser::Functions - newfunction(:keys, :type => :rvalue, :doc => <<-DOC + newfunction(:keys, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns the keys of a hash as an array. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 5.5.0, the built-in [`keys`](https://puppet.com/docs/puppet/latest/function.html#keys) function will be used instead of this function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? hash = arguments[0] diff --git a/lib/puppet/parser/functions/load_module_metadata.rb b/lib/puppet/parser/functions/load_module_metadata.rb index 79d98cdd8..b1fd196f1 100644 --- a/lib/puppet/parser/functions/load_module_metadata.rb +++ b/lib/puppet/parser/functions/load_module_metadata.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # load_module_metadata.rb # module Puppet::Parser::Functions - newfunction(:load_module_metadata, :type => :rvalue, :doc => <<-DOC + newfunction(:load_module_metadata, type: :rvalue, doc: <<-DOC @summary This function loads the metadata of a given module. @@ -13,7 +15,7 @@ module Puppet::Parser::Functions @return The modules metadata DOC - ) do |args| + ) do |args| raise(Puppet::ParseError, 'load_module_metadata(): Wrong number of arguments, expects one or two') unless [1, 2].include?(args.size) mod = args[0] allow_empty_metadata = args[1] diff --git a/lib/puppet/parser/functions/loadjson.rb b/lib/puppet/parser/functions/loadjson.rb index 3c6087855..ef1fd87c3 100644 --- a/lib/puppet/parser/functions/loadjson.rb +++ b/lib/puppet/parser/functions/loadjson.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # loadjson.rb # module Puppet::Parser::Functions - newfunction(:loadjson, :type => :rvalue, :arity => -2, :doc => <<-'DOC') do |args| + newfunction(:loadjson, type: :rvalue, arity: -2, doc: <<-'DOC') do |args| @summary Load a JSON file containing an array, string, or hash, and return the data in the corresponding native data type. @@ -40,7 +42,7 @@ module Puppet::Parser::Functions url = args[0] end begin - contents = OpenURI.open_uri(url, :http_basic_authentication => [username, password]) + contents = OpenURI.open_uri(url, http_basic_authentication: [username, password]) rescue OpenURI::HTTPError => err res = err.io warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'") diff --git a/lib/puppet/parser/functions/loadyaml.rb b/lib/puppet/parser/functions/loadyaml.rb index f84f5300d..70f8e5fe3 100644 --- a/lib/puppet/parser/functions/loadyaml.rb +++ b/lib/puppet/parser/functions/loadyaml.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # loadyaml.rb # module Puppet::Parser::Functions - newfunction(:loadyaml, :type => :rvalue, :arity => -2, :doc => <<-'DOC') do |args| + newfunction(:loadyaml, type: :rvalue, arity: -2, doc: <<-'DOC') do |args| @summary Load a YAML file containing an array, string, or hash, and return the data in the corresponding native data type. @@ -40,7 +42,7 @@ module Puppet::Parser::Functions url = args[0] end begin - contents = OpenURI.open_uri(url, :http_basic_authentication => [username, password]) + contents = OpenURI.open_uri(url, http_basic_authentication: [username, password]) rescue OpenURI::HTTPError => err res = err.io warning("Can't load '#{url}' HTTP Error Code: '#{res.status[0]}'") diff --git a/lib/puppet/parser/functions/lstrip.rb b/lib/puppet/parser/functions/lstrip.rb index 2fd31a226..16e0006dd 100644 --- a/lib/puppet/parser/functions/lstrip.rb +++ b/lib/puppet/parser/functions/lstrip.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # lstrip.rb # module Puppet::Parser::Functions - newfunction(:lstrip, :type => :rvalue, :doc => <<-DOC + newfunction(:lstrip, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Strips leading spaces to the left of a string. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a built-in [`max`](https://puppet.com/docs/puppet/latest/function.html#max) function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "lstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/max.rb b/lib/puppet/parser/functions/max.rb index 00a183aba..173dc0e9a 100644 --- a/lib/puppet/parser/functions/max.rb +++ b/lib/puppet/parser/functions/max.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # max.rb # module Puppet::Parser::Functions - newfunction(:max, :type => :rvalue, :doc => <<-DOC + newfunction(:max, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns the highest value of all arguments. @@ -14,8 +16,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a built-in [`lstrip`](https://puppet.com/docs/puppet/latest/function.html#lstrip) function. DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, 'max(): Wrong number of arguments need at least one') if args.empty? # Sometimes we get numbers as numerics and sometimes as strings. diff --git a/lib/puppet/parser/functions/member.rb b/lib/puppet/parser/functions/member.rb index 7efcb1f63..279548849 100644 --- a/lib/puppet/parser/functions/member.rb +++ b/lib/puppet/parser/functions/member.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + # TODO(Krzysztof Wilczynski): We need to add support for regular expression ... # TODO(Krzysztof Wilczynski): Support for strings and hashes too ... # # member.rb # module Puppet::Parser::Functions - newfunction(:member, :type => :rvalue, :doc => <<-DOC + newfunction(:member, type: :rvalue, doc: <<-DOC @summary This function determines if a variable is a member of an array. @@ -34,8 +36,7 @@ module Puppet::Parser::Functions hash is to use the built-in [`any`](https://puppet.com/docs/puppet/latest/function.html#any) and [`all`](https://puppet.com/docs/puppet/latest/function.html#all) functions. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "member(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 array = arguments[0] diff --git a/lib/puppet/parser/functions/merge.rb b/lib/puppet/parser/functions/merge.rb index 9a0e8c1f0..522e48401 100644 --- a/lib/puppet/parser/functions/merge.rb +++ b/lib/puppet/parser/functions/merge.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # merge.rb # module Puppet::Parser::Functions - newfunction(:merge, :type => :rvalue, :doc => <<-'DOC') do |args| + newfunction(:merge, type: :rvalue, doc: <<-'DOC') do |args| @summary Merges two or more hashes together and returns the resulting hash. diff --git a/lib/puppet/parser/functions/min.rb b/lib/puppet/parser/functions/min.rb index c211a9e24..1734222d3 100644 --- a/lib/puppet/parser/functions/min.rb +++ b/lib/puppet/parser/functions/min.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # min.rb # module Puppet::Parser::Functions - newfunction(:min, :type => :rvalue, :doc => <<-DOC + newfunction(:min, type: :rvalue, doc: <<-DOC @summary **Deprecated:** Returns the lowest value of all arguments. @@ -14,8 +16,7 @@ module Puppet::Parser::Functions > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a built-in [`min`](https://puppet.com/docs/puppet/latest/function.html#min) function. DOC - ) do |args| - + ) do |args| raise(Puppet::ParseError, 'min(): Wrong number of arguments need at least one') if args.empty? # Sometimes we get numbers as numerics and sometimes as strings. diff --git a/lib/puppet/parser/functions/num2bool.rb b/lib/puppet/parser/functions/num2bool.rb index 6e530db9a..c74ba0198 100644 --- a/lib/puppet/parser/functions/num2bool.rb +++ b/lib/puppet/parser/functions/num2bool.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # num2bool.rb # module Puppet::Parser::Functions - newfunction(:num2bool, :type => :rvalue, :doc => <<-DOC + newfunction(:num2bool, type: :rvalue, doc: <<-DOC @summary This function converts a number or a string representation of a number into a true boolean. @@ -14,14 +16,13 @@ module Puppet::Parser::Functions Boolean(0) # false for any zero or negative number Boolean(1) # true for any positive number DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "num2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 number = arguments[0] case number - when Numeric # rubocop:disable Lint/EmptyWhen : Required for the module to work + when Numeric # Yay, it's a number when String begin diff --git a/lib/puppet/parser/functions/parsejson.rb b/lib/puppet/parser/functions/parsejson.rb index 76b392fb1..bb1992e10 100644 --- a/lib/puppet/parser/functions/parsejson.rb +++ b/lib/puppet/parser/functions/parsejson.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # parsejson.rb # module Puppet::Parser::Functions - newfunction(:parsejson, :type => :rvalue, :doc => <<-DOC + newfunction(:parsejson, type: :rvalue, doc: <<-DOC @summary This function accepts JSON as a string and converts it into the correct Puppet structure. @@ -14,7 +16,7 @@ module Puppet::Parser::Functions The optional second argument can be used to pass a default value that will be returned if the parsing of YAML string have failed. DOC - ) do |arguments| + ) do |arguments| raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless arguments.length >= 1 begin diff --git a/lib/puppet/parser/functions/parseyaml.rb b/lib/puppet/parser/functions/parseyaml.rb index 5d081e6a6..f80c293d2 100644 --- a/lib/puppet/parser/functions/parseyaml.rb +++ b/lib/puppet/parser/functions/parseyaml.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # parseyaml.rb # module Puppet::Parser::Functions - newfunction(:parseyaml, :type => :rvalue, :doc => <<-DOC + newfunction(:parseyaml, type: :rvalue, doc: <<-DOC @summary This function accepts YAML as a string and converts it into the correct Puppet structure. @@ -14,7 +16,7 @@ module Puppet::Parser::Functions The optional second argument can be used to pass a default value that will be returned if the parsing of YAML string have failed. DOC - ) do |arguments| + ) do |arguments| raise ArgumentError, 'Wrong number of arguments. 1 or 2 arguments should be provided.' unless arguments.length >= 1 require 'yaml' diff --git a/lib/puppet/parser/functions/pick.rb b/lib/puppet/parser/functions/pick.rb index e31dc95de..34450c5fa 100644 --- a/lib/puppet/parser/functions/pick.rb +++ b/lib/puppet/parser/functions/pick.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # pick.rb # module Puppet::Parser::Functions - newfunction(:pick, :type => :rvalue, :doc => <<-EOS + newfunction(:pick, type: :rvalue, doc: <<-EOS @summary This function is similar to a coalesce function in SQL in that it will return the first value in a list of values that is not undefined or an empty string. @@ -21,7 +23,7 @@ module Puppet::Parser::Functions Enterprise Console are brought into Puppet as top-scope variables), and, failing that, will use a default value of 1.449. EOS - ) do |args| + ) do |args| args = args.compact args.delete(:undef) args.delete(:undefined) diff --git a/lib/puppet/parser/functions/pick_default.rb b/lib/puppet/parser/functions/pick_default.rb index d94bb52aa..0915df144 100644 --- a/lib/puppet/parser/functions/pick_default.rb +++ b/lib/puppet/parser/functions/pick_default.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # pick_default.rb # module Puppet::Parser::Functions - newfunction(:pick_default, :type => :rvalue, :doc => <<-DOC + newfunction(:pick_default, type: :rvalue, doc: <<-DOC @summary This function will return the first value in a list of values that is not undefined or an empty string. @@ -27,7 +29,7 @@ module Puppet::Parser::Functions all arguments are empty. This allows pick_default to use an empty value as default. DOC - ) do |args| + ) do |args| raise 'Must receive at least one argument.' if args.empty? default = args.last args = args[0..-2].compact diff --git a/lib/puppet/parser/functions/prefix.rb b/lib/puppet/parser/functions/prefix.rb index b5e96416d..04ed267d6 100644 --- a/lib/puppet/parser/functions/prefix.rb +++ b/lib/puppet/parser/functions/prefix.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # prefix.rb # module Puppet::Parser::Functions - newfunction(:prefix, :type => :rvalue, :doc => <<-DOC + newfunction(:prefix, type: :rvalue, doc: <<-DOC @summary This function applies a prefix to all elements in an array or a hash. @@ -17,8 +19,7 @@ module Puppet::Parser::Functions @return [Hash] or [Array] The passed values now contains the passed prefix DOC - ) do |arguments| - + ) do |arguments| # Technically we support two arguments but only first is mandatory ... raise(Puppet::ParseError, "prefix(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? diff --git a/lib/puppet/parser/functions/private.rb b/lib/puppet/parser/functions/private.rb index 11a9451f9..037d2b2a8 100644 --- a/lib/puppet/parser/functions/private.rb +++ b/lib/puppet/parser/functions/private.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # private.rb # module Puppet::Parser::Functions - newfunction(:private, :doc => <<-'DOC' + newfunction(:private, doc: <<-'DOC' @summary **Deprecated:** Sets the current class or definition as private. Calling the class or definition from outside the current module will fail. @@ -10,8 +12,8 @@ module Puppet::Parser::Functions @return Sets the current class or definition as private DOC - ) do |args| - warning("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : Cannot shorten this line + ) do |args| + warning("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Layout/LineLength : Cannot shorten this line unless Puppet::Parser::Functions.autoloader.loaded?(:assert_private) Puppet::Parser::Functions.autoloader.load(:assert_private) end diff --git a/lib/puppet/parser/functions/pry.rb b/lib/puppet/parser/functions/pry.rb index 4191951d3..8fb7d2053 100644 --- a/lib/puppet/parser/functions/pry.rb +++ b/lib/puppet/parser/functions/pry.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # pry.rb # module Puppet::Parser::Functions - newfunction(:pry, :type => :statement, :doc => <<-DOC + newfunction(:pry, type: :statement, doc: <<-DOC @summary This function invokes a pry debugging session in the current scope object. This is useful for debugging manifest code at specific points during a compilation. @@ -15,7 +17,7 @@ module Puppet::Parser::Functions `pry()` DOC - ) do |arguments| + ) do |arguments| begin require 'pry' rescue LoadError diff --git a/lib/puppet/parser/functions/pw_hash.rb b/lib/puppet/parser/functions/pw_hash.rb index 9b8e0d890..3351c9fe2 100644 --- a/lib/puppet/parser/functions/pw_hash.rb +++ b/lib/puppet/parser/functions/pw_hash.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. # To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # Puppet::Parser::Functions.newfunction( :pw_hash, - :type => :rvalue, - :arity => 3, - :doc => <<-DOC + type: :rvalue, + arity: 3, + doc: <<-DOC, @summary Hashes a password using the crypt function. Provides a hash usable on most POSIX systems. @@ -50,7 +52,7 @@ raise ArgumentError, "pw_hash(): #{args[1]} is not a valid hash type" if hash_type.nil? raise ArgumentError, 'pw_hash(): third argument must be a string' unless args[2].is_a? String raise ArgumentError, 'pw_hash(): third argument must not be empty' if args[2].empty? - raise ArgumentError, 'pw_hash(): characters in salt must be in the set [a-zA-Z0-9./]' unless args[2] =~ %r{\A[a-zA-Z0-9./]+\z} + raise ArgumentError, 'pw_hash(): characters in salt must be in the set [a-zA-Z0-9./]' unless %r{\A[a-zA-Z0-9./]+\z}.match?(args[2]) password = args[0] return nil if password.nil? || password.empty? @@ -58,7 +60,8 @@ salt = "$#{hash_type}$#{args[2]}" # handle weak implementations of String#crypt - if 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' + # dup the string to get rid of frozen status for testing + if ('test'.dup).crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' # JRuby < 1.7.17 # MS Windows and other systems that don't support enhanced salts raise Puppet::ParseError, 'system does not support enhanced salts' unless RUBY_PLATFORM == 'java' diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index 1df7327a5..541094374 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # range.rb # # TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ... module Puppet::Parser::Functions - newfunction(:range, :type => :rvalue, :doc => <<-DOC + newfunction(:range, type: :rvalue, doc: <<-DOC @summary When given range in the form of (start, stop) it will extrapolate a range as an array. @@ -42,8 +44,7 @@ module Puppet::Parser::Functions Integer[0, 9].each |$x| { notice($x) } # notices 0, 1, 2, ... 9 DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, 'range(): Wrong number of arguments given (0 for 1)') if arguments.empty? if arguments.size > 1 @@ -65,7 +66,7 @@ module Puppet::Parser::Functions type = m[2] step = 1 - elsif value =~ %r{^.+$} + elsif %r{^.+$}.match?(value) raise(Puppet::ParseError, "range(): Unable to compute range from the value: #{value}") else raise(Puppet::ParseError, "range(): Unknown range format: #{value}") @@ -73,7 +74,7 @@ module Puppet::Parser::Functions end # If we were given an integer, ensure we work with one - if start.to_s =~ %r{^\d+$} + if %r{^\d+$}.match?(start.to_s) start = start.to_i stop = stop.to_i else diff --git a/lib/puppet/parser/functions/regexpescape.rb b/lib/puppet/parser/functions/regexpescape.rb index 43b729ea8..c5dcf8cfe 100644 --- a/lib/puppet/parser/functions/regexpescape.rb +++ b/lib/puppet/parser/functions/regexpescape.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + # # regexpescape.rb # module Puppet::Parser::Functions - newfunction(:regexpescape, :type => :rvalue, :doc => <<-DOC + newfunction(:regexpescape, type: :rvalue, doc: <<-DOC @summary Regexp escape a string or array of strings. Requires either a single string or an array as an input. @return [String] A string of characters with metacharacters converted to their escaped form. DOC - ) do |arguments| # rubocop:disable Layout/ClosingParenthesisIndentation + ) do |arguments| raise(Puppet::ParseError, "regexpescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/reject.rb b/lib/puppet/parser/functions/reject.rb index 6342db6e4..490249c53 100644 --- a/lib/puppet/parser/functions/reject.rb +++ b/lib/puppet/parser/functions/reject.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # reject.rb # module Puppet::Parser::Functions - newfunction(:reject, :type => :rvalue, :doc => <<-DOC) do |args| + newfunction(:reject, type: :rvalue, doc: <<-DOC) do |args| @summary This function searches through an array and rejects all elements that match the provided regular expression. diff --git a/lib/puppet/parser/functions/reverse.rb b/lib/puppet/parser/functions/reverse.rb index 8b97a9731..38250bb09 100644 --- a/lib/puppet/parser/functions/reverse.rb +++ b/lib/puppet/parser/functions/reverse.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # reverse.rb # module Puppet::Parser::Functions - newfunction(:reverse, :type => :rvalue, :doc => <<-DOC + newfunction(:reverse, type: :rvalue, doc: <<-DOC @summary Reverses the order of a string or array. @@ -11,8 +13,7 @@ module Puppet::Parser::Functions > *Note:* that the same can be done with the reverse_each() function in Puppet. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "reverse(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/round.rb b/lib/puppet/parser/functions/round.rb index 12067bad9..bb1013ad9 100644 --- a/lib/puppet/parser/functions/round.rb +++ b/lib/puppet/parser/functions/round.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # round.rb # module Puppet::Parser::Functions - newfunction(:round, :type => :rvalue, :doc => <<-DOC + newfunction(:round, type: :rvalue, doc: <<-DOC @summary Rounds a number to the nearest integer @@ -18,8 +20,7 @@ module Puppet::Parser::Functions > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core will be used instead of this function. DOC - ) do |args| - + ) do |args| raise Puppet::ParseError, "round(): Wrong number of arguments given #{args.size} for 1" if args.size != 1 raise Puppet::ParseError, "round(): Expected a Numeric, got #{args[0].class}" unless args[0].is_a? Numeric diff --git a/lib/puppet/parser/functions/rstrip.rb b/lib/puppet/parser/functions/rstrip.rb index fc809c8bf..d07ef6398 100644 --- a/lib/puppet/parser/functions/rstrip.rb +++ b/lib/puppet/parser/functions/rstrip.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # rstrip.rb # module Puppet::Parser::Functions - newfunction(:rstrip, :type => :rvalue, :doc => <<-DOC + newfunction(:rstrip, type: :rvalue, doc: <<-DOC @summary Strips leading spaces to the right of the string. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core will be used instead of this function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "rstrip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/seeded_rand.rb b/lib/puppet/parser/functions/seeded_rand.rb index 848e09283..eb495e812 100644 --- a/lib/puppet/parser/functions/seeded_rand.rb +++ b/lib/puppet/parser/functions/seeded_rand.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + # # seeded_rand.rb # Puppet::Parser::Functions.newfunction( :seeded_rand, - :arity => 2, - :type => :rvalue, - :doc => <<-DOC + arity: 2, + type: :rvalue, + doc: <<-DOC, @summary Generates a random whole number greater than or equal to 0 and less than MAX, using the value of SEED for repeatable randomness. diff --git a/lib/puppet/parser/functions/shell_escape.rb b/lib/puppet/parser/functions/shell_escape.rb index 0cf07e59e..113feee5d 100644 --- a/lib/puppet/parser/functions/shell_escape.rb +++ b/lib/puppet/parser/functions/shell_escape.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'shellwords' # # shell_escape.rb # module Puppet::Parser::Functions - newfunction(:shell_escape, :type => :rvalue, :doc => <<-DOC + newfunction(:shell_escape, type: :rvalue, doc: <<-DOC @summary Escapes a string so that it can be safely used in a Bourne shell command line. @@ -15,8 +17,7 @@ module Puppet::Parser::Functions This function behaves the same as ruby's Shellwords.shellescape() function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "shell_escape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 # explicit conversion to string is required for ruby 1.9 diff --git a/lib/puppet/parser/functions/shell_join.rb b/lib/puppet/parser/functions/shell_join.rb index e498f55e1..12d1652af 100644 --- a/lib/puppet/parser/functions/shell_join.rb +++ b/lib/puppet/parser/functions/shell_join.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true require 'shellwords' # # shell_join.rb # module Puppet::Parser::Functions - newfunction(:shell_join, :type => :rvalue, :doc => <<-DOC + newfunction(:shell_join, type: :rvalue, doc: <<-DOC @summary Builds a command line string from the given array of strings. Each array item is escaped for Bourne shell. All items are then joined together, with a single space in between. @@ -13,8 +14,7 @@ module Puppet::Parser::Functions @return a command line string DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "shell_join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 array = arguments[0] diff --git a/lib/puppet/parser/functions/shell_split.rb b/lib/puppet/parser/functions/shell_split.rb index 7c9f12375..1fa3c8ed3 100644 --- a/lib/puppet/parser/functions/shell_split.rb +++ b/lib/puppet/parser/functions/shell_split.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'shellwords' # # shell_split.rb # module Puppet::Parser::Functions - newfunction(:shell_split, :type => :rvalue, :doc => <<-DOC + newfunction(:shell_split, type: :rvalue, doc: <<-DOC @summary Splits a string into an array of tokens in the same way the Bourne shell does. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions This function behaves the same as ruby's Shellwords.shellsplit() function DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "shell_split(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 string = arguments[0].to_s diff --git a/lib/puppet/parser/functions/shuffle.rb b/lib/puppet/parser/functions/shuffle.rb index 3e10739a5..c79ec2e8a 100644 --- a/lib/puppet/parser/functions/shuffle.rb +++ b/lib/puppet/parser/functions/shuffle.rb @@ -1,16 +1,17 @@ +# frozen_string_literal: true + # # shuffle.rb # module Puppet::Parser::Functions - newfunction(:shuffle, :type => :rvalue, :doc => <<-DOC + newfunction(:shuffle, type: :rvalue, doc: <<-DOC @summary Randomizes the order of a string or array elements. @return randomized string or array DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "shuffle(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/size.rb b/lib/puppet/parser/functions/size.rb index 39b856c1b..9942bb13b 100644 --- a/lib/puppet/parser/functions/size.rb +++ b/lib/puppet/parser/functions/size.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # size.rb # module Puppet::Parser::Functions - newfunction(:size, :type => :rvalue, :doc => <<-DOC + newfunction(:size, type: :rvalue, doc: <<-DOC @summary Returns the number of elements in a string, an array or a hash @@ -12,8 +14,7 @@ module Puppet::Parser::Functions > *Note:* that since Puppet 5.4.0, the length() function in Puppet is preferred over this. For versions of Puppet < 5.4.0 use the stdlib length() function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "size(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? item = arguments[0] diff --git a/lib/puppet/parser/functions/sort.rb b/lib/puppet/parser/functions/sort.rb index a6e0509dc..29c9f6098 100644 --- a/lib/puppet/parser/functions/sort.rb +++ b/lib/puppet/parser/functions/sort.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # sort.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:sort, :type => :rvalue, :doc => <<-DOC + newfunction(:sort, type: :rvalue, doc: <<-DOC @summary Sorts strings and arrays lexically. @@ -12,8 +14,7 @@ module Puppet::Parser::Functions Note that from Puppet 6.0.0 the same function in Puppet will be used instead of this. DOC - ) do |arguments| - + ) do |arguments| if arguments.size != 1 raise(Puppet::ParseError, "sort(): Wrong number of arguments given #{arguments.size} for 1") end diff --git a/lib/puppet/parser/functions/squeeze.rb b/lib/puppet/parser/functions/squeeze.rb index 548c93313..9fdc3a8d0 100644 --- a/lib/puppet/parser/functions/squeeze.rb +++ b/lib/puppet/parser/functions/squeeze.rb @@ -1,16 +1,17 @@ +# frozen_string_literal: true + # # squeeze.rb # module Puppet::Parser::Functions - newfunction(:squeeze, :type => :rvalue, :doc => <<-DOC + newfunction(:squeeze, type: :rvalue, doc: <<-DOC @summary Returns a new string where runs of the same character that occur in this set are replaced by a single character. @return a new string where runs of the same character that occur in this set are replaced by a single character. DOC - ) do |arguments| - + ) do |arguments| if (arguments.size != 2) && (arguments.size != 1) raise(Puppet::ParseError, "squeeze(): Wrong number of arguments given #{arguments.size} for 2 or 1") end diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb index 165cf5d64..672306035 100644 --- a/lib/puppet/parser/functions/str2bool.rb +++ b/lib/puppet/parser/functions/str2bool.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # str2bool.rb # module Puppet::Parser::Functions - newfunction(:str2bool, :type => :rvalue, :doc => <<-DOC + newfunction(:str2bool, type: :rvalue, doc: <<-DOC @summary This converts a string to a boolean. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions > *Note:* that since Puppet 5.0.0 the Boolean data type can convert strings to a Boolean value. See the function new() in Puppet for details what the Boolean data type supports. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "str2bool(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? string = arguments[0] diff --git a/lib/puppet/parser/functions/str2saltedpbkdf2.rb b/lib/puppet/parser/functions/str2saltedpbkdf2.rb index 1f0a19376..f3cd811a5 100644 --- a/lib/puppet/parser/functions/str2saltedpbkdf2.rb +++ b/lib/puppet/parser/functions/str2saltedpbkdf2.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # str2saltedpbkdf2.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:str2saltedpbkdf2, :type => :rvalue, :doc => <<-DOC + newfunction(:str2saltedpbkdf2, type: :rvalue, doc: <<-DOC @summary Convert a string into a salted SHA512 PBKDF2 password hash like requred for OS X / macOS 10.8+ Convert a string into a salted SHA512 PBKDF2 password hash like requred for OS X / macOS 10.8+. @@ -33,7 +35,7 @@ module Puppet::Parser::Functions @return [Hash] Provides a hash containing the hex version of the password, the hex version of the salt, and iterations. DOC - ) do |args| + ) do |args| require 'openssl' raise ArgumentError, "str2saltedpbkdf2(): wrong number of arguments (#{args.size} for 3)" if args.size != 3 diff --git a/lib/puppet/parser/functions/str2saltedsha512.rb b/lib/puppet/parser/functions/str2saltedsha512.rb index 8b1c2c997..a1a278bc7 100644 --- a/lib/puppet/parser/functions/str2saltedsha512.rb +++ b/lib/puppet/parser/functions/str2saltedsha512.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # str2saltedsha512.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:str2saltedsha512, :type => :rvalue, :doc => <<-DOC + newfunction(:str2saltedsha512, type: :rvalue, doc: <<-DOC @summary This converts a string to a salted-SHA512 password hash (which is used for OS X versions >= 10.7). @@ -15,7 +17,7 @@ module Puppet::Parser::Functions of a salted-SHA512 password hash that can be inserted into your Puppet manifests as a valid password attribute. DOC - ) do |arguments| + ) do |arguments| require 'digest/sha2' raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments passed (#{arguments.size} but we require 1)") if arguments.size != 1 diff --git a/lib/puppet/parser/functions/strip.rb b/lib/puppet/parser/functions/strip.rb index 067af001d..6f11736f2 100644 --- a/lib/puppet/parser/functions/strip.rb +++ b/lib/puppet/parser/functions/strip.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # strip.rb # module Puppet::Parser::Functions - newfunction(:strip, :type => :rvalue, :doc => <<-DOC + newfunction(:strip, type: :rvalue, doc: <<-DOC @summary This function removes leading and trailing whitespace from a string or from every string inside an array. @@ -18,8 +20,7 @@ module Puppet::Parser::Functions > *Note:*: from Puppet 6.0.0, the compatible function with the same name in Puppet core will be used instead of this function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "strip(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/suffix.rb b/lib/puppet/parser/functions/suffix.rb index 643d7223a..5c519ba93 100644 --- a/lib/puppet/parser/functions/suffix.rb +++ b/lib/puppet/parser/functions/suffix.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # suffix.rb # module Puppet::Parser::Functions - newfunction(:suffix, :type => :rvalue, :doc => <<-DOC + newfunction(:suffix, type: :rvalue, doc: <<-DOC @summary This function applies a suffix to all elements in an array, or to the keys in a hash. @@ -21,8 +23,7 @@ module Puppet::Parser::Functions ```['a', 'b', 'c'].map |$x| { "${x}p" }``` DOC - ) do |arguments| - + ) do |arguments| # Technically we support two arguments but only first is mandatory ... raise(Puppet::ParseError, "suffix(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? diff --git a/lib/puppet/parser/functions/swapcase.rb b/lib/puppet/parser/functions/swapcase.rb index dd17330b3..cddd289fe 100644 --- a/lib/puppet/parser/functions/swapcase.rb +++ b/lib/puppet/parser/functions/swapcase.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # swapcase.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:swapcase, :type => :rvalue, :doc => <<-DOC + newfunction(:swapcase, type: :rvalue, doc: <<-DOC @summary This function will swap the existing case of a string. @@ -15,8 +17,7 @@ module Puppet::Parser::Functions swapcase("aBcD") Would result in: "AbCd" DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "swapcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/time.rb b/lib/puppet/parser/functions/time.rb index d123cf68a..e154643f3 100644 --- a/lib/puppet/parser/functions/time.rb +++ b/lib/puppet/parser/functions/time.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # time.rb # module Puppet::Parser::Functions - newfunction(:time, :type => :rvalue, :doc => <<-DOC + newfunction(:time, type: :rvalue, doc: <<-DOC @summary This function will return the current time since epoch as an integer. @@ -21,8 +23,7 @@ module Puppet::Parser::Functions ```Timestamp()``` DOC - ) do |arguments| - + ) do |arguments| # The Time Zone argument is optional ... time_zone = arguments[0] if arguments[0] diff --git a/lib/puppet/parser/functions/to_bytes.rb b/lib/puppet/parser/functions/to_bytes.rb index b7de587ff..b1beb5fe8 100644 --- a/lib/puppet/parser/functions/to_bytes.rb +++ b/lib/puppet/parser/functions/to_bytes.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # to_bytes.rb # module Puppet::Parser::Functions - newfunction(:to_bytes, :type => :rvalue, :doc => <<-DOC + newfunction(:to_bytes, type: :rvalue, doc: <<-DOC @summary Converts the argument into bytes, for example 4 kB becomes 4096. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions These conversions reflect a layperson's understanding of 1 MB = 1024 KB, when in fact 1 MB = 1000 KB, and 1 MiB = 1024 KiB. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 arg = arguments[0] diff --git a/lib/puppet/parser/functions/try_get_value.rb b/lib/puppet/parser/functions/try_get_value.rb index 26c0b2d77..8df953089 100644 --- a/lib/puppet/parser/functions/try_get_value.rb +++ b/lib/puppet/parser/functions/try_get_value.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + # # try_get_value.rb # module Puppet::Parser::Functions newfunction( :try_get_value, - :type => :rvalue, - :arity => -2, - :doc => <<-DOC + type: :rvalue, + arity: -2, + doc: <<-DOC, @summary **DEPRECATED:** this function is deprecated, please use dig() instead. diff --git a/lib/puppet/parser/functions/type.rb b/lib/puppet/parser/functions/type.rb index 6b0140827..57dd3e133 100644 --- a/lib/puppet/parser/functions/type.rb +++ b/lib/puppet/parser/functions/type.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # type.rb # module Puppet::Parser::Functions - newfunction(:type, :type => :rvalue, :doc => <<-DOC + newfunction(:type, type: :rvalue, doc: <<-DOC @summary **DEPRECATED:** This function will cease to function on Puppet 4; please use type3x() before upgrading to Puppet 4 for backwards-compatibility, or migrate to the new parser's typing system. @@ -16,9 +18,8 @@ module Puppet::Parser::Functions * integer * boolean DOC - ) do |args| - - warning("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : Cannot reduce line length + ) do |args| + warning("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Layout/LineLength : Cannot reduce line length unless Puppet::Parser::Functions.autoloader.loaded?(:type3x) Puppet::Parser::Functions.autoloader.load(:type3x) end diff --git a/lib/puppet/parser/functions/type3x.rb b/lib/puppet/parser/functions/type3x.rb index e8d90d838..49903b905 100644 --- a/lib/puppet/parser/functions/type3x.rb +++ b/lib/puppet/parser/functions/type3x.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # type3x.rb # module Puppet::Parser::Functions - newfunction(:type3x, :type => :rvalue, :doc => <<-DOC + newfunction(:type3x, type: :rvalue, doc: <<-DOC @summary **DEPRECATED:** This function will be removed when Puppet 3 support is dropped; please migrate to the new parser's typing system. @@ -15,7 +17,7 @@ module Puppet::Parser::Functions * integer * boolean DOC - ) do |args| + ) do |args| raise(Puppet::ParseError, "type3x(): Wrong number of arguments given (#{args.size} for 1)") unless args.size == 1 value = args[0] diff --git a/lib/puppet/parser/functions/union.rb b/lib/puppet/parser/functions/union.rb index ac521e55c..353e51e8e 100644 --- a/lib/puppet/parser/functions/union.rb +++ b/lib/puppet/parser/functions/union.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # union.rb # module Puppet::Parser::Functions - newfunction(:union, :type => :rvalue, :doc => <<-DOC + newfunction(:union, type: :rvalue, doc: <<-DOC @summary This function returns a union of two or more arrays. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions union(["a","b","c"],["b","c","d"]) Would return: ["a","b","c","d"] DOC - ) do |arguments| - + ) do |arguments| # Check that 2 or more arguments have been given ... raise(Puppet::ParseError, "union(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2 diff --git a/lib/puppet/parser/functions/unique.rb b/lib/puppet/parser/functions/unique.rb index c9eaa08ef..7efdaa39e 100644 --- a/lib/puppet/parser/functions/unique.rb +++ b/lib/puppet/parser/functions/unique.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # unique.rb # module Puppet::Parser::Functions - newfunction(:unique, :type => :rvalue, :doc => <<-DOC + newfunction(:unique, type: :rvalue, doc: <<-DOC @summary This function will remove duplicates from strings and arrays. @@ -20,8 +22,7 @@ module Puppet::Parser::Functions This returns: ["a","b","c"] DOC - ) do |arguments| - + ) do |arguments| if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0 function_deprecation([:unique, 'This method is deprecated, please use the core puppet unique function. There is further documentation for the function in the release notes of Puppet 5.0.']) end diff --git a/lib/puppet/parser/functions/unix2dos.rb b/lib/puppet/parser/functions/unix2dos.rb index 91b259672..95d9dfc50 100644 --- a/lib/puppet/parser/functions/unix2dos.rb +++ b/lib/puppet/parser/functions/unix2dos.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + # Custom Puppet function to convert unix to dos format module Puppet::Parser::Functions - newfunction(:unix2dos, :type => :rvalue, :arity => 1, :doc => <<-DOC + newfunction(:unix2dos, type: :rvalue, arity: 1, doc: <<-DOC @summary Returns the DOS version of the given string. @@ -9,8 +11,7 @@ module Puppet::Parser::Functions Takes a single string argument. DOC - ) do |arguments| - + ) do |arguments| unless arguments[0].is_a?(String) raise(Puppet::ParseError, 'unix2dos(): Requires string as argument') end diff --git a/lib/puppet/parser/functions/upcase.rb b/lib/puppet/parser/functions/upcase.rb index de0797039..a7685d1e0 100644 --- a/lib/puppet/parser/functions/upcase.rb +++ b/lib/puppet/parser/functions/upcase.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + # # upcase.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:upcase, :type => :rvalue, :doc => <<-DOC + newfunction(:upcase, type: :rvalue, doc: <<-DOC @summary Converts a string or an array of strings to uppercase. @@ -18,8 +20,7 @@ module Puppet::Parser::Functions > *Note:* from Puppet 6.0.0, the compatible function with the same name in Puppet core will be used instead of this function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "upcase(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.size != 1 value = arguments[0] diff --git a/lib/puppet/parser/functions/uriescape.rb b/lib/puppet/parser/functions/uriescape.rb index 4078b86c4..b7de4c1e4 100644 --- a/lib/puppet/parser/functions/uriescape.rb +++ b/lib/puppet/parser/functions/uriescape.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'uri' # # uriescape.rb # Please note: This function is an implementation of a Ruby class and as such may not be entirely UTF8 compatible. To ensure compatibility please use this function with Ruby 2.4.0 or greater - https://bugs.ruby-lang.org/issues/10085. # module Puppet::Parser::Functions - newfunction(:uriescape, :type => :rvalue, :doc => <<-DOC + newfunction(:uriescape, type: :rvalue, doc: <<-DOC @summary Urlencodes a string or array of strings. Requires either a single string or an array as an input. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions a string that contains the converted value DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "uriescape(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? value = arguments[0] diff --git a/lib/puppet/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb index 7d794452f..e0ea72b4c 100644 --- a/lib/puppet/parser/functions/validate_absolute_path.rb +++ b/lib/puppet/parser/functions/validate_absolute_path.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_absolute_path.rb # module Puppet::Parser::Functions - newfunction(:validate_absolute_path, :doc => <<-DOC) do |args| + newfunction(:validate_absolute_path, doc: <<-DOC) do |args| @summary Validate the string represents an absolute path in the filesystem. This function works for windows and unix style paths. diff --git a/lib/puppet/parser/functions/validate_array.rb b/lib/puppet/parser/functions/validate_array.rb index d24f75e48..15cbc4480 100644 --- a/lib/puppet/parser/functions/validate_array.rb +++ b/lib/puppet/parser/functions/validate_array.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_array.rb # module Puppet::Parser::Functions - newfunction(:validate_array, :doc => <<-DOC) do |args| + newfunction(:validate_array, doc: <<-DOC) do |args| @summary Validate that all passed values are array data structures. Abort catalog compilation if any value fails this check. diff --git a/lib/puppet/parser/functions/validate_augeas.rb b/lib/puppet/parser/functions/validate_augeas.rb index 26e51e8ff..55f932f29 100644 --- a/lib/puppet/parser/functions/validate_augeas.rb +++ b/lib/puppet/parser/functions/validate_augeas.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'tempfile' # # validate_augaes.rb # module Puppet::Parser::Functions - newfunction(:validate_augeas, :doc => <<-DOC + newfunction(:validate_augeas, doc: <<-DOC @summary Perform validation of a string using an Augeas lens @@ -40,7 +42,7 @@ module Puppet::Parser::Functions validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') DOC - ) do |args| + ) do |args| unless Puppet.features.augeas? raise Puppet::ParseError, 'validate_augeas(): this function requires the augeas feature. See http://docs.puppetlabs.com/guides/augeas.html#pre-requisites for how to activate it.' end @@ -67,9 +69,9 @@ module Puppet::Parser::Functions # Check for syntax lens = args[1] aug.transform( - :lens => lens, - :name => 'Validate_augeas', - :incl => tmpfile.path, + lens: lens, + name: 'Validate_augeas', + incl: tmpfile.path, ) aug.load! diff --git a/lib/puppet/parser/functions/validate_bool.rb b/lib/puppet/parser/functions/validate_bool.rb index d6f07af00..125d26278 100644 --- a/lib/puppet/parser/functions/validate_bool.rb +++ b/lib/puppet/parser/functions/validate_bool.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_bool.rb # module Puppet::Parser::Functions - newfunction(:validate_bool, :doc => <<-DOC + newfunction(:validate_bool, doc: <<-DOC @summary Validate that all passed values are either true or false. Abort catalog compilation if any value fails this check. @@ -25,7 +27,7 @@ module Puppet::Parser::Functions validate_bool("true") validate_bool($some_array) DOC - ) do |args| + ) do |args| if args.empty? raise Puppet::ParseError, "validate_bool(): wrong number of arguments (#{args.length}; must be > 0)" end diff --git a/lib/puppet/parser/functions/validate_cmd.rb b/lib/puppet/parser/functions/validate_cmd.rb index 592d0ee32..16b4ab932 100644 --- a/lib/puppet/parser/functions/validate_cmd.rb +++ b/lib/puppet/parser/functions/validate_cmd.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'puppet/util/execution' require 'tempfile' @@ -5,7 +7,7 @@ # validate_cmd.rb # module Puppet::Parser::Functions - newfunction(:validate_cmd, :doc => <<-DOC + newfunction(:validate_cmd, doc: <<-DOC @summary Perform validation of a string with an external command. @@ -31,7 +33,7 @@ module Puppet::Parser::Functions validate_cmd($haproxycontent, '/usr/sbin/haproxy -f % -c', 'Haproxy failed to validate config content') DOC - ) do |args| + ) do |args| if (args.length < 2) || (args.length > 3) raise Puppet::ParseError, "validate_cmd(): wrong number of arguments (#{args.length}; must be 2 or 3)" end @@ -47,7 +49,7 @@ module Puppet::Parser::Functions tmpfile.write(content) tmpfile.close - check_with_correct_location = if checkscript =~ %r{\s%(\s|$)} + check_with_correct_location = if %r{\s%(\s|$)}.match?(checkscript) checkscript.gsub(%r{%}, tmpfile.path) else "#{checkscript} #{tmpfile.path}" diff --git a/lib/puppet/parser/functions/validate_domain_name.rb b/lib/puppet/parser/functions/validate_domain_name.rb index f3dc1d5f1..0ed576f16 100644 --- a/lib/puppet/parser/functions/validate_domain_name.rb +++ b/lib/puppet/parser/functions/validate_domain_name.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_domain_name.rb # module Puppet::Parser::Functions - newfunction(:validate_domain_name, :doc => <<-DOC + newfunction(:validate_domain_name, doc: <<-DOC @summary Validate that all values passed are syntactically correct domain names. Fail compilation if any value fails this check. @@ -26,8 +28,7 @@ module Puppet::Parser::Functions validate_domain_name('-foo.example.com') validate_domain_name('www.example.2com') DOC - ) do |args| - + ) do |args| rescuable_exceptions = [ArgumentError] if args.empty? diff --git a/lib/puppet/parser/functions/validate_email_address.rb b/lib/puppet/parser/functions/validate_email_address.rb index 5ad983a30..ae847b591 100644 --- a/lib/puppet/parser/functions/validate_email_address.rb +++ b/lib/puppet/parser/functions/validate_email_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_email_address.rb # module Puppet::Parser::Functions - newfunction(:validate_email_address, :doc => <<-DOC + newfunction(:validate_email_address, doc: <<-DOC @summary Validate that all values passed are valid email addresses. Fail compilation if any value fails this check. @@ -23,7 +25,7 @@ module Puppet::Parser::Functions $some_array = [ 'bad_email@/d/efdf.com' ] validate_email_address($some_array) DOC - ) do |args| + ) do |args| rescuable_exceptions = [ArgumentError] if args.empty? diff --git a/lib/puppet/parser/functions/validate_hash.rb b/lib/puppet/parser/functions/validate_hash.rb index c3b0dfdc6..c34f1e4bc 100644 --- a/lib/puppet/parser/functions/validate_hash.rb +++ b/lib/puppet/parser/functions/validate_hash.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_hash.rb # module Puppet::Parser::Functions - newfunction(:validate_hash, :doc => <<-DOC + newfunction(:validate_hash, doc: <<-DOC @summary Validate that all passed values are hash data structures. Abort catalog compilation if any value fails this check. @@ -24,8 +26,7 @@ module Puppet::Parser::Functions $undefined = undef validate_hash($undefined) DOC - ) do |args| - + ) do |args| function_deprecation([:validate_hash, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb index 6a56d5c71..4ec05b0bb 100644 --- a/lib/puppet/parser/functions/validate_integer.rb +++ b/lib/puppet/parser/functions/validate_integer.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_interger.rb # module Puppet::Parser::Functions - newfunction(:validate_integer, :doc => <<-DOC + newfunction(:validate_integer, doc: <<-DOC @summary Validate that the first argument is an integer (or an array of integers). Abort catalog compilation if any of the checks fail. @@ -58,7 +60,7 @@ module Puppet::Parser::Functions Plus all of the above, but with non-integer items in arrays or maximum / minimum argument. DOC - ) do |args| + ) do |args| function_deprecation([:validate_integer, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_ip_address.rb b/lib/puppet/parser/functions/validate_ip_address.rb index 3fd582b0e..32400e2b8 100644 --- a/lib/puppet/parser/functions/validate_ip_address.rb +++ b/lib/puppet/parser/functions/validate_ip_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_ip_address.rb # module Puppet::Parser::Functions - newfunction(:validate_ip_address, :doc => <<-DOC + newfunction(:validate_ip_address, doc: <<-DOC @summary Validate that all values passed are valid IP addresses, regardless they are IPv4 or IPv6 @@ -28,8 +30,7 @@ module Puppet::Parser::Functions $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] validate_ip_address($some_array) DOC - ) do |args| - + ) do |args| require 'ipaddr' rescuable_exceptions = [ArgumentError] diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb index 1f3223fab..9e86690e3 100644 --- a/lib/puppet/parser/functions/validate_ipv4_address.rb +++ b/lib/puppet/parser/functions/validate_ipv4_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_ipv4_address.rb # module Puppet::Parser::Functions - newfunction(:validate_ipv4_address, :doc => <<-DOC + newfunction(:validate_ipv4_address, doc: <<-DOC @summary Validate that all values passed are valid IPv4 addresses. Fail compilation if any value fails this check. @@ -22,8 +24,7 @@ module Puppet::Parser::Functions $some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ] validate_ipv4_address($some_array) DOC - ) do |args| - + ) do |args| function_deprecation([:validate_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_ipv6_address.rb b/lib/puppet/parser/functions/validate_ipv6_address.rb index b1f33fedc..3596e6959 100644 --- a/lib/puppet/parser/functions/validate_ipv6_address.rb +++ b/lib/puppet/parser/functions/validate_ipv6_address.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_ipv7_address.rb # module Puppet::Parser::Functions - newfunction(:validate_ipv6_address, :doc => <<-DOC + newfunction(:validate_ipv6_address, doc: <<-DOC @summary Validate that all values passed are valid IPv6 addresses. Fail compilation if any value fails this check. @@ -24,8 +26,7 @@ module Puppet::Parser::Functions validate_ipv6_address($some_array) DOC - ) do |args| - + ) do |args| function_deprecation([:validate_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb index 6ccdb0e96..1bbc6672f 100644 --- a/lib/puppet/parser/functions/validate_numeric.rb +++ b/lib/puppet/parser/functions/validate_numeric.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_numeric.rb # module Puppet::Parser::Functions - newfunction(:validate_numeric, :doc => <<-DOC + newfunction(:validate_numeric, doc: <<-DOC @summary Validate that the first argument is a numeric value (or an array of numeric values). Abort catalog compilation if any of the checks fail. @@ -18,7 +20,7 @@ module Puppet::Parser::Functions For passing and failing usage, see `validate_integer()`. It is all the same for validate_numeric, yet now floating point values are allowed, too. DOC - ) do |args| + ) do |args| function_deprecation([:validate_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_re.rb b/lib/puppet/parser/functions/validate_re.rb index 14ad7abd4..f11628004 100644 --- a/lib/puppet/parser/functions/validate_re.rb +++ b/lib/puppet/parser/functions/validate_re.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate.rb # module Puppet::Parser::Functions - newfunction(:validate_re, :doc => <<-DOC + newfunction(:validate_re, doc: <<-DOC @summary Perform simple validation of a string against one or more regular expressions. @@ -37,7 +39,7 @@ module Puppet::Parser::Functions quotes to force stringification: validate_re("${::operatingsystemmajrelease}", '^[57]$') DOC - ) do |args| + ) do |args| function_deprecation([:validate_re, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Re. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_slength.rb b/lib/puppet/parser/functions/validate_slength.rb index c28650fcd..c7d5bb6c3 100644 --- a/lib/puppet/parser/functions/validate_slength.rb +++ b/lib/puppet/parser/functions/validate_slength.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_slength.rb # module Puppet::Parser::Functions - newfunction(:validate_slength, :doc => <<-DOC + newfunction(:validate_slength, doc: <<-DOC @summary Validate that the first argument is a string (or an array of strings), and less/equal to than the length of the second argument. An optional third parameter can be given the minimum length. It fails if the first argument is not a string or array of strings, @@ -24,7 +26,7 @@ module Puppet::Parser::Functions validate_slength(["discombobulate","thermometer"],5) validate_slength(["discombobulate","moo"],17,10) DOC - ) do |args| + ) do |args| function_deprecation([:validate_slength, 'This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb index f6c52a711..6dd9634b9 100644 --- a/lib/puppet/parser/functions/validate_string.rb +++ b/lib/puppet/parser/functions/validate_string.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_String.rb # module Puppet::Parser::Functions - newfunction(:validate_string, :doc => <<-DOC + newfunction(:validate_string, doc: <<-DOC @summary Validate that all passed values are string data structures @@ -29,7 +31,7 @@ module Puppet::Parser::Functions } ``` DOC - ) do |args| + ) do |args| function_deprecation([:validate_string, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.']) diff --git a/lib/puppet/parser/functions/validate_x509_rsa_key_pair.rb b/lib/puppet/parser/functions/validate_x509_rsa_key_pair.rb index 93388e0d0..a62ba3753 100644 --- a/lib/puppet/parser/functions/validate_x509_rsa_key_pair.rb +++ b/lib/puppet/parser/functions/validate_x509_rsa_key_pair.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # validate_x509_rsa_key_pair.rb # module Puppet::Parser::Functions - newfunction(:validate_x509_rsa_key_pair, :doc => <<-DOC + newfunction(:validate_x509_rsa_key_pair, doc: <<-DOC @summary Validates a PEM-formatted X.509 certificate and RSA private key using OpenSSL. Verifies that the certficate's signature was created from the @@ -14,8 +16,7 @@ module Puppet::Parser::Functions ```validate_x509_rsa_key_pair($cert, $key)``` DOC - ) do |args| - + ) do |args| require 'openssl' NUM_ARGS = 2 unless defined? NUM_ARGS diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb index 434ce6c91..a47fe5277 100644 --- a/lib/puppet/parser/functions/values.rb +++ b/lib/puppet/parser/functions/values.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # values.rb # module Puppet::Parser::Functions - newfunction(:values, :type => :rvalue, :doc => <<-DOC + newfunction(:values, type: :rvalue, doc: <<-DOC @summary When given a hash this function will return the values of that hash. @@ -24,8 +26,7 @@ module Puppet::Parser::Functions will be used instead of this function. DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "values(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? hash = arguments[0] diff --git a/lib/puppet/parser/functions/values_at.rb b/lib/puppet/parser/functions/values_at.rb index 337104207..29301b8e1 100644 --- a/lib/puppet/parser/functions/values_at.rb +++ b/lib/puppet/parser/functions/values_at.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # values_at.rb # module Puppet::Parser::Functions - newfunction(:values_at, :type => :rvalue, :doc => <<-DOC + newfunction(:values_at, type: :rvalue, doc: <<-DOC @summary Finds value inside an array based on location. @@ -36,8 +38,7 @@ module Puppet::Parser::Functions `['a', 'b', 'c', 'd'][1, -2]` results in `['b', 'c']` DOC - ) do |arguments| - + ) do |arguments| raise(Puppet::ParseError, "values_at(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 array = arguments.shift @@ -74,7 +75,7 @@ module Puppet::Parser::Functions range.each { |i| indices_list << i.to_i } # rubocop:disable Lint/ShadowingOuterLocalVariable : Value is meant to be shadowed else # Only positive numbers allowed in this case ... - unless i =~ %r{^\d+$} + unless %r{^\d+$}.match?(i) raise(Puppet::ParseError, 'values_at(): Unknown format of given index') end diff --git a/lib/puppet/parser/functions/zip.rb b/lib/puppet/parser/functions/zip.rb index 120d09720..100618340 100644 --- a/lib/puppet/parser/functions/zip.rb +++ b/lib/puppet/parser/functions/zip.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + # # zip.rb # module Puppet::Parser::Functions - newfunction(:zip, :type => :rvalue, :doc => <<-DOC + newfunction(:zip, type: :rvalue, doc: <<-DOC @summary Takes one element from first array and merges corresponding elements from second array. @@ -13,8 +15,7 @@ module Puppet::Parser::Functions zip(['1','2','3'],['4','5','6']) Would result in: ["1", "4"], ["2", "5"], ["3", "6"] DOC - ) do |arguments| - + ) do |arguments| # Technically we support three arguments but only first is mandatory ... raise(Puppet::ParseError, "zip(): Wrong number of arguments given (#{arguments.size} for 2)") if arguments.size < 2 diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb index f85ae85f8..41e053168 100644 --- a/lib/puppet/provider/file_line/ruby.rb +++ b/lib/puppet/provider/file_line/ruby.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Type.type(:file_line).provide(:ruby) do desc <<-DOC @summary @@ -77,7 +79,7 @@ def lines # small-ish config files that can fit into memory without # too much trouble. - @lines ||= File.readlines(resource[:path], :encoding => resource[:encoding]) + @lines ||= File.readlines(resource[:path], encoding: resource[:encoding]) rescue TypeError => _e # Ruby 1.8 doesn't support open_args @lines ||= File.readlines(resource[:path]) @@ -92,13 +94,13 @@ def new_match_regex end def count_matches(regex) - lines.select { |line| + lines.count do |line| if resource[:replace_all_matches_not_matching_line].to_s == 'true' line.match(regex) unless line.chomp == resource[:line] else line.match(regex) end - }.size + end end def handle_create_with_match diff --git a/lib/puppet/type/anchor.rb b/lib/puppet/type/anchor.rb index 7458a4b98..8bd35d747 100644 --- a/lib/puppet/type/anchor.rb +++ b/lib/puppet/type/anchor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:anchor) do desc <<-DOC @summary diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb index ead6b1033..00a6512cb 100644 --- a/lib/puppet/type/file_line.rb +++ b/lib/puppet/type/file_line.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Puppet::Type.newtype(:file_line) do desc <<-DOC @summary @@ -104,7 +106,7 @@ defaultto :present end - newparam(:name, :namevar => true) do + newparam(:name, namevar: true) do desc 'An arbitrary name used as the identity of the resource.' end diff --git a/spec/acceptance/anchor_spec.rb b/spec/acceptance/anchor_spec.rb index fda167425..9136b6623 100644 --- a/spec/acceptance/anchor_spec.rb +++ b/spec/acceptance/anchor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'anchor type' do diff --git a/spec/acceptance/file_line_spec.rb b/spec/acceptance/file_line_spec.rb index d8068deb3..a322ab111 100644 --- a/spec/acceptance/file_line_spec.rb +++ b/spec/acceptance/file_line_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper_acceptance' describe 'file_line type' do diff --git a/spec/functions/abs_spec.rb b/spec/functions/abs_spec.rb index 24dfa2fda..00448640e 100644 --- a/spec/functions/abs_spec.rb +++ b/spec/functions/abs_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 describe 'abs' do diff --git a/spec/functions/any2array_spec.rb b/spec/functions/any2array_spec.rb index a7956722e..7ddf67b47 100644 --- a/spec/functions/any2array_spec.rb +++ b/spec/functions/any2array_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'any2array' do diff --git a/spec/functions/any2bool_spec.rb b/spec/functions/any2bool_spec.rb index 4de9d216f..ff06a689d 100644 --- a/spec/functions/any2bool_spec.rb +++ b/spec/functions/any2bool_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'any2bool' do @@ -34,7 +36,7 @@ end describe 'everything else returns true' do - [[], {}, ['1'], [1], { :one => 1 }].each do |value| + [[], {}, ['1'], [1], { one: 1 }].each do |value| it { is_expected.to run.with_params(value).and_return(true) } end end diff --git a/spec/functions/assert_private_spec.rb b/spec/functions/assert_private_spec.rb index ee7db0b23..cb1e896bb 100644 --- a/spec/functions/assert_private_spec.rb +++ b/spec/functions/assert_private_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'assert_private' do diff --git a/spec/functions/base64_spec.rb b/spec/functions/base64_spec.rb index dafab360c..3a1081190 100644 --- a/spec/functions/base64_spec.rb +++ b/spec/functions/base64_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'base64' do diff --git a/spec/functions/basename_spec.rb b/spec/functions/basename_spec.rb index a2a12a1f8..3f520602a 100644 --- a/spec/functions/basename_spec.rb +++ b/spec/functions/basename_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'basename' do diff --git a/spec/functions/bool2num_spec.rb b/spec/functions/bool2num_spec.rb index 7402f3a9f..63a664b6b 100644 --- a/spec/functions/bool2num_spec.rb +++ b/spec/functions/bool2num_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'bool2num' do diff --git a/spec/functions/bool2str_spec.rb b/spec/functions/bool2str_spec.rb index 8d8f9b5bc..013d5514f 100644 --- a/spec/functions/bool2str_spec.rb +++ b/spec/functions/bool2str_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'bool2str' do diff --git a/spec/functions/camelcase_spec.rb b/spec/functions/camelcase_spec.rb index e0e4003b7..aa78fcbdc 100644 --- a/spec/functions/camelcase_spec.rb +++ b/spec/functions/camelcase_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'camelcase', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'camelcase', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/capitalize_spec.rb b/spec/functions/capitalize_spec.rb index dd5fc354b..f67c8beff 100644 --- a/spec/functions/capitalize_spec.rb +++ b/spec/functions/capitalize_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'capitalize', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'capitalize', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError) } diff --git a/spec/functions/ceiling_spec.rb b/spec/functions/ceiling_spec.rb index 7f9a0450a..5e5f34c94 100644 --- a/spec/functions/ceiling_spec.rb +++ b/spec/functions/ceiling_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'ceiling', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'ceiling', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError, %r{Wrong argument type given}) } diff --git a/spec/functions/chomp_spec.rb b/spec/functions/chomp_spec.rb index 2137c6166..68b7cd3dc 100644 --- a/spec/functions/chomp_spec.rb +++ b/spec/functions/chomp_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'chomp', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'chomp', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments given}) } it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either array or string}) } diff --git a/spec/functions/chop_spec.rb b/spec/functions/chop_spec.rb index be9098129..2cbccd14d 100644 --- a/spec/functions/chop_spec.rb +++ b/spec/functions/chop_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'chop', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'chop', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires either an array or string}) } diff --git a/spec/functions/clamp_spec.rb b/spec/functions/clamp_spec.rb index 6380b2936..37b4935c9 100644 --- a/spec/functions/clamp_spec.rb +++ b/spec/functions/clamp_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'clamp' do diff --git a/spec/functions/concat_spec.rb b/spec/functions/concat_spec.rb index 9290d407c..d0893e991 100644 --- a/spec/functions/concat_spec.rb +++ b/spec/functions/concat_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'concat' do diff --git a/spec/functions/convert_base_spec.rb b/spec/functions/convert_base_spec.rb index d1a6cef14..a2de736c9 100644 --- a/spec/functions/convert_base_spec.rb +++ b/spec/functions/convert_base_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'convert_base' do diff --git a/spec/functions/count_spec.rb b/spec/functions/count_spec.rb index 54e1491c4..564974a23 100644 --- a/spec/functions/count_spec.rb +++ b/spec/functions/count_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'count' do diff --git a/spec/functions/deep_merge_spec.rb b/spec/functions/deep_merge_spec.rb index 489bca58e..bd40d6720 100644 --- a/spec/functions/deep_merge_spec.rb +++ b/spec/functions/deep_merge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'deep_merge' do diff --git a/spec/functions/defined_with_params_spec.rb b/spec/functions/defined_with_params_spec.rb index 36a627d3a..e372cd319 100644 --- a/spec/functions/defined_with_params_spec.rb +++ b/spec/functions/defined_with_params_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'defined_with_params' do diff --git a/spec/functions/delete_at_spec.rb b/spec/functions/delete_at_spec.rb index 89359b1b8..7bc714044 100644 --- a/spec/functions/delete_at_spec.rb +++ b/spec/functions/delete_at_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'delete_at' do diff --git a/spec/functions/delete_regex_spec.rb b/spec/functions/delete_regex_spec.rb index 8e16b0b3d..ab9516f1b 100644 --- a/spec/functions/delete_regex_spec.rb +++ b/spec/functions/delete_regex_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'delete_regex' do diff --git a/spec/functions/delete_spec.rb b/spec/functions/delete_spec.rb index df5ee7a40..5fe782513 100644 --- a/spec/functions/delete_spec.rb +++ b/spec/functions/delete_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'delete' do diff --git a/spec/functions/delete_undef_values_spec.rb b/spec/functions/delete_undef_values_spec.rb index 129457949..068217f61 100644 --- a/spec/functions/delete_undef_values_spec.rb +++ b/spec/functions/delete_undef_values_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'delete_undef_values' do diff --git a/spec/functions/delete_values_spec.rb b/spec/functions/delete_values_spec.rb index 3ee3af13c..4a488934a 100644 --- a/spec/functions/delete_values_spec.rb +++ b/spec/functions/delete_values_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'delete_values' do diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb index 50203c9b0..d03b5e2d2 100644 --- a/spec/functions/deprecation_spec.rb +++ b/spec/functions/deprecation_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/functions/difference_spec.rb b/spec/functions/difference_spec.rb index b30437e71..292023c19 100644 --- a/spec/functions/difference_spec.rb +++ b/spec/functions/difference_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'difference' do diff --git a/spec/functions/dig44_spec.rb b/spec/functions/dig44_spec.rb index e7c6d817c..576935f3f 100644 --- a/spec/functions/dig44_spec.rb +++ b/spec/functions/dig44_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'dig44' do diff --git a/spec/functions/dig_spec.rb b/spec/functions/dig_spec.rb index ac2b6e443..a11ab7ec6 100644 --- a/spec/functions/dig_spec.rb +++ b/spec/functions/dig_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'dig' do diff --git a/spec/functions/dirname_spec.rb b/spec/functions/dirname_spec.rb index cda15c8d7..a801f1c1f 100644 --- a/spec/functions/dirname_spec.rb +++ b/spec/functions/dirname_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'dirname' do diff --git a/spec/functions/dos2unix_spec.rb b/spec/functions/dos2unix_spec.rb index 4b04f5bba..d86d93ba8 100644 --- a/spec/functions/dos2unix_spec.rb +++ b/spec/functions/dos2unix_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'dos2unix' do diff --git a/spec/functions/downcase_spec.rb b/spec/functions/downcase_spec.rb index 181e282b9..07c6374c3 100644 --- a/spec/functions/downcase_spec.rb +++ b/spec/functions/downcase_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'downcase', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'downcase', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } it { is_expected.to run.with_params(100).and_raise_error(Puppet::ParseError, %r{Requires either array or string}) } diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb index 695c8a5ad..5b0ba29cd 100644 --- a/spec/functions/empty_spec.rb +++ b/spec/functions/empty_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'empty', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do +describe 'empty', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } it { diff --git a/spec/functions/end_with_spec.rb b/spec/functions/end_with_spec.rb index 5c1e8a974..19c4ed68a 100644 --- a/spec/functions/end_with_spec.rb +++ b/spec/functions/end_with_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'stdlib::end_with' do diff --git a/spec/functions/ensure_packages_spec.rb b/spec/functions/ensure_packages_spec.rb index 6d1a84181..1f6b85db0 100644 --- a/spec/functions/ensure_packages_spec.rb +++ b/spec/functions/ensure_packages_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'ensure_packages' do diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb index 9bbfaccf8..b7266f75b 100644 --- a/spec/functions/ensure_resource_spec.rb +++ b/spec/functions/ensure_resource_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'ensure_resource' do diff --git a/spec/functions/ensure_resources_spec.rb b/spec/functions/ensure_resources_spec.rb index 10a27bfd4..55dac3d67 100644 --- a/spec/functions/ensure_resources_spec.rb +++ b/spec/functions/ensure_resources_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'ensure_resources' do diff --git a/spec/functions/extname_spec.rb b/spec/functions/extname_spec.rb index 0a8d3caf7..4808e11b4 100644 --- a/spec/functions/extname_spec.rb +++ b/spec/functions/extname_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'stdlib::extname' do diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb index 0b08f35fd..365535baa 100644 --- a/spec/functions/flatten_spec.rb +++ b/spec/functions/flatten_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'flatten', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do +describe 'flatten', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } diff --git a/spec/functions/floor_spec.rb b/spec/functions/floor_spec.rb index e87a601f9..fe45142f0 100644 --- a/spec/functions/floor_spec.rb +++ b/spec/functions/floor_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'floor', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'floor', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } it { is_expected.to run.with_params('foo').and_raise_error(Puppet::ParseError, %r{Wrong argument type}) } diff --git a/spec/functions/fqdn_rand_string_spec.rb b/spec/functions/fqdn_rand_string_spec.rb index d5d3fbf57..1102b87f8 100644 --- a/spec/functions/fqdn_rand_string_spec.rb +++ b/spec/functions/fqdn_rand_string_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'fqdn_rand_string' do @@ -28,22 +30,22 @@ end it 'considers the same host and same extra arguments to have the same random sequence' do - first_random = fqdn_rand_string(10, :extra_identifier => [1, 'same', 'host']) - second_random = fqdn_rand_string(10, :extra_identifier => [1, 'same', 'host']) + first_random = fqdn_rand_string(10, extra_identifier: [1, 'same', 'host']) + second_random = fqdn_rand_string(10, extra_identifier: [1, 'same', 'host']) expect(first_random).to eql(second_random) end it 'allows extra arguments to control the random value on a single host' do - first_random = fqdn_rand_string(10, :extra_identifier => [1, 'different', 'host']) - second_different_random = fqdn_rand_string(10, :extra_identifier => [2, 'different', 'host']) + first_random = fqdn_rand_string(10, extra_identifier: [1, 'different', 'host']) + second_different_random = fqdn_rand_string(10, extra_identifier: [2, 'different', 'host']) expect(first_random).not_to eql(second_different_random) end it 'returns different strings for different hosts' do - val1 = fqdn_rand_string(10, :host => 'first.host.com') - val2 = fqdn_rand_string(10, :host => 'second.host.com') + val1 = fqdn_rand_string(10, host: 'first.host.com') + val2 = fqdn_rand_string(10, host: 'second.host.com') expect(val1).not_to eql(val2) end diff --git a/spec/functions/fqdn_rotate_spec.rb b/spec/functions/fqdn_rotate_spec.rb index 7cd9f1d0b..8c68c3754 100644 --- a/spec/functions/fqdn_rotate_spec.rb +++ b/spec/functions/fqdn_rotate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'fqdn_rotate' do @@ -17,26 +19,26 @@ end it 'rotates a string to give the same results for one host' do - val1 = fqdn_rotate('abcdefg', :host => 'one') - val2 = fqdn_rotate('abcdefg', :host => 'one') + val1 = fqdn_rotate('abcdefg', host: 'one') + val2 = fqdn_rotate('abcdefg', host: 'one') expect(val1).to eq(val2) end it 'allows extra arguments to control the random rotation on a single host' do - val1 = fqdn_rotate('abcdefg', :extra_identifier => [1, 'different', 'host']) - val2 = fqdn_rotate('abcdefg', :extra_identifier => [2, 'different', 'host']) + val1 = fqdn_rotate('abcdefg', extra_identifier: [1, 'different', 'host']) + val2 = fqdn_rotate('abcdefg', extra_identifier: [2, 'different', 'host']) expect(val1).not_to eq(val2) end it 'considers the same host and same extra arguments to have the same random rotation' do - val1 = fqdn_rotate('abcdefg', :extra_identifier => [1, 'same', 'host']) - val2 = fqdn_rotate('abcdefg', :extra_identifier => [1, 'same', 'host']) + val1 = fqdn_rotate('abcdefg', extra_identifier: [1, 'same', 'host']) + val2 = fqdn_rotate('abcdefg', extra_identifier: [1, 'same', 'host']) expect(val1).to eq(val2) end it 'rotates a string to give different values on different hosts' do - val1 = fqdn_rotate('abcdefg', :host => 'one') - val2 = fqdn_rotate('abcdefg', :host => 'two') + val1 = fqdn_rotate('abcdefg', host: 'one') + val2 = fqdn_rotate('abcdefg', host: 'two') expect(val1).not_to eq(val2) end diff --git a/spec/functions/fqdn_uuid_spec.rb b/spec/functions/fqdn_uuid_spec.rb index 60df2e47c..a15751f6f 100644 --- a/spec/functions/fqdn_uuid_spec.rb +++ b/spec/functions/fqdn_uuid_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'fqdn_uuid' do diff --git a/spec/functions/get_module_path_spec.rb b/spec/functions/get_module_path_spec.rb index dd31c6783..1d6d3be1f 100644 --- a/spec/functions/get_module_path_spec.rb +++ b/spec/functions/get_module_path_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'get_module_path' do diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb index 3a3cc274e..d79493b1d 100644 --- a/spec/functions/getparam_spec.rb +++ b/spec/functions/getparam_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'getparam' do diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb index 6c37baafa..94af5187b 100644 --- a/spec/functions/getvar_spec.rb +++ b/spec/functions/getvar_spec.rb @@ -1,14 +1,16 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'getvar' do it { is_expected.not_to eq(nil) } - describe 'before Puppet 6.0.0', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do + describe 'before Puppet 6.0.0', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } end - describe 'from Puppet 6.0.0', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') >= 0 do + describe 'from Puppet 6.0.0', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') >= 0 do it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{expects between 1 and 2 arguments, got none}i) } it { is_expected.to run.with_params('one', 'two').and_return('two') } it { is_expected.to run.with_params('one', 'two', 'three').and_raise_error(ArgumentError, %r{expects between 1 and 2 arguments, got 3}i) } diff --git a/spec/functions/glob_spec.rb b/spec/functions/glob_spec.rb index 209aca6c5..141ee7725 100644 --- a/spec/functions/glob_spec.rb +++ b/spec/functions/glob_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'glob' do diff --git a/spec/functions/grep_spec.rb b/spec/functions/grep_spec.rb index 587e51b8d..b428d2daa 100644 --- a/spec/functions/grep_spec.rb +++ b/spec/functions/grep_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'grep' do diff --git a/spec/functions/has_interface_with_spec.rb b/spec/functions/has_interface_with_spec.rb index 273ecb250..d55f58ead 100644 --- a/spec/functions/has_interface_with_spec.rb +++ b/spec/functions/has_interface_with_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'has_interface_with' do @@ -8,7 +10,7 @@ # We need to mock out the Facts so we can specify how we expect this function # to behave on different platforms. context 'when on Mac OS X Systems' do - let(:facts) { { :interfaces => 'lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0' } } + let(:facts) { { interfaces: 'lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0' } } it { is_expected.to run.with_params('lo0').and_return(true) } it { is_expected.to run.with_params('lo').and_return(false) } @@ -17,13 +19,13 @@ context 'when on Linux Systems' do let(:facts) do { - :interfaces => 'eth0,lo', - :ipaddress => '10.0.0.1', - :ipaddress_lo => '127.0.0.1', - :ipaddress_eth0 => '10.0.0.1', - :muppet => 'kermit', - :muppet_lo => 'mspiggy', - :muppet_eth0 => 'kermit', + interfaces: 'eth0,lo', + ipaddress: '10.0.0.1', + ipaddress_lo: '127.0.0.1', + ipaddress_eth0: '10.0.0.1', + muppet: 'kermit', + muppet_lo: 'mspiggy', + muppet_eth0: 'kermit', } end diff --git a/spec/functions/has_ip_address_spec.rb b/spec/functions/has_ip_address_spec.rb index 8fbde610e..a30a5a5ab 100644 --- a/spec/functions/has_ip_address_spec.rb +++ b/spec/functions/has_ip_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'has_ip_address' do @@ -8,10 +10,10 @@ context 'when on Linux Systems' do let(:facts) do { - :interfaces => 'eth0,lo', - :ipaddress => '10.0.0.1', - :ipaddress_lo => '127.0.0.1', - :ipaddress_eth0 => '10.0.0.1', + interfaces: 'eth0,lo', + ipaddress: '10.0.0.1', + ipaddress_lo: '127.0.0.1', + ipaddress_eth0: '10.0.0.1', } end diff --git a/spec/functions/has_ip_network_spec.rb b/spec/functions/has_ip_network_spec.rb index b9dbde910..3366757a1 100644 --- a/spec/functions/has_ip_network_spec.rb +++ b/spec/functions/has_ip_network_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'has_ip_network' do @@ -8,9 +10,9 @@ context 'when on Linux Systems' do let(:facts) do { - :interfaces => 'eth0,lo', - :network_lo => '127.0.0.0', - :network_eth0 => '10.0.0.0', + interfaces: 'eth0,lo', + network_lo: '127.0.0.0', + network_eth0: '10.0.0.0', } end diff --git a/spec/functions/has_key_spec.rb b/spec/functions/has_key_spec.rb index 6abebba26..882356171 100644 --- a/spec/functions/has_key_spec.rb +++ b/spec/functions/has_key_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'has_key' do diff --git a/spec/functions/hash_spec.rb b/spec/functions/hash_spec.rb index 2f78da4d3..1d678f9aa 100644 --- a/spec/functions/hash_spec.rb +++ b/spec/functions/hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'hash' do diff --git a/spec/functions/intersection_spec.rb b/spec/functions/intersection_spec.rb index 0ea871fb1..2be738f77 100644 --- a/spec/functions/intersection_spec.rb +++ b/spec/functions/intersection_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'intersection' do diff --git a/spec/functions/ip_in_range_spec.rb b/spec/functions/ip_in_range_spec.rb index 01d800ce6..78130de96 100644 --- a/spec/functions/ip_in_range_spec.rb +++ b/spec/functions/ip_in_range_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'stdlib::ip_in_range' do diff --git a/spec/functions/is_a_spec.rb b/spec/functions/is_a_spec.rb index a5fe59089..fd510b277 100644 --- a/spec/functions/is_a_spec.rb +++ b/spec/functions/is_a_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if ENV['FUTURE_PARSER'] == 'yes' diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb index a24c2c70b..63561600f 100644 --- a/spec/functions/is_array_spec.rb +++ b/spec/functions/is_array_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_array' do diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb index 2a8112e67..7c5eddac2 100644 --- a/spec/functions/is_bool_spec.rb +++ b/spec/functions/is_bool_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_bool' do diff --git a/spec/functions/is_domain_name_spec.rb b/spec/functions/is_domain_name_spec.rb index 16caa8ae0..a0221408c 100644 --- a/spec/functions/is_domain_name_spec.rb +++ b/spec/functions/is_domain_name_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_domain_name' do @@ -36,7 +38,7 @@ # Values obtained from Facter values will be frozen strings # in newer versions of Facter: - it { is_expected.to run.with_params('www.example.com'.freeze).and_return(true) } + it { is_expected.to run.with_params('www.example.com').and_return(true) } describe 'top level domain must be alphabetic if there are multiple labels' do it { is_expected.to run.with_params('2com').and_return(true) } diff --git a/spec/functions/is_email_address_spec.rb b/spec/functions/is_email_address_spec.rb index 6c291e65b..c2aeaf3d5 100644 --- a/spec/functions/is_email_address_spec.rb +++ b/spec/functions/is_email_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_email_address' do diff --git a/spec/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb index a231446fa..e80dc4cea 100644 --- a/spec/functions/is_float_spec.rb +++ b/spec/functions/is_float_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_float' do diff --git a/spec/functions/is_function_available_spec.rb b/spec/functions/is_function_available_spec.rb index 4de7f9ea8..3b3965427 100644 --- a/spec/functions/is_function_available_spec.rb +++ b/spec/functions/is_function_available_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_function_available' do diff --git a/spec/functions/is_hash_spec.rb b/spec/functions/is_hash_spec.rb index e154be3e5..126535db6 100644 --- a/spec/functions/is_hash_spec.rb +++ b/spec/functions/is_hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_hash' do diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb index 7e9300568..1de12c9c5 100644 --- a/spec/functions/is_integer_spec.rb +++ b/spec/functions/is_integer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_integer' do diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb index 86f3cf892..208d6459d 100644 --- a/spec/functions/is_ip_address_spec.rb +++ b/spec/functions/is_ip_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_ip_address' do diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb index fddd351da..42986836f 100644 --- a/spec/functions/is_ipv4_address_spec.rb +++ b/spec/functions/is_ipv4_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_ipv4_address' do @@ -12,7 +14,7 @@ it { is_expected.to run.with_params(value).and_return(false) } end - context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do after(:each) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end diff --git a/spec/functions/is_ipv6_address_spec.rb b/spec/functions/is_ipv6_address_spec.rb index c8bad5128..39171336d 100644 --- a/spec/functions/is_ipv6_address_spec.rb +++ b/spec/functions/is_ipv6_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_ipv6_address' do @@ -11,7 +13,7 @@ it { is_expected.to run.with_params('one').and_return(false) } it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334:ggg').and_return(false) } - context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do after(:each) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end diff --git a/spec/functions/is_mac_address_spec.rb b/spec/functions/is_mac_address_spec.rb index 2f6602b7b..3312bb398 100644 --- a/spec/functions/is_mac_address_spec.rb +++ b/spec/functions/is_mac_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_mac_address' do diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb index 6125ecdbb..9c9d9dbf9 100644 --- a/spec/functions/is_numeric_spec.rb +++ b/spec/functions/is_numeric_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_numeric' do diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb index 946305fb9..9a221501c 100644 --- a/spec/functions/is_string_spec.rb +++ b/spec/functions/is_string_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_string' do diff --git a/spec/functions/join_keys_to_values_spec.rb b/spec/functions/join_keys_to_values_spec.rb index 97674ef9e..5d9942e0e 100644 --- a/spec/functions/join_keys_to_values_spec.rb +++ b/spec/functions/join_keys_to_values_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'join_keys_to_values' do diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb index 264ebc945..2175248ab 100644 --- a/spec/functions/join_spec.rb +++ b/spec/functions/join_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'join', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do +describe 'join', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb index 2b538a018..befc834cd 100644 --- a/spec/functions/keys_spec.rb +++ b/spec/functions/keys_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'keys', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do +describe 'keys', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/length_spec.rb b/spec/functions/length_spec.rb index 72ebb6205..183a31c4a 100644 --- a/spec/functions/length_spec.rb +++ b/spec/functions/length_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'length', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do +describe 'length', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'length' expects 1 argument, got none}) } it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, %r{'length' expects 1 argument, got 2}) } diff --git a/spec/functions/load_module_metadata_spec.rb b/spec/functions/load_module_metadata_spec.rb index 45eaa7ee9..caca5e751 100644 --- a/spec/functions/load_module_metadata_spec.rb +++ b/spec/functions/load_module_metadata_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'load_module_metadata' do @@ -9,15 +11,15 @@ before :each do # In Puppet 7, there are two prior calls to File.read prior to the responses we want to mock allow(File).to receive(:read).with(anything, anything).and_call_original - allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}') allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}') # Additional modules used by litmus which are identified while running these dues to being in fixtures - allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, :encoding => 'utf-8') + allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, encoding: 'utf-8') end context 'when calling with valid utf8 and double byte character arguments' do before :each do - allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš - + allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš - この文字"}') allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"ĭďèʼnţĩƒіểя": "ċơņťęאּť ỡƒ ţħíš - この文字"}') diff --git a/spec/functions/loadjson_spec.rb b/spec/functions/loadjson_spec.rb index 48d79fbdf..c45123cc4 100644 --- a/spec/functions/loadjson_spec.rb +++ b/spec/functions/loadjson_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'loadjson' do @@ -8,10 +10,10 @@ before :each do # In Puppet 7, there are two prior calls to File.read prior to the responses we want to mock allow(File).to receive(:read).with(anything, anything).and_call_original - allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, :encoding => 'utf-8').and_return('{"name": "puppetlabs-stdlib"}') + allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}, encoding: 'utf-8').and_return('{"name": "puppetlabs-stdlib"}') allow(File).to receive(:read).with(%r{\/(stdlib|test)\/metadata.json}).and_return('{"name": "puppetlabs-stdlib"}') # Additional modules used by litmus which are identified while running these dues to being in fixtures - allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, :encoding => 'utf-8') + allow(File).to receive(:read).with(%r{\/(provision|puppet_agent|facts)\/metadata.json}, encoding: 'utf-8') end context 'when a non-existing file is specified' do @@ -74,7 +76,7 @@ let(:filename) do 'https://example.local/myhash.json' end - let(:basic_auth) { { :http_basic_authentication => ['', ''] } } + let(:basic_auth) { { http_basic_authentication: ['', ''] } } let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' } @@ -90,7 +92,7 @@ 'https://user1:pass1@example.local/myhash.json' end let(:url_no_auth) { 'https://example.local/myhash.json' } - let(:basic_auth) { { :http_basic_authentication => ['user1', 'pass1'] } } + let(:basic_auth) { { http_basic_authentication: ['user1', 'pass1'] } } let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' } @@ -106,7 +108,7 @@ 'https://user1@example.local/myhash.json' end let(:url_no_auth) { 'https://example.local/myhash.json' } - let(:basic_auth) { { :http_basic_authentication => ['user1', ''] } } + let(:basic_auth) { { http_basic_authentication: ['user1', ''] } } let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } let(:json) { '{"key":"value", {"ķęŷ":"νậŀųề" }, {"キー":"値" }' } @@ -121,7 +123,7 @@ let(:filename) do 'https://example.local/myhash.json' end - let(:basic_auth) { { :http_basic_authentication => ['', ''] } } + let(:basic_auth) { { http_basic_authentication: ['', ''] } } let(:json) { ',;{"key":"value"}' } it { @@ -135,7 +137,7 @@ let(:filename) do 'https://example.local/myhash.json' end - let(:basic_auth) { { :http_basic_authentication => ['', ''] } } + let(:basic_auth) { { http_basic_authentication: ['', ''] } } it { expect(OpenURI).to receive(:open_uri).with(filename, basic_auth).and_raise OpenURI::HTTPError, '404 File not Found' diff --git a/spec/functions/loadyaml_spec.rb b/spec/functions/loadyaml_spec.rb index d71fd32bc..4de82ec35 100644 --- a/spec/functions/loadyaml_spec.rb +++ b/spec/functions/loadyaml_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'loadyaml' do @@ -37,7 +39,7 @@ context 'when an existing URL is specified' do let(:filename) { 'https://example.local/myhash.yaml' } - let(:basic_auth) { { :http_basic_authentication => ['', ''] } } + let(:basic_auth) { { http_basic_authentication: ['', ''] } } let(:yaml) { 'Dummy YAML' } let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } @@ -51,7 +53,7 @@ context 'when an existing URL (with username and password) is specified' do let(:filename) { 'https://user1:pass1@example.local/myhash.yaml' } let(:url_no_auth) { 'https://example.local/myhash.yaml' } - let(:basic_auth) { { :http_basic_authentication => ['user1', 'pass1'] } } + let(:basic_auth) { { http_basic_authentication: ['user1', 'pass1'] } } let(:yaml) { 'Dummy YAML' } let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } @@ -65,7 +67,7 @@ context 'when an existing URL (with username) is specified' do let(:filename) { 'https://user1@example.local/myhash.yaml' } let(:url_no_auth) { 'https://example.local/myhash.yaml' } - let(:basic_auth) { { :http_basic_authentication => ['user1', ''] } } + let(:basic_auth) { { http_basic_authentication: ['user1', ''] } } let(:yaml) { 'Dummy YAML' } let(:data) { { 'key' => 'value', 'ķęŷ' => 'νậŀųề', 'キー' => '値' } } @@ -78,7 +80,7 @@ context 'when an existing URL could not be parsed, with default specified' do let(:filename) { 'https://example.local/myhash.yaml' } - let(:basic_auth) { { :http_basic_authentication => ['', ''] } } + let(:basic_auth) { { http_basic_authentication: ['', ''] } } let(:yaml) { 'Dummy YAML' } it { @@ -90,7 +92,7 @@ context 'when a URL does not exist, with default specified' do let(:filename) { 'https://example.local/myhash.yaml' } - let(:basic_auth) { { :http_basic_authentication => ['', ''] } } + let(:basic_auth) { { http_basic_authentication: ['', ''] } } let(:yaml) { 'Dummy YAML' } it { diff --git a/spec/functions/lstrip_spec.rb b/spec/functions/lstrip_spec.rb index ab2f6f0c4..ee822232d 100644 --- a/spec/functions/lstrip_spec.rb +++ b/spec/functions/lstrip_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'lstrip', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'lstrip', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/max_spec.rb b/spec/functions/max_spec.rb index 88879d19b..b3868d798 100644 --- a/spec/functions/max_spec.rb +++ b/spec/functions/max_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'max', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'max', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { is_expected.to run.with_params(1).and_return(1) } diff --git a/spec/functions/member_spec.rb b/spec/functions/member_spec.rb index 861f6e5f8..f4a5bc216 100644 --- a/spec/functions/member_spec.rb +++ b/spec/functions/member_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'member' do diff --git a/spec/functions/merge_spec.rb b/spec/functions/merge_spec.rb index 7bffaab85..da3e2e7b7 100644 --- a/spec/functions/merge_spec.rb +++ b/spec/functions/merge_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'merge' do diff --git a/spec/functions/min_spec.rb b/spec/functions/min_spec.rb index 34efb67b5..4b730127b 100644 --- a/spec/functions/min_spec.rb +++ b/spec/functions/min_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'min', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'min', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { is_expected.to run.with_params(1).and_return(1) } diff --git a/spec/functions/num2bool_spec.rb b/spec/functions/num2bool_spec.rb index 786fd9757..bedfb64a9 100644 --- a/spec/functions/num2bool_spec.rb +++ b/spec/functions/num2bool_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'num2bool' do diff --git a/spec/functions/os_version_gte_spec.rb b/spec/functions/os_version_gte_spec.rb index 98ccc4428..5de58384f 100644 --- a/spec/functions/os_version_gte_spec.rb +++ b/spec/functions/os_version_gte_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'os_version_gte' do context 'on Debian 9' do let(:facts) do { - :operatingsystem => 'Debian', - :operatingsystemmajrelease => '9', + operatingsystem: 'Debian', + operatingsystemmajrelease: '9', } end @@ -19,8 +21,8 @@ context 'on Ubuntu 16.04' do let(:facts) do { - :operatingsystem => 'Ubuntu', - :operatingsystemmajrelease => '16.04', + operatingsystem: 'Ubuntu', + operatingsystemmajrelease: '16.04', } end @@ -34,8 +36,8 @@ context 'with invalid params' do let(:facts) do { - :operatingsystem => 'Ubuntu', - :operatingsystemmajrelease => '16.04', + operatingsystem: 'Ubuntu', + operatingsystemmajrelease: '16.04', } end diff --git a/spec/functions/parsehocon_spec.rb b/spec/functions/parsehocon_spec.rb index 4eae3abd3..623a7da5f 100644 --- a/spec/functions/parsehocon_spec.rb +++ b/spec/functions/parsehocon_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'parsehocon' do diff --git a/spec/functions/parsejson_spec.rb b/spec/functions/parsejson_spec.rb index d03858479..bc8c2f70c 100644 --- a/spec/functions/parsejson_spec.rb +++ b/spec/functions/parsejson_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'parsejson' do @@ -57,7 +59,7 @@ end ['', 1, 1.2, nil, true, false, [], {}, :yaml].each do |value| - it "should return the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do + it "returns the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do is_expected.to run.with_params(value, 'default_value') .and_return('default_value') end diff --git a/spec/functions/parseyaml_spec.rb b/spec/functions/parseyaml_spec.rb index 62e18a324..f4ce41993 100644 --- a/spec/functions/parseyaml_spec.rb +++ b/spec/functions/parseyaml_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'parseyaml' do @@ -56,7 +58,7 @@ end [1, 1.2, nil, true, false, [], {}, :yaml].each do |value| - it "should return the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do + it "returns the default value for an incorrect #{value.inspect} (#{value.class}) parameter" do is_expected.to run.with_params(value, 'default_value') .and_return('default_value') end @@ -64,7 +66,7 @@ context 'when running on modern rubies' do ['---', '...', '*8', ''].each do |value| - it "should return the default value for an incorrect #{value.inspect} string parameter" do + it "returns the default value for an incorrect #{value.inspect} string parameter" do is_expected.to run.with_params(value, 'default_value') .and_return('default_value') end diff --git a/spec/functions/pick_default_spec.rb b/spec/functions/pick_default_spec.rb index 29d789658..6e32c4010 100644 --- a/spec/functions/pick_default_spec.rb +++ b/spec/functions/pick_default_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'pick_default' do diff --git a/spec/functions/pick_spec.rb b/spec/functions/pick_spec.rb index d8c6fbff0..741e0b798 100644 --- a/spec/functions/pick_spec.rb +++ b/spec/functions/pick_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'pick' do diff --git a/spec/functions/prefix_spec.rb b/spec/functions/prefix_spec.rb index 1b771d916..7353857d7 100644 --- a/spec/functions/prefix_spec.rb +++ b/spec/functions/prefix_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'prefix' do diff --git a/spec/functions/private_spec.rb b/spec/functions/private_spec.rb index cfd78c4e8..e0f266701 100644 --- a/spec/functions/private_spec.rb +++ b/spec/functions/private_spec.rb @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'private' do it 'issues a warning' do - expect(scope).to receive(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : unable to cut line to required length + expect(scope).to receive(:warning).with("private() DEPRECATED: This function will cease to function on Puppet 4; please use assert_private() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Layout/LineLength : unable to cut line to required length begin subject.execute - rescue # rubocop:disable Lint/HandleExceptions + rescue # ignore this end end diff --git a/spec/functions/pw_hash_spec.rb b/spec/functions/pw_hash_spec.rb index 31010d621..ac7d0973f 100644 --- a/spec/functions/pw_hash_spec.rb +++ b/spec/functions/pw_hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'pw_hash' do diff --git a/spec/functions/range_spec.rb b/spec/functions/range_spec.rb index 7b9e6d43c..f6d9a2f6f 100644 --- a/spec/functions/range_spec.rb +++ b/spec/functions/range_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'range' do it { is_expected.not_to eq(nil) } - describe 'signature validation in puppet3', :unless => RSpec.configuration.puppet_future do + describe 'signature validation in puppet3', unless: RSpec.configuration.puppet_future do it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { pending('Current implementation ignores parameters after the third.') @@ -13,7 +15,7 @@ it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Unknown range format}i) } end - describe 'signature validation in puppet4', :if => RSpec.configuration.puppet_future do + describe 'signature validation in puppet4', if: RSpec.configuration.puppet_future do it { pending 'the puppet 4 implementation' is_expected.to run.with_params.and_raise_error(ArgumentError) @@ -142,15 +144,15 @@ describe 'when passing mixed arguments as bounds' do it { - pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Metrics/LineLength : unable to cut line to required length + pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Layout/LineLength : unable to cut line to required length is_expected.to run.with_params('0', 'a').and_raise_error(Puppet::ParseError, %r{cannot interpolate between numeric and non-numeric bounds}) } it { - pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Metrics/LineLength : unable to cut line to required length + pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Layout/LineLength : unable to cut line to required length is_expected.to run.with_params(0, 'a').and_raise_error(Puppet::ParseError, %r{cannot interpolate between numeric and non-numeric bounds}) } it { - pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Metrics/LineLength : unable to cut line to required length + pending('these bounds should not be allowed as ruby will OOM hard. e.g. `(\'host0\'..\'hosta\').to_a` has 3239930 elements on ruby 1.9, adding more \'0\'s and \'a\'s increases that exponentially') # rubocop:disable Layout/LineLength : unable to cut line to required length is_expected.to run.with_params('h0', 'ha').and_raise_error(Puppet::ParseError, %r{cannot interpolate between numeric and non-numeric bounds}) } end diff --git a/spec/functions/regexpescape_spec.rb b/spec/functions/regexpescape_spec.rb index b60cb992b..b8d66cff2 100644 --- a/spec/functions/regexpescape_spec.rb +++ b/spec/functions/regexpescape_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'regexpescape' do diff --git a/spec/functions/reject_spec.rb b/spec/functions/reject_spec.rb index b7f6d2ed7..efc3b693e 100644 --- a/spec/functions/reject_spec.rb +++ b/spec/functions/reject_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'reject' do diff --git a/spec/functions/reverse_spec.rb b/spec/functions/reverse_spec.rb index 93a4e2a8f..cad7086d8 100644 --- a/spec/functions/reverse_spec.rb +++ b/spec/functions/reverse_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'reverse' do diff --git a/spec/functions/round_spec.rb b/spec/functions/round_spec.rb index fa8ebd5fa..7b3baf1b3 100644 --- a/spec/functions/round_spec.rb +++ b/spec/functions/round_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'round', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'round', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params(34.3).and_return(34) } it { is_expected.to run.with_params(-34.3).and_return(-34) } diff --git a/spec/functions/rstrip_spec.rb b/spec/functions/rstrip_spec.rb index 60776d895..251fb6677 100644 --- a/spec/functions/rstrip_spec.rb +++ b/spec/functions/rstrip_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'rstrip', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'rstrip', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/seeded_rand_spec.rb b/spec/functions/seeded_rand_spec.rb index 0bd8d6d28..9ee3b867b 100644 --- a/spec/functions/seeded_rand_spec.rb +++ b/spec/functions/seeded_rand_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'seeded_rand' do @@ -35,8 +37,8 @@ end it 'does not return different values for different hosts' do - val1 = seeded_rand(1000, 'foo', :host => 'first.host.com') - val2 = seeded_rand(1000, 'foo', :host => 'second.host.com') + val1 = seeded_rand(1000, 'foo', host: 'first.host.com') + val2 = seeded_rand(1000, 'foo', host: 'second.host.com') expect(val1).to eql(val2) end diff --git a/spec/functions/seeded_rand_string_spec.rb b/spec/functions/seeded_rand_string_spec.rb index 9083feb1b..66a5a16b9 100644 --- a/spec/functions/seeded_rand_string_spec.rb +++ b/spec/functions/seeded_rand_string_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'seeded_rand_string' do diff --git a/spec/functions/shell_escape_spec.rb b/spec/functions/shell_escape_spec.rb index 1e86d7c1d..4b1723777 100644 --- a/spec/functions/shell_escape_spec.rb +++ b/spec/functions/shell_escape_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'shell_escape' do diff --git a/spec/functions/shell_join_spec.rb b/spec/functions/shell_join_spec.rb index 8c4ba1ec5..f29bf53ce 100644 --- a/spec/functions/shell_join_spec.rb +++ b/spec/functions/shell_join_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'shell_join' do diff --git a/spec/functions/shell_split_spec.rb b/spec/functions/shell_split_spec.rb index 4a72cab2f..82d41f138 100644 --- a/spec/functions/shell_split_spec.rb +++ b/spec/functions/shell_split_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'shell_split' do diff --git a/spec/functions/shuffle_spec.rb b/spec/functions/shuffle_spec.rb index a3b68a856..0e4b1e578 100644 --- a/spec/functions/shuffle_spec.rb +++ b/spec/functions/shuffle_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'shuffle' do diff --git a/spec/functions/size_spec.rb b/spec/functions/size_spec.rb index 69fdff2f8..386f91249 100644 --- a/spec/functions/size_spec.rb +++ b/spec/functions/size_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'size', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'size', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { @@ -28,7 +30,7 @@ it { is_expected.to run.with_params('万').and_return(1) } it { is_expected.to run.with_params('āβćđ').and_return(4) } - context 'when using a class extending String', :unless => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') == 0 do + context 'when using a class extending String', unless: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.7') == 0 do it 'calls its size method' do value = AlsoString.new('asdfghjkl') expect(value).to receive(:size).and_return('foo') diff --git a/spec/functions/sort_spec.rb b/spec/functions/sort_spec.rb index 0e6e8e6e6..3387e7503 100644 --- a/spec/functions/sort_spec.rb +++ b/spec/functions/sort_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'sort', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'sort', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } diff --git a/spec/functions/sprintf_hash_spec.rb b/spec/functions/sprintf_hash_spec.rb index 4bead465c..4e72d3da8 100644 --- a/spec/functions/sprintf_hash_spec.rb +++ b/spec/functions/sprintf_hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'sprintf_hash' do diff --git a/spec/functions/squeeze_spec.rb b/spec/functions/squeeze_spec.rb index ee144b308..281846171 100644 --- a/spec/functions/squeeze_spec.rb +++ b/spec/functions/squeeze_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'squeeze' do diff --git a/spec/functions/startswith_spec.rb b/spec/functions/startswith_spec.rb index a25919230..a3478bb39 100644 --- a/spec/functions/startswith_spec.rb +++ b/spec/functions/startswith_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'stdlib::start_with' do diff --git a/spec/functions/stdlib_ensure_spec.rb b/spec/functions/stdlib_ensure_spec.rb index ebdcb9cb6..8a110b89b 100644 --- a/spec/functions/stdlib_ensure_spec.rb +++ b/spec/functions/stdlib_ensure_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'stdlib::ensure' do diff --git a/spec/functions/str2bool_spec.rb b/spec/functions/str2bool_spec.rb index fe43c4c24..070955ceb 100644 --- a/spec/functions/str2bool_spec.rb +++ b/spec/functions/str2bool_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'str2bool' do diff --git a/spec/functions/str2saltedpbkdf2_spec.rb b/spec/functions/str2saltedpbkdf2_spec.rb index 48dcdc48e..c46df7a6d 100644 --- a/spec/functions/str2saltedpbkdf2_spec.rb +++ b/spec/functions/str2saltedpbkdf2_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'str2saltedpbkdf2' do @@ -11,13 +13,13 @@ it { is_expected.to run.with_params('Pa55w0rd', 'Using s0m3 s@lt', 1).and_raise_error(ArgumentError, %r{third argument must be between 40,000 and 70,000}) } context 'when running with "Pa55w0rd", "Using s0m3 s@lt",and "50000" as params' do - # rubocop:disable Metrics/LineLength + # rubocop:disable Layout/LineLength it { is_expected.to run.with_params('Pa55w0rd', 'Using s0m3 s@lt', 50_000) .and_return('password_hex' => '3577f79f7d2e73df1cf1eecc36da16fffcd3650126d79e797a8b227492d13de4cdd0656933b43118b7361692f755e5b3c1e0536f826d12442400f3467bcc8fb4ac2235d5648b0f1b0906d0712aecd265834319b5a42e98af2ced81597fd78d1ac916f6eff6122c3577bb120a9f534e2a5c9a58c7d1209e3914c967c6a467b594', 'salt_hex' => '5573696e672073306d332073406c74', 'iterations' => 50_000) } - # rubocop:enable Metrics/LineLength + # rubocop:enable Layout/LineLength end end diff --git a/spec/functions/str2saltedsha512_spec.rb b/spec/functions/str2saltedsha512_spec.rb index e7513c97b..ae50ea76e 100644 --- a/spec/functions/str2saltedsha512_spec.rb +++ b/spec/functions/str2saltedsha512_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'str2saltedsha512' do diff --git a/spec/functions/strip_spec.rb b/spec/functions/strip_spec.rb index 28f8d86f2..1328baa5e 100644 --- a/spec/functions/strip_spec.rb +++ b/spec/functions/strip_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'strip', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'strip', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/suffix_spec.rb b/spec/functions/suffix_spec.rb index 802d598f2..0c12100be 100644 --- a/spec/functions/suffix_spec.rb +++ b/spec/functions/suffix_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'suffix' do diff --git a/spec/functions/swapcase_spec.rb b/spec/functions/swapcase_spec.rb index 837014060..49d2117de 100644 --- a/spec/functions/swapcase_spec.rb +++ b/spec/functions/swapcase_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'swapcase' do diff --git a/spec/functions/time_spec.rb b/spec/functions/time_spec.rb index 239e2ab09..181bb056e 100644 --- a/spec/functions/time_spec.rb +++ b/spec/functions/time_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'time' do diff --git a/spec/functions/to_bytes_spec.rb b/spec/functions/to_bytes_spec.rb index f3efd90f0..71ee00fe7 100644 --- a/spec/functions/to_bytes_spec.rb +++ b/spec/functions/to_bytes_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'to_bytes' do diff --git a/spec/functions/to_json_pretty_spec.rb b/spec/functions/to_json_pretty_spec.rb index 6f1b3fa57..071e88a9b 100644 --- a/spec/functions/to_json_pretty_spec.rb +++ b/spec/functions/to_json_pretty_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'to_json_pretty' do @@ -9,7 +11,7 @@ it { is_expected.to run.with_params('key' => 'value').and_return("{\n \"key\": \"value\"\n}\n") } it { is_expected.to run.with_params('one' => { 'oneA' => 'A', 'oneB' => { 'oneB1' => '1', 'oneB2' => '2' } }, 'two' => ['twoA', 'twoB']) - .and_return("{\n \"one\": {\n \"oneA\": \"A\",\n \"oneB\": {\n \"oneB1\": \"1\",\n \"oneB2\": \"2\"\n }\n },\n \"two\": [\n \"twoA\",\n \"twoB\"\n ]\n}\n") # rubocop:disable Metrics/LineLength : Unable to reduce line to required length + .and_return("{\n \"one\": {\n \"oneA\": \"A\",\n \"oneB\": {\n \"oneB1\": \"1\",\n \"oneB2\": \"2\"\n }\n },\n \"two\": [\n \"twoA\",\n \"twoB\"\n ]\n}\n") # rubocop:disable Layout/LineLength : Unable to reduce line to required length } it { is_expected.to run.with_params({ 'one' => '1', 'two' => nil }, true).and_return("{\n \"one\": \"1\"\n}\n") } it { is_expected.to run.with_params(['one', 'two', nil, 'three'], true).and_return("[\n \"one\",\n \"two\",\n \"three\"\n]\n") } diff --git a/spec/functions/to_json_spec.rb b/spec/functions/to_json_spec.rb index 83bb8866a..32184d6dd 100644 --- a/spec/functions/to_json_spec.rb +++ b/spec/functions/to_json_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'to_json' do diff --git a/spec/functions/to_yaml_spec.rb b/spec/functions/to_yaml_spec.rb index eecb8a4e2..98985c404 100644 --- a/spec/functions/to_yaml_spec.rb +++ b/spec/functions/to_yaml_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'to_yaml' do @@ -18,5 +20,5 @@ it { is_expected.to run.with_params('‰').and_return("--- \"‰\"\n") } it { is_expected.to run.with_params('∇').and_return("--- \"∇\"\n") } - it { is_expected.to run.with_params({ 'foo' => { 'bar' => true, 'baz' => false } }, :indentation => 4).and_return("---\nfoo:\n bar: true\n baz: false\n") } + it { is_expected.to run.with_params({ 'foo' => { 'bar' => true, 'baz' => false } }, indentation: 4).and_return("---\nfoo:\n bar: true\n baz: false\n") } end diff --git a/spec/functions/try_get_value_spec.rb b/spec/functions/try_get_value_spec.rb index 6fe9c10fd..2b9b96c65 100644 --- a/spec/functions/try_get_value_spec.rb +++ b/spec/functions/try_get_value_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'try_get_value' do diff --git a/spec/functions/type3x_spec.rb b/spec/functions/type3x_spec.rb index a53362d72..750752628 100644 --- a/spec/functions/type3x_spec.rb +++ b/spec/functions/type3x_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'type3x' do diff --git a/spec/functions/type_of_spec.rb b/spec/functions/type_of_spec.rb index 4f55b2c03..243b17355 100644 --- a/spec/functions/type_of_spec.rb +++ b/spec/functions/type_of_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if ENV['FUTURE_PARSER'] == 'yes' diff --git a/spec/functions/type_spec.rb b/spec/functions/type_spec.rb index e1d687bf4..8a0f2a11e 100644 --- a/spec/functions/type_spec.rb +++ b/spec/functions/type_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'type' do @@ -6,7 +8,7 @@ end it 'gives a deprecation warning when called' do - expect(scope).to receive(:warning).with("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Metrics/LineLength : Unable to reduce to required length + expect(scope).to receive(:warning).with("type() DEPRECATED: This function will cease to function on Puppet 4; please use type3x() before upgrading to puppet 4 for backwards-compatibility, or migrate to the new parser's typing system.") # rubocop:disable Layout/LineLength : Unable to reduce to required length scope.function_type(['aoeu']) end diff --git a/spec/functions/union_spec.rb b/spec/functions/union_spec.rb index 549229808..d5ab61730 100644 --- a/spec/functions/union_spec.rb +++ b/spec/functions/union_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'union' do diff --git a/spec/functions/unique_spec.rb b/spec/functions/unique_spec.rb index 1cdb93451..92234fae0 100644 --- a/spec/functions/unique_spec.rb +++ b/spec/functions/unique_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'unique' do diff --git a/spec/functions/unix2dos_spec.rb b/spec/functions/unix2dos_spec.rb index a6af64f08..cd94e150e 100644 --- a/spec/functions/unix2dos_spec.rb +++ b/spec/functions/unix2dos_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'unix2dos' do diff --git a/spec/functions/upcase_spec.rb b/spec/functions/upcase_spec.rb index 5b5e42617..d110ee108 100644 --- a/spec/functions/upcase_spec.rb +++ b/spec/functions/upcase_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'upcase', :if => Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do +describe 'upcase', if: Puppet::Util::Package.versioncmp(Puppet.version, '6.0.0') < 0 do describe 'signature validation' do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } diff --git a/spec/functions/uriescape_spec.rb b/spec/functions/uriescape_spec.rb index fdc3e20b2..3ac632ade 100644 --- a/spec/functions/uriescape_spec.rb +++ b/spec/functions/uriescape_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'uriescape' do diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb index ba73a2192..4365229b9 100644 --- a/spec/functions/validate_absolute_path_spec.rb +++ b/spec/functions/validate_absolute_path_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_absolute_path' do diff --git a/spec/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb index 87b7c2431..da8b093cf 100644 --- a/spec/functions/validate_array_spec.rb +++ b/spec/functions/validate_array_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_array' do diff --git a/spec/functions/validate_augeas_spec.rb b/spec/functions/validate_augeas_spec.rb index 2dd0df897..04ee0eb3e 100644 --- a/spec/functions/validate_augeas_spec.rb +++ b/spec/functions/validate_augeas_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_augeas' do diff --git a/spec/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb index 72c1e2dc9..ffcf1ba02 100644 --- a/spec/functions/validate_bool_spec.rb +++ b/spec/functions/validate_bool_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_bool' do diff --git a/spec/functions/validate_cmd_spec.rb b/spec/functions/validate_cmd_spec.rb index 91fd0d192..7d8a8a166 100644 --- a/spec/functions/validate_cmd_spec.rb +++ b/spec/functions/validate_cmd_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'validate_cmd', :unless => Puppet::Util::Platform.windows? do +describe 'validate_cmd', unless: Puppet::Util::Platform.windows? do let(:touch) { File.exist?('/usr/bin/touch') ? '/usr/bin/touch' : '/bin/touch' } describe 'signature validation' do diff --git a/spec/functions/validate_domain_name_spec.rb b/spec/functions/validate_domain_name_spec.rb index 0ac1a3d35..f48d31ab5 100644 --- a/spec/functions/validate_domain_name_spec.rb +++ b/spec/functions/validate_domain_name_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_domain_name' do diff --git a/spec/functions/validate_email_address_spec.rb b/spec/functions/validate_email_address_spec.rb index 520c7a486..9d87061bb 100644 --- a/spec/functions/validate_email_address_spec.rb +++ b/spec/functions/validate_email_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_email_address' do diff --git a/spec/functions/validate_hash_spec.rb b/spec/functions/validate_hash_spec.rb index 1c6213b78..89fe882ea 100644 --- a/spec/functions/validate_hash_spec.rb +++ b/spec/functions/validate_hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_hash' do diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb index cf29cf8d6..6252a6dc7 100644 --- a/spec/functions/validate_integer_spec.rb +++ b/spec/functions/validate_integer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_integer' do @@ -24,11 +26,11 @@ it { is_expected.to run.with_params([0, 1, 2, invalid, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } end - context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do + context 'when running on modern rubies', unless: RUBY_VERSION == '1.8.7' do it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be an Integer}) } end - context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do + context 'when running on ruby, which munges hashes weirdly', if: RUBY_VERSION == '1.8.7' do it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } end diff --git a/spec/functions/validate_ip_address_spec.rb b/spec/functions/validate_ip_address_spec.rb index 8fd145eb6..ded6df976 100644 --- a/spec/functions/validate_ip_address_spec.rb +++ b/spec/functions/validate_ip_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_ip_address' do @@ -20,7 +22,7 @@ it { is_expected.to run.with_params('::1/64') } it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') } - context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do after(:each) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb index 72c3e7a2d..bc8ed7648 100644 --- a/spec/functions/validate_ipv4_address_spec.rb +++ b/spec/functions/validate_ipv4_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_ipv4_address' do @@ -6,7 +8,7 @@ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } end - context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do after(:each) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index 0834307f5..3e1563ed1 100644 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_ipv6_address' do @@ -6,7 +8,7 @@ it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } end - context 'Checking for deprecation warning', :if => Puppet.version.to_f < 4.0 do + context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do after(:each) do ENV.delete('STDLIB_LOG_DEPRECATIONS') end @@ -51,7 +53,7 @@ it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, %r{is not a string}) } it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, %r{is not a string}) } it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, %r{is not a valid IPv6}) } - context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do + context 'unless running on ruby 1.8.7', if: RUBY_VERSION != '1.8.7' do it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{is not a string}) } it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, %r{is not a string}) } end diff --git a/spec/functions/validate_legacy_spec.rb b/spec/functions/validate_legacy_spec.rb index 6c65d5e7d..0998cf618 100644 --- a/spec/functions/validate_legacy_spec.rb +++ b/spec/functions/validate_legacy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.4.0') >= 0 diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb index 80b3e3715..8b593c318 100644 --- a/spec/functions/validate_numeric_spec.rb +++ b/spec/functions/validate_numeric_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_numeric' do @@ -23,11 +25,11 @@ it { is_expected.to run.with_params(invalid, 10.0, -10.0).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) } end - context 'when running on modern rubies', :unless => RUBY_VERSION == '1.8.7' do + context 'when running on modern rubies', unless: RUBY_VERSION == '1.8.7' do it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError, %r{to be a Numeric}) } end - context 'when running on ruby, which munges hashes weirdly', :if => RUBY_VERSION == '1.8.7' do + context 'when running on ruby, which munges hashes weirdly', if: RUBY_VERSION == '1.8.7' do it { is_expected.to run.with_params([0, 1, 2, { 1 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } it { is_expected.to run.with_params([0, 1, 2, { 0 => 2 }, 3, 4], 10, -10).and_raise_error(Puppet::ParseError) } end diff --git a/spec/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb index 2a5068981..bfa824e6e 100644 --- a/spec/functions/validate_re_spec.rb +++ b/spec/functions/validate_re_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_re' do @@ -47,7 +49,7 @@ false, # FalseClass ['10'], # Array :key, # Symbol - { :key => 'val' }, # Hash + { key: 'val' }, # Hash ].each do |input| it { is_expected.to run.with_params(input, '.*').and_raise_error(Puppet::ParseError, %r{needs to be a String}) } end diff --git a/spec/functions/validate_slength_spec.rb b/spec/functions/validate_slength_spec.rb index b11444dc6..6ff44c737 100644 --- a/spec/functions/validate_slength_spec.rb +++ b/spec/functions/validate_slength_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_slength' do diff --git a/spec/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb index 40522c6f1..515747f84 100644 --- a/spec/functions/validate_string_spec.rb +++ b/spec/functions/validate_string_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_string' do diff --git a/spec/functions/validate_x509_rsa_key_pair_spec.rb b/spec/functions/validate_x509_rsa_key_pair_spec.rb index 937c1898e..08a24234e 100644 --- a/spec/functions/validate_x509_rsa_key_pair_spec.rb +++ b/spec/functions/validate_x509_rsa_key_pair_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'validate_x509_rsa_key_pair' do @@ -174,7 +176,6 @@ def truncate_middle(string) start_pos = middle - (chars_to_truncate / 2) end_pos = middle + (chars_to_truncate / 2) - string[start_pos...end_pos] = '' - string + string[0..start_pos] + string[end_pos..-1] end end diff --git a/spec/functions/values_at_spec.rb b/spec/functions/values_at_spec.rb index 048f270b1..61c9f4d2f 100644 --- a/spec/functions/values_at_spec.rb +++ b/spec/functions/values_at_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'values_at' do diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb index 850d31472..b2c3e4b05 100644 --- a/spec/functions/values_spec.rb +++ b/spec/functions/values_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -describe 'values', :if => Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do +describe 'values', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do it { is_expected.not_to eq(nil) } it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } it { diff --git a/spec/functions/zip_spec.rb b/spec/functions/zip_spec.rb index c2b4e3bb3..77c7f9435 100644 --- a/spec/functions/zip_spec.rb +++ b/spec/functions/zip_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'zip' do diff --git a/spec/monkey_patches/alias_should_to_must.rb b/spec/monkey_patches/alias_should_to_must.rb index 51a7b9db2..beb36bff1 100644 --- a/spec/monkey_patches/alias_should_to_must.rb +++ b/spec/monkey_patches/alias_should_to_must.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rspec' # class Object class Object diff --git a/spec/monkey_patches/publicize_methods.rb b/spec/monkey_patches/publicize_methods.rb index 70cf4f056..91eca2f60 100644 --- a/spec/monkey_patches/publicize_methods.rb +++ b/spec/monkey_patches/publicize_methods.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Some monkey-patching to allow us to test private methods. class Class def publicize_methods(*methods) diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index 5fea4da4a..877294391 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # automatically load any shared examples or contexts Dir['./spec/support/**/*.rb'].sort.each { |f| require f } diff --git a/spec/support/shared_data.rb b/spec/support/shared_data.rb index 013ec105a..e19f82488 100644 --- a/spec/support/shared_data.rb +++ b/spec/support/shared_data.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SharedData IPV4_PATTERNS = [ '0.0.0.0', diff --git a/spec/type_aliases/absolute_path_spec.rb b/spec/type_aliases/absolute_path_spec.rb index 0e5564f45..ba4195548 100644 --- a/spec/type_aliases/absolute_path_spec.rb +++ b/spec/type_aliases/absolute_path_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/array_spec.rb b/spec/type_aliases/array_spec.rb index 0b0da3cbf..07bc7cce8 100644 --- a/spec/type_aliases/array_spec.rb +++ b/spec/type_aliases/array_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/base32_spec.rb b/spec/type_aliases/base32_spec.rb index 48c47451a..b50dc94b1 100644 --- a/spec/type_aliases/base32_spec.rb +++ b/spec/type_aliases/base32_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/base64_spec.rb b/spec/type_aliases/base64_spec.rb index 0de9e6daf..ddb297094 100644 --- a/spec/type_aliases/base64_spec.rb +++ b/spec/type_aliases/base64_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/bool_spec.rb b/spec/type_aliases/bool_spec.rb index bdc8f75f6..6b8da7cd1 100644 --- a/spec/type_aliases/bool_spec.rb +++ b/spec/type_aliases/bool_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/compat__ip_address.rb b/spec/type_aliases/compat__ip_address.rb index 671c64b2f..c98c45cd7 100644 --- a/spec/type_aliases/compat__ip_address.rb +++ b/spec/type_aliases/compat__ip_address.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/compat__ipv4_spec.rb b/spec/type_aliases/compat__ipv4_spec.rb index dfd4be180..fb5ad79f8 100644 --- a/spec/type_aliases/compat__ipv4_spec.rb +++ b/spec/type_aliases/compat__ipv4_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/compat__ipv6_spec.rb b/spec/type_aliases/compat__ipv6_spec.rb index 94211b695..c9214b62b 100644 --- a/spec/type_aliases/compat__ipv6_spec.rb +++ b/spec/type_aliases/compat__ipv6_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/datasize_spec.rb b/spec/type_aliases/datasize_spec.rb index b5976fd26..c7c6b4cbf 100644 --- a/spec/type_aliases/datasize_spec.rb +++ b/spec/type_aliases/datasize_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/email_spec.rb b/spec/type_aliases/email_spec.rb index 5c262c9ce..add96eeff 100644 --- a/spec/type_aliases/email_spec.rb +++ b/spec/type_aliases/email_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' # Test cases are a combination of the test cases used in MediaWiki[1] and a diff --git a/spec/type_aliases/filemode_spec.rb b/spec/type_aliases/filemode_spec.rb index c5a60857c..09a47a34a 100644 --- a/spec/type_aliases/filemode_spec.rb +++ b/spec/type_aliases/filemode_spec.rb @@ -1,4 +1,5 @@ # coding: utf-8 +# frozen_string_literal: true require 'spec_helper' diff --git a/spec/type_aliases/filesource_spec.rb b/spec/type_aliases/filesource_spec.rb index 544a90ea3..8c13b1364 100644 --- a/spec/type_aliases/filesource_spec.rb +++ b/spec/type_aliases/filesource_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/float_spec.rb b/spec/type_aliases/float_spec.rb index 3d1d6673a..fe4810e75 100644 --- a/spec/type_aliases/float_spec.rb +++ b/spec/type_aliases/float_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/fqdn_spec.rb b/spec/type_aliases/fqdn_spec.rb index c8dfef135..904716cc7 100644 --- a/spec/type_aliases/fqdn_spec.rb +++ b/spec/type_aliases/fqdn_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/hash_spec.rb b/spec/type_aliases/hash_spec.rb index 6e88a4268..e5960d009 100644 --- a/spec/type_aliases/hash_spec.rb +++ b/spec/type_aliases/hash_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/host_spec.rb b/spec/type_aliases/host_spec.rb index acf9b1f41..e0a40341a 100644 --- a/spec/type_aliases/host_spec.rb +++ b/spec/type_aliases/host_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/httpstatus_spec.rb b/spec/type_aliases/httpstatus_spec.rb index 16721bec6..0e7b2a33a 100644 --- a/spec/type_aliases/httpstatus_spec.rb +++ b/spec/type_aliases/httpstatus_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/httpsurl_spec.rb b/spec/type_aliases/httpsurl_spec.rb index 07f6804d4..f0e99b7e0 100644 --- a/spec/type_aliases/httpsurl_spec.rb +++ b/spec/type_aliases/httpsurl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/httpurl_spec.rb b/spec/type_aliases/httpurl_spec.rb index 420b06eaa..9459479b6 100644 --- a/spec/type_aliases/httpurl_spec.rb +++ b/spec/type_aliases/httpurl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/integer_spec.rb b/spec/type_aliases/integer_spec.rb index 29298fa65..eefac67e9 100644 --- a/spec/type_aliases/integer_spec.rb +++ b/spec/type_aliases/integer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_nosubnet_spec.rb b/spec/type_aliases/ip_address_nosubnet_spec.rb index 921d95704..e82181e47 100644 --- a/spec/type_aliases/ip_address_nosubnet_spec.rb +++ b/spec/type_aliases/ip_address_nosubnet_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_spec.rb b/spec/type_aliases/ip_address_spec.rb index e60335068..9b226ea80 100644 --- a/spec/type_aliases/ip_address_spec.rb +++ b/spec/type_aliases/ip_address_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v4_nosubnet_spec.rb b/spec/type_aliases/ip_address_v4_nosubnet_spec.rb index ab74f8ce8..8dc9aa60c 100644 --- a/spec/type_aliases/ip_address_v4_nosubnet_spec.rb +++ b/spec/type_aliases/ip_address_v4_nosubnet_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v4_spec.rb b/spec/type_aliases/ip_address_v4_spec.rb index 10854c8fa..cd61c2d07 100644 --- a/spec/type_aliases/ip_address_v4_spec.rb +++ b/spec/type_aliases/ip_address_v4_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_alternative_spec.rb b/spec/type_aliases/ip_address_v6_alternative_spec.rb index 9fbf7ca72..90bf40a5e 100644 --- a/spec/type_aliases/ip_address_v6_alternative_spec.rb +++ b/spec/type_aliases/ip_address_v6_alternative_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_cidr_spec.rb b/spec/type_aliases/ip_address_v6_cidr_spec.rb index 4b8fee3bb..1cc20316e 100644 --- a/spec/type_aliases/ip_address_v6_cidr_spec.rb +++ b/spec/type_aliases/ip_address_v6_cidr_spec.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'spec_helper' diff --git a/spec/type_aliases/ip_address_v6_compressed_spec.rb b/spec/type_aliases/ip_address_v6_compressed_spec.rb index e2b7dd533..968fcd2a0 100644 --- a/spec/type_aliases/ip_address_v6_compressed_spec.rb +++ b/spec/type_aliases/ip_address_v6_compressed_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_full_spec.rb b/spec/type_aliases/ip_address_v6_full_spec.rb index cc8013d87..c69ed1d94 100644 --- a/spec/type_aliases/ip_address_v6_full_spec.rb +++ b/spec/type_aliases/ip_address_v6_full_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_nosubnet_alternative_spec.rb b/spec/type_aliases/ip_address_v6_nosubnet_alternative_spec.rb index 0b36cb9ca..85f037a8c 100644 --- a/spec/type_aliases/ip_address_v6_nosubnet_alternative_spec.rb +++ b/spec/type_aliases/ip_address_v6_nosubnet_alternative_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_nosubnet_compressed_spec.rb b/spec/type_aliases/ip_address_v6_nosubnet_compressed_spec.rb index 96af0354c..bbca083ab 100644 --- a/spec/type_aliases/ip_address_v6_nosubnet_compressed_spec.rb +++ b/spec/type_aliases/ip_address_v6_nosubnet_compressed_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_nosubnet_full_spec.rb b/spec/type_aliases/ip_address_v6_nosubnet_full_spec.rb index 9135e002d..6ef0a31af 100644 --- a/spec/type_aliases/ip_address_v6_nosubnet_full_spec.rb +++ b/spec/type_aliases/ip_address_v6_nosubnet_full_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/ip_address_v6_spec.rb b/spec/type_aliases/ip_address_v6_spec.rb index 864c56538..a44ea326e 100644 --- a/spec/type_aliases/ip_address_v6_spec.rb +++ b/spec/type_aliases/ip_address_v6_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/mac_spec.rb b/spec/type_aliases/mac_spec.rb index af8cd177e..67c08e2b0 100644 --- a/spec/type_aliases/mac_spec.rb +++ b/spec/type_aliases/mac_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/numeric_spec.rb b/spec/type_aliases/numeric_spec.rb index a59b4e227..3a7aabb5a 100644 --- a/spec/type_aliases/numeric_spec.rb +++ b/spec/type_aliases/numeric_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/objectstore_gsuri_spec.rb b/spec/type_aliases/objectstore_gsuri_spec.rb index 5b9390aac..c4c728a54 100644 --- a/spec/type_aliases/objectstore_gsuri_spec.rb +++ b/spec/type_aliases/objectstore_gsuri_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/objectstore_s3uri_spec.rb b/spec/type_aliases/objectstore_s3uri_spec.rb index c4785abab..efcbbd639 100644 --- a/spec/type_aliases/objectstore_s3uri_spec.rb +++ b/spec/type_aliases/objectstore_s3uri_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/objectstore_spec.rb b/spec/type_aliases/objectstore_spec.rb index ae3c2caca..a1f61effd 100644 --- a/spec/type_aliases/objectstore_spec.rb +++ b/spec/type_aliases/objectstore_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/port__dynamic_spec.rb b/spec/type_aliases/port__dynamic_spec.rb index 5503e7c0d..a282f5158 100644 --- a/spec/type_aliases/port__dynamic_spec.rb +++ b/spec/type_aliases/port__dynamic_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/port__privileged_spec.rb b/spec/type_aliases/port__privileged_spec.rb index 51ddd2478..7260188d3 100644 --- a/spec/type_aliases/port__privileged_spec.rb +++ b/spec/type_aliases/port__privileged_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/port__unprivileged_spec.rb b/spec/type_aliases/port__unprivileged_spec.rb index 0009e1f64..a3fa39208 100644 --- a/spec/type_aliases/port__unprivileged_spec.rb +++ b/spec/type_aliases/port__unprivileged_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/port__user_spec.rb b/spec/type_aliases/port__user_spec.rb index c34e9b227..061d5700b 100644 --- a/spec/type_aliases/port__user_spec.rb +++ b/spec/type_aliases/port__user_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/port_spec.rb b/spec/type_aliases/port_spec.rb index 3c9582c19..02f094466 100644 --- a/spec/type_aliases/port_spec.rb +++ b/spec/type_aliases/port_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/string_spec.rb b/spec/type_aliases/string_spec.rb index 93a9d0f13..b3cdd2d84 100644 --- a/spec/type_aliases/string_spec.rb +++ b/spec/type_aliases/string_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/unixpath_spec.rb b/spec/type_aliases/unixpath_spec.rb index 3f8372dd0..3c9f4a7a7 100644 --- a/spec/type_aliases/unixpath_spec.rb +++ b/spec/type_aliases/unixpath_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/windowspath_spec.rb b/spec/type_aliases/windowspath_spec.rb index fb0baaf99..00b4ee4a9 100644 --- a/spec/type_aliases/windowspath_spec.rb +++ b/spec/type_aliases/windowspath_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' if Puppet::Util::Package.versioncmp(Puppet.version, '4.5.0') >= 0 diff --git a/spec/type_aliases/yes_no_spec.rb b/spec/type_aliases/yes_no_spec.rb index 9416c6ae2..b61d10a70 100644 --- a/spec/type_aliases/yes_no_spec.rb +++ b/spec/type_aliases/yes_no_spec.rb @@ -1,4 +1,5 @@ # coding: utf-8 +# frozen_string_literal: true require 'spec_helper' diff --git a/spec/unit/facter/package_provider_spec.rb b/spec/unit/facter/package_provider_spec.rb index 011d3ed8e..3e75c2870 100644 --- a/spec/unit/facter/package_provider_spec.rb +++ b/spec/unit/facter/package_provider_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet/type' require 'puppet/type/package' -describe 'package_provider', :type => :fact do +describe 'package_provider', type: :fact do before(:each) { Facter.clear } after(:each) { Facter.clear } diff --git a/spec/unit/facter/pe_version_spec.rb b/spec/unit/facter/pe_version_spec.rb index ba9058280..e152548f7 100644 --- a/spec/unit/facter/pe_version_spec.rb +++ b/spec/unit/facter/pe_version_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'PE Version specs' do @@ -32,19 +34,19 @@ expect(Facter.fact(:is_pe).value).to eq(true) end - it "Should have a version of #{version}" do + it "has a version of #{version}" do expect(Facter.fact(:pe_version).value).to eq(version) end - it "Should have a major version of #{major}" do + it "has a major version of #{major}" do expect(Facter.fact(:pe_major_version).value).to eq(major) end - it "Should have a minor version of #{minor}" do + it "has a minor version of #{minor}" do expect(Facter.fact(:pe_minor_version).value).to eq(minor) end - it "Should have a patch version of #{patch}" do + it "has a patch version of #{patch}" do expect(Facter.fact(:pe_patch_version).value).to eq(patch) end end diff --git a/spec/unit/facter/root_home_spec.rb b/spec/unit/facter/root_home_spec.rb index 5e5b0bfc5..5421f3e68 100644 --- a/spec/unit/facter/root_home_spec.rb +++ b/spec/unit/facter/root_home_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'facter/root_home' describe 'Root Home Specs' do @@ -28,7 +30,7 @@ end end - describe 'root_home', :type => :fact do + describe 'root_home', type: :fact do before(:each) { Facter.clear } after(:each) { Facter.clear } diff --git a/spec/unit/facter/service_provider_spec.rb b/spec/unit/facter/service_provider_spec.rb index b3d4aec69..4d7d4e104 100644 --- a/spec/unit/facter/service_provider_spec.rb +++ b/spec/unit/facter/service_provider_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' require 'puppet/type' require 'puppet/type/service' -describe 'service_provider', :type => :fact do +describe 'service_provider', type: :fact do before(:each) { Facter.clear } after(:each) { Facter.clear } diff --git a/spec/unit/facter/util/puppet_settings_spec.rb b/spec/unit/facter/util/puppet_settings_spec.rb index 05dff893f..edd63a86e 100644 --- a/spec/unit/facter/util/puppet_settings_spec.rb +++ b/spec/unit/facter/util/puppet_settings_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'facter/util/puppet_settings' diff --git a/spec/unit/puppet/parser/functions/enclose_ipv6_spec.rb b/spec/unit/puppet/parser/functions/enclose_ipv6_spec.rb index 39d3b7afb..ca815de61 100644 --- a/spec/unit/puppet/parser/functions/enclose_ipv6_spec.rb +++ b/spec/unit/puppet/parser/functions/enclose_ipv6_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'the enclose_ipv6 function' do diff --git a/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb b/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb index 589ad8228..097b3db1a 100644 --- a/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb +++ b/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'is_absolute_path' do diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb index d0f653aa9..506160bee 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:file_line).provider(:ruby) #  These tests fail on windows when run as part of the rake task. Individually they pass -describe provider_class, :unless => Puppet::Util::Platform.windows? do +describe provider_class, unless: Puppet::Util::Platform.windows? do include PuppetlabsSpec::Files let :tmpfile do @@ -16,9 +18,9 @@ end let :resource do Puppet::Type::File_line.new({ - :name => 'foo', - :path => tmpfile, - :line => 'foo', + name: 'foo', + path: tmpfile, + line: 'foo', }.merge(params)) end let :provider do @@ -53,7 +55,7 @@ end describe 'match parameter' do - let(:params) { { :match => '^bar' } } + let(:params) { { match: '^bar' } } describe 'does not match line - line does not exist - replacing' do let(:content) { "foo bar\nbar" } @@ -68,7 +70,7 @@ end describe 'does not match line - line does not exist - appending' do - let(:params) { super().merge(:replace => false) } + let(:params) { super().merge(replace: false) } let(:content) { "foo bar\nbar" } it 'does not request changes' do @@ -85,7 +87,7 @@ end context 'when matches line - line exists' do - let(:params) { { :match => '^foo' } } + let(:params) { { match: '^foo' } } let(:content) { "foo\nbar" } it 'detects the line' do @@ -94,7 +96,7 @@ end context 'when matches line - line does not exist' do - let(:params) { { :match => '^foo' } } + let(:params) { { match: '^foo' } } let(:content) { "foo bar\nbar" } it 'requests changes' do @@ -110,8 +112,8 @@ describe 'append_on_no_match' do let(:params) do { - :append_on_no_match => false, - :match => '^foo1$', + append_on_no_match: false, + match: '^foo1$', } end @@ -139,8 +141,8 @@ context 'when replace is false' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :replace => false, + replace_all_matches_not_matching_line: true, + replace: false, } end @@ -152,9 +154,9 @@ context 'when match matches line - when there are more matches than lines' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :match => '^foo', - :multiple => true, + replace_all_matches_not_matching_line: true, + match: '^foo', + multiple: true, } end let(:content) { "foo\nfoo bar\nbar\nfoo baz" } @@ -171,9 +173,9 @@ context 'when match matches line - when there are the same matches and lines' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :match => '^foo', - :multiple => true, + replace_all_matches_not_matching_line: true, + match: '^foo', + multiple: true, } end let(:content) { "foo\nfoo\nbar" } @@ -186,9 +188,9 @@ context 'when match does not match line - when there are more matches than lines' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :match => '^bar', - :multiple => true, + replace_all_matches_not_matching_line: true, + match: '^bar', + multiple: true, } end let(:content) { "foo\nfoo bar\nbar\nbar baz" } @@ -205,9 +207,9 @@ context 'when match does not match line - when there are the same matches and lines' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :match => '^bar', - :multiple => true, + replace_all_matches_not_matching_line: true, + match: '^bar', + multiple: true, } end let(:content) { "foo\nfoo\nbar\nbar baz" } @@ -225,9 +227,9 @@ context 'when match does not match line - when there are no matches' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :match => '^bar', - :multiple => true, + replace_all_matches_not_matching_line: true, + match: '^bar', + multiple: true, } end let(:content) { "foo\nfoo bar" } @@ -240,9 +242,9 @@ context 'when match does not match line - when there are no matches or lines' do let(:params) do { - :replace_all_matches_not_matching_line => true, - :match => '^bar', - :multiple => true, + replace_all_matches_not_matching_line: true, + match: '^bar', + multiple: true, } end let(:content) { 'foo bar' } diff --git a/spec/unit/puppet/provider/file_line/ruby_spec_alter.rb b/spec/unit/puppet/provider/file_line/ruby_spec_alter.rb index c2b30ffad..f6f7e9340 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec_alter.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec_alter.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:file_line).provider(:ruby) #  These tests fail on windows when run as part of the rake task. Individually they pass -describe provider_class, :unless => Puppet::Util::Platform.windows? do +describe provider_class, unless: Puppet::Util::Platform.windows? do include PuppetlabsSpec::Files let :tmpfile do @@ -16,9 +18,9 @@ end let :resource do Puppet::Type::File_line.new({ - :name => 'foo', - :path => tmpfile, - :line => 'foo', + name: 'foo', + path: tmpfile, + line: 'foo', }.merge(params)) end let :provider do @@ -38,9 +40,9 @@ context 'when replacing' do let :params do { - :line => 'foo = bar', - :match => '^foo\s*=.*$', - :replace => false, + line: 'foo = bar', + match: '^foo\s*=.*$', + replace: false, } end let(:content) { "foo1\nfoo=blah\nfoo2\nfoo3" } @@ -61,7 +63,7 @@ it 'raises an error with invalid values' do expect { @resource = Puppet::Type::File_line.new( - :name => 'foo', :path => tmpfile, :line => 'foo = bar', :match => '^foo\s*=.*$', :replace => 'asgadga', + name: 'foo', path: tmpfile, line: 'foo = bar', match: '^foo\s*=.*$', replace: 'asgadga', ) }.to raise_error(Puppet::Error, %r{Invalid value "asgadga"\. Valid values are true, false\.}) end @@ -74,10 +76,10 @@ # rubocop:disable RSpec/InstanceVariable : replacing before with let breaks the tests, variables need to be altered within it block : multi before :each do @resource = Puppet::Type::File_line.new( - :name => 'foo', - :path => tmpfile, - :line => 'foo = bar', - :match => '^foo\s*=.*$', + name: 'foo', + path: tmpfile, + line: 'foo = bar', + match: '^foo\s*=.*$', ) @provider = provider_class.new(@resource) end @@ -89,7 +91,7 @@ end it 'replaces all lines that matches' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'foo = bar', :match => '^foo\s*=.*$', :multiple => true) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo = bar', match: '^foo\s*=.*$', multiple: true) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") } @provider.create @@ -97,7 +99,7 @@ end it 'replaces all lines that match, even when some lines are correct' do - @resource = Puppet::Type::File_line.new(:name => 'neil', :path => tmpfile, :line => "\thard\tcore\t0\n", :match => '^[ \t]hard[ \t]+core[ \t]+.*', :multiple => true) + @resource = Puppet::Type::File_line.new(name: 'neil', path: tmpfile, line: "\thard\tcore\t0\n", match: '^[ \t]hard[ \t]+core[ \t]+.*', multiple: true) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("\thard\tcore\t90\n\thard\tcore\t0\n") } @provider.create @@ -107,7 +109,7 @@ it 'raises an error with invalid values' do expect { @resource = Puppet::Type::File_line.new( - :name => 'foo', :path => tmpfile, :line => 'foo = bar', :match => '^foo\s*=.*$', :multiple => 'asgadga', + name: 'foo', path: tmpfile, line: 'foo = bar', match: '^foo\s*=.*$', multiple: 'asgadga', ) }.to raise_error(Puppet::Error, %r{Invalid value "asgadga"\. Valid values are true, false\.}) end @@ -130,7 +132,7 @@ end describe 'using match+append_on_no_match - when there is a match' do it 'replaces line' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'inserted = line', :match => '^foo3$', :append_on_no_match => false) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'inserted = line', match: '^foo3$', append_on_no_match: false) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") } expect(File.read(tmpfile).chomp).to eql("foo1\nfoo = blah\nfoo2\nfoo = baz") @@ -138,7 +140,7 @@ end describe 'using match+append_on_no_match - when there is no match' do it 'does not add line after no matches found' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'inserted = line', :match => '^foo3$', :append_on_no_match => false) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'inserted = line', match: '^foo3$', append_on_no_match: false) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo = blah\nfoo2\nfoo = baz") } expect(File.read(tmpfile).chomp).to eql("foo1\nfoo = blah\nfoo2\nfoo = baz") @@ -151,10 +153,10 @@ context 'when after' do let :resource do Puppet::Type::File_line.new( - :name => 'foo', - :path => tmpfile, - :line => 'inserted = line', - :after => '^foo1', + name: 'foo', + path: tmpfile, + line: 'inserted = line', + after: '^foo1', ) end @@ -168,11 +170,11 @@ let(:after) { '^foo1$' } let(:resource) do Puppet::Type::File_line.new( - :name => 'foo', - :path => tmpfile, - :line => 'inserted = line', - :after => after, - :match => match, + name: 'foo', + path: tmpfile, + line: 'inserted = line', + after: after, + match: match, ) end end @@ -226,7 +228,7 @@ end it 'adds the line after all lines matching the after expression' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'inserted = line', :after => '^foo1$', :multiple => true) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'inserted = line', after: '^foo1$', multiple: true) @provider = provider_class.new(@resource) @provider.create expect(File.read(tmpfile).chomp).to eql("foo1\ninserted = line\nfoo = blah\nfoo2\nfoo1\ninserted = line\nfoo = baz") @@ -253,10 +255,10 @@ # file fixtures once the following pull request has been merged: # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files @resource = Puppet::Type::File_line.new( - :name => 'foo', - :path => tmpfile, - :line => 'foo', - :ensure => 'absent', + name: 'foo', + path: tmpfile, + line: 'foo', + ensure: 'absent', ) @provider = provider_class.new(@resource) end @@ -276,7 +278,7 @@ expect(File.read(tmpfile)).to eql("foo1\nfoo2\n") end it 'example in the docs' do - @resource = Puppet::Type::File_line.new(:name => 'bashrc_proxy', :ensure => 'absent', :path => tmpfile, :line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128') + @resource = Puppet::Type::File_line.new(name: 'bashrc_proxy', ensure: 'absent', path: tmpfile, line: 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128') @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nexport HTTP_PROXY=http://squid.puppetlabs.vm:3128\nfoo4\n") } @provider.destroy @@ -286,12 +288,12 @@ context 'when removing with a match' do before :each do @resource = Puppet::Type::File_line.new( - :name => 'foo', - :path => tmpfile, - :line => 'foo2', - :ensure => 'absent', - :match => 'o$', - :match_for_absence => true, + name: 'foo', + path: tmpfile, + line: 'foo2', + ensure: 'absent', + match: 'o$', + match_for_absence: true, ) @provider = provider_class.new(@resource) end @@ -308,7 +310,7 @@ end it 'the line parameter is actually not used at all but is silently ignored if here' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'supercalifragilisticexpialidocious', :ensure => 'absent', :match => 'o$', :match_for_absence => true) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'supercalifragilisticexpialidocious', ensure: 'absent', match: 'o$', match_for_absence: true) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } @provider.destroy @@ -316,7 +318,7 @@ end it 'and may not be here and does not need to be here' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :ensure => 'absent', :match => 'o$', :match_for_absence => true) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, ensure: 'absent', match: 'o$', match_for_absence: true) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } @provider.destroy @@ -329,7 +331,7 @@ end it 'removes multiple lines if :multiple is true' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'foo2', :ensure => 'absent', :match => 'o$', :multiple => true, :match_for_absence => true) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo2', ensure: 'absent', match: 'o$', multiple: true, match_for_absence: true) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2\nfoo\nfoo") } @provider.destroy @@ -337,7 +339,7 @@ end it 'ignores the match if match_for_absence is not specified' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'foo2', :ensure => 'absent', :match => 'o$') + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo2', ensure: 'absent', match: 'o$') @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } @provider.destroy @@ -345,7 +347,7 @@ end it 'ignores the match if match_for_absence is false' do - @resource = Puppet::Type::File_line.new(:name => 'foo', :path => tmpfile, :line => 'foo2', :ensure => 'absent', :match => 'o$', :match_for_absence => false) + @resource = Puppet::Type::File_line.new(name: 'foo', path: tmpfile, line: 'foo2', ensure: 'absent', match: 'o$', match_for_absence: false) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo\nfoo2") } @provider.destroy @@ -354,8 +356,8 @@ it 'example in the docs' do @resource = Puppet::Type::File_line.new( - :name => 'bashrc_proxy', :ensure => 'absent', :path => tmpfile, :line => 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', - :match => '^export\ HTTP_PROXY\=', :match_for_absence => true + name: 'bashrc_proxy', ensure: 'absent', path: tmpfile, line: 'export HTTP_PROXY=http://squid.puppetlabs.vm:3128', + match: '^export\ HTTP_PROXY\=', match_for_absence: true ) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n") } @@ -364,7 +366,7 @@ end it 'example in the docs showing line is redundant' do - @resource = Puppet::Type::File_line.new(:name => 'bashrc_proxy', :ensure => 'absent', :path => tmpfile, :match => '^export\ HTTP_PROXY\=', :match_for_absence => true) + @resource = Puppet::Type::File_line.new(name: 'bashrc_proxy', ensure: 'absent', path: tmpfile, match: '^export\ HTTP_PROXY\=', match_for_absence: true) @provider = provider_class.new(@resource) File.open(tmpfile, 'w') { |fh| fh.write("foo1\nfoo2\nexport HTTP_PROXY=foo\nfoo4\n") } @provider.destroy diff --git a/spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb b/spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb index 5114decb6..456ddd614 100644 --- a/spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb +++ b/spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'spec_helper' provider_class = Puppet::Type.type(:file_line).provider(:ruby) #  These tests fail on windows when run as part of the rake task. Individually they pass -describe provider_class, :unless => Puppet::Util::Platform.windows? do +describe provider_class, unless: Puppet::Util::Platform.windows? do include PuppetlabsSpec::Files let :tmpfile do @@ -16,9 +18,9 @@ end let :resource do Puppet::Type::File_line.new({ - :name => 'foo', - :path => tmpfile, - :line => 'foo', + name: 'foo', + path: tmpfile, + line: 'foo', }.merge(params)) end let :provider do @@ -35,9 +37,9 @@ describe 'MODULES-5003' do let(:params) do { - :line => "*\thard\tcore\t0", - :match => "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*", - :multiple => true, + line: "*\thard\tcore\t0", + match: "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*", + multiple: true, } end let(:content) { "* hard core 90\n* hard core 10\n" } @@ -54,9 +56,9 @@ describe 'MODULES-5003 - one match, one line - just ensure the line exists' do let(:params) do { - :line => "*\thard\tcore\t0", - :match => "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*", - :multiple => true, + line: "*\thard\tcore\t0", + match: "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*", + multiple: true, } end let(:content) { "* hard core 90\n* hard core 0\n" } @@ -69,11 +71,11 @@ describe 'MODULES-5003 - one match, one line - replace all matches, even when line exists' do let(:params) do { - :line => "*\thard\tcore\t0", - :match => "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*", - :multiple => true, + line: "*\thard\tcore\t0", + match: "^[ \t]*\\*[ \t]+hard[ \t]+core[ \t]+.*", + multiple: true, - }.merge(:replace_all_matches_not_matching_line => true) + }.merge(replace_all_matches_not_matching_line: true) end let(:content) { "* hard core 90\n* hard core 0\n" } @@ -89,8 +91,8 @@ describe 'MODULES-5651 - match, no line' do let(:params) do { - :line => 'LogLevel=notice', - :match => '^#LogLevel$', + line: 'LogLevel=notice', + match: '^#LogLevel$', } end let(:content) { "#LogLevel\nstuff" } @@ -107,8 +109,8 @@ describe 'MODULES-5651 - match, line' do let(:params) do { - :line => 'LogLevel=notice', - :match => '^#LogLevel$', + line: 'LogLevel=notice', + match: '^#LogLevel$', } end let(:content) { "#Loglevel\nLogLevel=notice\nstuff" } @@ -121,8 +123,8 @@ describe 'MODULES-5651 - no match, line' do let(:params) do { - :line => 'LogLevel=notice', - :match => '^#LogLevel$', + line: 'LogLevel=notice', + match: '^#LogLevel$', } end let(:content) { "LogLevel=notice\nstuff" } diff --git a/spec/unit/puppet/type/anchor_spec.rb b/spec/unit/puppet/type/anchor_spec.rb index c2d9779a6..9dc4ebd65 100644 --- a/spec/unit/puppet/type/anchor_spec.rb +++ b/spec/unit/puppet/type/anchor_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'spec_helper' -anchor = Puppet::Type.type(:anchor).new(:name => 'ntp::begin') +anchor = Puppet::Type.type(:anchor).new(name: 'ntp::begin') describe anchor do it 'stringifies normally' do diff --git a/spec/unit/puppet/type/file_line_spec.rb b/spec/unit/puppet/type/file_line_spec.rb index 627bdf0b1..e506b133a 100644 --- a/spec/unit/puppet/type/file_line_spec.rb +++ b/spec/unit/puppet/type/file_line_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'tempfile' describe Puppet::Type.type(:file_line) do @@ -16,7 +18,7 @@ end end let :file_line do - Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'line', :path => tmp_path) + Puppet::Type.type(:file_line).new(name: 'foo', line: 'line', path: tmp_path) end it 'accepts a line' do @@ -35,28 +37,28 @@ it 'accepts a match regex that does not match the specified line' do expect { Puppet::Type.type(:file_line).new( - :name => 'foo', :path => my_path, :line => 'foo=bar', :match => '^bar=blah$', + name: 'foo', path: my_path, line: 'foo=bar', match: '^bar=blah$', ) }.not_to raise_error end it 'accepts a match regex that does match the specified line' do expect { Puppet::Type.type(:file_line).new( - :name => 'foo', :path => my_path, :line => 'foo=bar', :match => '^\s*foo=.*$', + name: 'foo', path: my_path, line: 'foo=bar', match: '^\s*foo=.*$', ) }.not_to raise_error end it 'accepts utf8 characters' do expect { Puppet::Type.type(:file_line).new( - :name => 'ƒồỗ', :path => my_path, :line => 'ƒồỗ=ьåя', :match => '^ьåя=βļάħ$', + name: 'ƒồỗ', path: my_path, line: 'ƒồỗ=ьåя', match: '^ьåя=βļάħ$', ) }.not_to raise_error end it 'accepts double byte characters' do expect { Puppet::Type.type(:file_line).new( - :name => 'フーバー', :path => my_path, :line => 'この=それ', :match => '^この=ああ$', + name: 'フーバー', path: my_path, line: 'この=それ', match: '^この=ああ$', ) }.not_to raise_error end @@ -68,16 +70,16 @@ expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, %r{File paths must be fully qualified}) end it 'requires that a line is specified' do - expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => tmp_path) }.to raise_error(Puppet::Error, %r{line is a required attribute}) + expect { Puppet::Type.type(:file_line).new(name: 'foo', path: tmp_path) }.to raise_error(Puppet::Error, %r{line is a required attribute}) end it 'does not require that a line is specified when matching for absence' do - expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => tmp_path, :ensure => :absent, :match_for_absence => :true, :match => 'match') }.not_to raise_error # rubocop:disable Metrics/LineLength + expect { Puppet::Type.type(:file_line).new(name: 'foo', path: tmp_path, ensure: :absent, match_for_absence: :true, match: 'match') }.not_to raise_error end it 'although if a line is specified anyway when matching for absence it still works and the line is silently ignored' do - expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => tmp_path, :line => 'i_am_irrelevant', :ensure => :absent, :match_for_absence => :true, :match => 'match') }.not_to raise_error # rubocop:disable Metrics/LineLength + expect { Puppet::Type.type(:file_line).new(name: 'foo', path: tmp_path, line: 'i_am_irrelevant', ensure: :absent, match_for_absence: :true, match: 'match') }.not_to raise_error end it 'requires that a file is specified' do - expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, %r{path is a required attribute}) + expect { Puppet::Type.type(:file_line).new(name: 'foo', line: 'path') }.to raise_error(Puppet::Error, %r{path is a required attribute}) end it 'defaults to ensure => present' do expect(file_line[:ensure]).to eq :present @@ -89,12 +91,12 @@ expect(file_line[:encoding]).to eq 'UTF-8' end it 'accepts encoding => iso-8859-1' do - expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => tmp_path, :ensure => :present, :encoding => 'iso-8859-1', :line => 'bar') }.not_to raise_error + expect { Puppet::Type.type(:file_line).new(name: 'foo', path: tmp_path, ensure: :present, encoding: 'iso-8859-1', line: 'bar') }.not_to raise_error end it 'autorequires the file it manages' do catalog = Puppet::Resource::Catalog.new - file = Puppet::Type.type(:file).new(:name => tmp_path) + file = Puppet::Type.type(:file).new(name: tmp_path) catalog.add_resource file catalog.add_resource file_line relationship = file_line.autorequire.find do |rel|