From 8d4243450fc5d3a4d41d4af6be9f2d62693f3731 Mon Sep 17 00:00:00 2001 From: Aria Li Date: Fri, 8 Mar 2024 11:29:57 -0800 Subject: [PATCH] (PUP-11993) Style/WordArray This commit enables the Style/WordArray cop and fixes 41 autocorrectable offenses. --- .rubocop_todo.yml | 6 ----- lib/puppet/application/lookup.rb | 2 +- lib/puppet/coercion.rb | 2 +- lib/puppet/defaults.rb | 2 +- lib/puppet/external/dot.rb | 22 +++++++++---------- lib/puppet/functions.rb | 8 +++---- lib/puppet/indirector/facts/facter.rb | 2 +- lib/puppet/network/http/handler.rb | 2 +- lib/puppet/parser/scope.rb | 2 +- lib/puppet/pops/lookup/hiera_config.rb | 2 +- lib/puppet/provider/package/dpkg.rb | 2 +- lib/puppet/provider/package/pip.rb | 2 +- .../provider/package/puppetserver_gem.rb | 6 ++--- .../provider/package/windows/msi_package.rb | 6 ++--- .../provider/package/windows/package.rb | 2 +- lib/puppet/provider/service/debian.rb | 4 ++-- lib/puppet/provider/service/init.rb | 2 +- lib/puppet/provider/service/redhat.rb | 4 ++-- lib/puppet/provider/service/smf.rb | 2 +- lib/puppet/provider/service/systemd.rb | 10 ++++----- lib/puppet/provider/service/upstart.rb | 2 +- lib/puppet/provider/user/directoryservice.rb | 2 +- lib/puppet/resource/type.rb | 2 +- lib/puppet/settings.rb | 2 +- lib/puppet/type/file/data_sync.rb | 2 +- lib/puppet/util/package/version/pip.rb | 4 ++-- lib/puppet/util/posix.rb | 6 ++--- lib/puppet/util/selinux.rb | 2 +- 28 files changed, 53 insertions(+), 59 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e051f9a6d05..5f033075e75 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -776,12 +776,6 @@ Style/WhileUntilModifier: - 'lib/puppet/pops/types/p_object_type.rb' - 'lib/puppet/util/windows/process.rb' -# This cop supports safe auto-correction (--auto-correct). -# Configuration parameters: EnforcedStyle, MinSize, WordRegex. -# SupportedStyles: percent, brackets -Style/WordArray: - Enabled: false - # This cop supports unsafe auto-correction (--auto-correct-all). # Configuration parameters: EnforcedStyle. # SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only diff --git a/lib/puppet/application/lookup.rb b/lib/puppet/application/lookup.rb index 96a4e5e1faa..384c99f2c5b 100644 --- a/lib/puppet/application/lookup.rb +++ b/lib/puppet/application/lookup.rb @@ -8,7 +8,7 @@ class Puppet::Application::Lookup < Puppet::Application RUN_HELP = _("Run 'puppet lookup --help' for more details").freeze DEEP_MERGE_OPTIONS = '--knock-out-prefix, --sort-merged-arrays, and --merge-hash-arrays' - TRUSTED_INFORMATION_FACTS = ["hostname", "domain", "fqdn", "clientcert"].freeze + TRUSTED_INFORMATION_FACTS = %w[hostname domain fqdn clientcert].freeze run_mode :server diff --git a/lib/puppet/coercion.rb b/lib/puppet/coercion.rb index 2b7d9a4f23b..02c7899c51d 100644 --- a/lib/puppet/coercion.rb +++ b/lib/puppet/coercion.rb @@ -37,6 +37,6 @@ def self.boolean(value) # @raise # @api private def self.boolean_values - ['true', 'false', 'yes', 'no'] + %w[true false yes no] end end diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb index 6fd3235a4d2..f6542f1bb06 100644 --- a/lib/puppet/defaults.rb +++ b/lib/puppet/defaults.rb @@ -132,7 +132,7 @@ def self.initialize_default_settings!(settings) :log_level => { :default => 'notice', :type => :enum, - :values => ["debug","info","notice","warning","err","alert","emerg","crit"], + :values => %w[debug info notice warning err alert emerg crit], :desc => "Default logging level for messages from Puppet. Allowed values are: * debug diff --git a/lib/puppet/external/dot.rb b/lib/puppet/external/dot.rb index c8177a4424d..b1372b1c601 100644 --- a/lib/puppet/external/dot.rb +++ b/lib/puppet/external/dot.rb @@ -100,17 +100,17 @@ def change_tab(t) # options for graph declaration - GRAPH_OPTS = [ - 'bgcolor', - 'center', 'clusterrank', 'color', 'concentrate', - 'fontcolor', 'fontname', 'fontsize', - 'label', 'layerseq', - 'margin', 'mclimit', - 'nodesep', 'nslimit', - 'ordering', 'orientation', - 'page', - 'rank', 'rankdir', 'ranksep', 'ratio', - 'size' + GRAPH_OPTS = %w[ + bgcolor + center clusterrank color concentrate + fontcolor fontname fontsize + label layerseq + margin mclimit + nodesep nslimit + ordering orientation + page + rank rankdir ranksep ratio + size ] # a root class for any element in dot notation diff --git a/lib/puppet/functions.rb b/lib/puppet/functions.rb index d3422c7bd84..74a0f3f46f7 100644 --- a/lib/puppet/functions.rb +++ b/lib/puppet/functions.rb @@ -685,10 +685,10 @@ class Function3x < InternalFunction PARAM_NAMES = [ [], ['p0'].freeze, - ['p0', 'p1'].freeze, - ['p0', 'p1', 'p2'].freeze, - ['p0', 'p1', 'p2', 'p3'].freeze, - ['p0', 'p1', 'p2', 'p3', 'p4'].freeze + %w[p0 p1].freeze, + %w[p0 p1 p2].freeze, + %w[p0 p1 p2 p3].freeze, + %w[p0 p1 p2 p3 p4].freeze ] # Creates an anonymous Function3x class that wraps a 3x function diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb index 9d3aac33f98..8eb847db6d1 100644 --- a/lib/puppet/indirector/facts/facter.rb +++ b/lib/puppet/indirector/facts/facter.rb @@ -57,7 +57,7 @@ def find(request) def self.setup_search_paths(request) # Add any per-module fact directories to facter's search path dirs = request.environment.modulepath.collect do |dir| - ['lib', 'plugins'].map do |subdirectory| + %w[lib plugins].map do |subdirectory| Dir.glob("#{dir}/*/#{subdirectory}/facter") end end.flatten + Puppet[:factpath].split(File::PATH_SEPARATOR) diff --git a/lib/puppet/network/http/handler.rb b/lib/puppet/network/http/handler.rb index becd6a0151d..1f5cd180193 100644 --- a/lib/puppet/network/http/handler.rb +++ b/lib/puppet/network/http/handler.rb @@ -13,7 +13,7 @@ module Puppet::Network::HTTP::Handler # These shouldn't be allowed to be set by clients # in the query string, for security reasons. - DISALLOWED_KEYS = ["node", "ip"] + DISALLOWED_KEYS = %w[node ip] def register(routes) # There's got to be a simpler way to do this, right? diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 9b3fe22db60..8a63566a851 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -17,7 +17,7 @@ class Puppet::Parser::Scope extend Forwardable # Variables that always exist with nil value even if not set - BUILT_IN_VARS = ['module_name', 'caller_module_name'].freeze + BUILT_IN_VARS = %w[module_name caller_module_name].freeze EMPTY_HASH = {}.freeze Puppet::Util.logmethods(self) diff --git a/lib/puppet/pops/lookup/hiera_config.rb b/lib/puppet/pops/lookup/hiera_config.rb index 84708456acd..254b6fde4fd 100644 --- a/lib/puppet/pops/lookup/hiera_config.rb +++ b/lib/puppet/pops/lookup/hiera_config.rb @@ -723,7 +723,7 @@ def has_default_hierarchy? @config.include?(KEY_DEFAULT_HIERARCHY) end - RESERVED_OPTION_KEYS = ['path', 'uri'].freeze + RESERVED_OPTION_KEYS = %w[path uri].freeze DEFAULT_CONFIG_HASH = { KEY_VERSION => 5, diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb index f91b5df5cc0..c2ca0079356 100644 --- a/lib/puppet/provider/package/dpkg.rb +++ b/lib/puppet/provider/package/dpkg.rb @@ -73,7 +73,7 @@ def self.parse_line(line, regex = self::FIELDS_REGEX) if hash[:status] == 'not-installed' hash[:ensure] = :purged - elsif ['config-files', 'half-installed', 'unpacked', 'half-configured'].include?(hash[:status]) + elsif %w[config-files half-installed unpacked half-configured].include?(hash[:status]) hash[:ensure] = :absent end hash[:mark] = hash[:desired] == 'hold' ? :hold : :none diff --git a/lib/puppet/provider/package/pip.rb b/lib/puppet/provider/package/pip.rb index 7c00c73b7b7..c7352a36e5f 100644 --- a/lib/puppet/provider/package/pip.rb +++ b/lib/puppet/provider/package/pip.rb @@ -39,7 +39,7 @@ def self.cmd if Puppet::Util::Platform.windows? ["pip.exe"] else - ["pip", "pip-python", "pip2", "pip-2"] + %w[pip pip-python pip2 pip-2] end end diff --git a/lib/puppet/provider/package/puppetserver_gem.rb b/lib/puppet/provider/package/puppetserver_gem.rb index 474a6155b22..83582c7b247 100644 --- a/lib/puppet/provider/package/puppetserver_gem.rb +++ b/lib/puppet/provider/package/puppetserver_gem.rb @@ -38,7 +38,7 @@ def self.provider_command end def self.gemlist(options) - command_options = ['gem', 'list'] + command_options = %w[gem list] if options[:local] command_options << '--local' @@ -82,7 +82,7 @@ def self.gemlist(options) end def install(useversion = true) - command_options = ['gem', 'install'] + command_options = %w[gem install] command_options += install_options if resource[:install_options] command_options << '-v' << resource[:ensure] if (!resource[:ensure].is_a? Symbol) && useversion @@ -119,7 +119,7 @@ def install(useversion = true) end def uninstall - command_options = ['gem', 'uninstall'] + command_options = %w[gem uninstall] command_options << '--executables' << '--all' << resource[:name] command_options += uninstall_options if resource[:uninstall_options] diff --git a/lib/puppet/provider/package/windows/msi_package.rb b/lib/puppet/provider/package/windows/msi_package.rb index f949f1b7cc8..79c47be465c 100644 --- a/lib/puppet/provider/package/windows/msi_package.rb +++ b/lib/puppet/provider/package/windows/msi_package.rb @@ -13,9 +13,9 @@ class MsiPackage < Puppet::Provider::Package::Windows::Package # registry values to load under each product entry in # HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall # for this provider - REG_VALUE_NAMES = [ - 'DisplayVersion', - 'WindowsInstaller' + REG_VALUE_NAMES = %w[ + DisplayVersion + WindowsInstaller ] # Get the COM installer object, it's in a separate method for testing diff --git a/lib/puppet/provider/package/windows/package.rb b/lib/puppet/provider/package/windows/package.rb index a989f3f2b6f..96a582a4446 100644 --- a/lib/puppet/provider/package/windows/package.rb +++ b/lib/puppet/provider/package/windows/package.rb @@ -13,7 +13,7 @@ class Package attr_reader :name, :version - REG_DISPLAY_VALUE_NAMES = ['DisplayName', 'QuietDisplayName'] + REG_DISPLAY_VALUE_NAMES = %w[DisplayName QuietDisplayName] def self.reg_value_names_to_load REG_DISPLAY_VALUE_NAMES | diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb index 013f41c6dc8..975c2a28b93 100644 --- a/lib/puppet/provider/service/debian.rb +++ b/lib/puppet/provider/service/debian.rb @@ -21,8 +21,8 @@ confine :false => Puppet::FileSystem.exist?('/proc/1/comm') && Puppet::FileSystem.read('/proc/1/comm').include?('systemd') - defaultfor 'os.name' => :cumuluslinux, 'os.release.major' => ['1', '2'] - defaultfor 'os.name' => :debian, 'os.release.major' => ['5', '6', '7'] + defaultfor 'os.name' => :cumuluslinux, 'os.release.major' => %w[1 2] + defaultfor 'os.name' => :debian, 'os.release.major' => %w[5 6 7] defaultfor 'os.name' => :devuan # Remove the symlinks diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb index 5929f52a636..d7097f1b0da 100644 --- a/lib/puppet/provider/service/init.rb +++ b/lib/puppet/provider/service/init.rb @@ -21,7 +21,7 @@ def self.defpath end # Debian and Ubuntu should use the Debian provider. - confine :false => ['Debian', 'Ubuntu'].include?(Puppet.runtime[:facter].value('os.name')) + confine :false => %w[Debian Ubuntu].include?(Puppet.runtime[:facter].value('os.name')) # RedHat systems should use the RedHat provider. confine :false => Puppet.runtime[:facter].value('os.family') == 'RedHat' diff --git a/lib/puppet/provider/service/redhat.rb b/lib/puppet/provider/service/redhat.rb index 535c13a2fe7..e03634acc12 100644 --- a/lib/puppet/provider/service/redhat.rb +++ b/lib/puppet/provider/service/redhat.rb @@ -10,9 +10,9 @@ commands :chkconfig => "/sbin/chkconfig", :service => "/sbin/service" - defaultfor 'os.name' => :amazon, 'os.release.major' => ["2017", "2018"] + defaultfor 'os.name' => :amazon, 'os.release.major' => %w[2017 2018] defaultfor 'os.name' => :redhat, 'os.release.major' => (4..6).to_a - defaultfor 'os.family' => :suse, 'os.release.major' => ["10", "11"] + defaultfor 'os.family' => :suse, 'os.release.major' => %w[10 11] # Remove the symlinks def disable diff --git a/lib/puppet/provider/service/smf.rb b/lib/puppet/provider/service/smf.rb index 446f057f378..59be2179da9 100644 --- a/lib/puppet/provider/service/smf.rb +++ b/lib/puppet/provider/service/smf.rb @@ -262,7 +262,7 @@ def flush fmri = service_fmri # Useful constants for operations involving multiple states - stopped = ['offline', 'disabled', 'uninitialized'] + stopped = %w[offline disabled uninitialized] # Get the current state of the service. cur_state = status diff --git a/lib/puppet/provider/service/systemd.rb b/lib/puppet/provider/service/systemd.rb index 0c27dc9a417..54a1639bdc6 100644 --- a/lib/puppet/provider/service/systemd.rb +++ b/lib/puppet/provider/service/systemd.rb @@ -22,15 +22,15 @@ defaultfor 'os.family' => :suse defaultfor 'os.family' => :coreos defaultfor 'os.family' => :gentoo - notdefaultfor 'os.name' => :amazon, 'os.release.major' => ["2017", "2018"] - defaultfor 'os.name' => :amazon, 'os.release.major' => ["2", "2023"] + notdefaultfor 'os.name' => :amazon, 'os.release.major' => %w[2017 2018] + defaultfor 'os.name' => :amazon, 'os.release.major' => %w[2 2023] defaultfor 'os.name' => :debian - notdefaultfor 'os.name' => :debian, 'os.release.major' => ["5", "6", "7"] # These are using the "debian" method + notdefaultfor 'os.name' => :debian, 'os.release.major' => %w[5 6 7] # These are using the "debian" method defaultfor 'os.name' => :LinuxMint - notdefaultfor 'os.name' => :LinuxMint, 'os.release.major' => ["10", "11", "12", "13", "14", "15", "16", "17"] # These are using upstart + notdefaultfor 'os.name' => :LinuxMint, 'os.release.major' => %w[10 11 12 13 14 15 16 17] # These are using upstart defaultfor 'os.name' => :ubuntu notdefaultfor 'os.name' => :ubuntu, 'os.release.major' => ["10.04", "12.04", "14.04", "14.10"] # These are using upstart - defaultfor 'os.name' => :cumuluslinux, 'os.release.major' => ["3", "4"] + defaultfor 'os.name' => :cumuluslinux, 'os.release.major' => %w[3 4] def self.instances i = [] diff --git a/lib/puppet/provider/service/upstart.rb b/lib/puppet/provider/service/upstart.rb index 9b40866ef42..fac33ae9c4c 100644 --- a/lib/puppet/provider/service/upstart.rb +++ b/lib/puppet/provider/service/upstart.rb @@ -19,7 +19,7 @@ ] defaultfor 'os.name' => :ubuntu, 'os.release.major' => ["10.04", "12.04", "14.04", "14.10"] - defaultfor 'os.name' => :LinuxMint, 'os.release.major' => ["10", "11", "12", "13", "14", "15", "16", "17"] + defaultfor 'os.name' => :LinuxMint, 'os.release.major' => %w[10 11 12 13 14 15 16 17] commands :start => "/sbin/start", :stop => "/sbin/stop", diff --git a/lib/puppet/provider/user/directoryservice.rb b/lib/puppet/provider/user/directoryservice.rb index 8ed5e29a5e1..40e3ca2c29e 100644 --- a/lib/puppet/provider/user/directoryservice.rb +++ b/lib/puppet/provider/user/directoryservice.rb @@ -448,7 +448,7 @@ def salt=(value) # In the event that the user doesn't HAVE a value for the attribute, the # provider should use the -create option with dscl to add the attribute value # for the user record - ['home', 'uid', 'gid', 'comment', 'shell'].each do |setter_method| + %w[home uid gid comment shell].each do |setter_method| define_method("#{setter_method}=") do |value| if @property_hash[setter_method.intern] if %w[home uid].include?(setter_method) diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb index 4129ef4e5de..24ba6416d20 100644 --- a/lib/puppet/resource/type.rb +++ b/lib/puppet/resource/type.rb @@ -189,7 +189,7 @@ def instantiate_resource(scope, resource) parent_type(scope).ensure_in_catalog(scope) end - if ['Class', 'Node'].include? resource.type + if %w[Class Node].include? resource.type scope.catalog.merge_tags_from(resource) end end diff --git a/lib/puppet/settings.rb b/lib/puppet/settings.rb index d338fd5547a..a99cffd886a 100644 --- a/lib/puppet/settings.rb +++ b/lib/puppet/settings.rb @@ -50,7 +50,7 @@ class Puppet::Settings REQUIRED_APP_SETTINGS = [:logdir, :confdir, :vardir, :codedir] # The acceptable sections of the puppet.conf configuration file. - ALLOWED_SECTION_NAMES = ['main', 'server', 'master', 'agent', 'user'].freeze + ALLOWED_SECTION_NAMES = %w[main server master agent user].freeze NONE = 'none' diff --git a/lib/puppet/type/file/data_sync.rb b/lib/puppet/type/file/data_sync.rb index e1b05857e7a..5430535ba03 100644 --- a/lib/puppet/type/file/data_sync.rb +++ b/lib/puppet/type/file/data_sync.rb @@ -83,7 +83,7 @@ def retrieve_checksum(resource) ftype = stat.ftype # Don't even try to manage the content on directories or links - return nil if ['directory', 'link', 'fifo', 'socket'].include?(ftype) + return nil if %w[directory link fifo socket].include?(ftype) begin resource.parameter(:checksum).sum_file(resource[:path]) diff --git a/lib/puppet/util/package/version/pip.rb b/lib/puppet/util/package/version/pip.rb index f799d636126..d30009d4207 100644 --- a/lib/puppet/util/package/version/pip.rb +++ b/lib/puppet/util/package/version/pip.rb @@ -100,9 +100,9 @@ def parse_letter_version(letter, number) letter = "a" elsif letter == "beta" letter = "b" - elsif ["c", "pre", "preview"].include?(letter) + elsif %w[c pre preview].include?(letter) letter = "rc" - elsif ["rev", "r"].include?(letter) + elsif %w[rev r].include?(letter) letter = "post" end diff --git a/lib/puppet/util/posix.rb b/lib/puppet/util/posix.rb index 71cb241d6af..6c1121b4842 100644 --- a/lib/puppet/util/posix.rb +++ b/lib/puppet/util/posix.rb @@ -3,12 +3,12 @@ # Utility methods for interacting with POSIX objects; mostly user and group module Puppet::Util::POSIX # This is a list of environment variables that we will set when we want to override the POSIX locale - LOCALE_ENV_VARS = ['LANG', 'LC_ALL', 'LC_MESSAGES', 'LANGUAGE', - 'LC_COLLATE', 'LC_CTYPE', 'LC_MONETARY', 'LC_NUMERIC', 'LC_TIME'] + LOCALE_ENV_VARS = %w[LANG LC_ALL LC_MESSAGES LANGUAGE + LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME] # This is a list of user-related environment variables that we will unset when we want to provide a pristine # environment for "exec" runs - USER_ENV_VARS = ['HOME', 'USER', 'LOGNAME'] + USER_ENV_VARS = %w[HOME USER LOGNAME] class << self # Returns an array of all the groups that the user's a member of. diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb index 44976924059..cd2c636f2e7 100644 --- a/lib/puppet/util/selinux.rb +++ b/lib/puppet/util/selinux.rb @@ -215,7 +215,7 @@ def selinux_label_support?(file) fstype = find_fs(file) return false if fstype.nil? - filesystems = ['ext2', 'ext3', 'ext4', 'gfs', 'gfs2', 'xfs', 'jfs', 'btrfs', 'tmpfs', 'zfs'] + filesystems = %w[ext2 ext3 ext4 gfs gfs2 xfs jfs btrfs tmpfs zfs] filesystems.include?(fstype) end