Skip to content

Commit

Permalink
(PUP-11993) Style/WordArray
Browse files Browse the repository at this point in the history
This commit enables the Style/WordArray cop and fixes 41
autocorrectable offenses.
  • Loading branch information
AriaXLi committed Mar 8, 2024
1 parent 27a5441 commit 8d42434
Show file tree
Hide file tree
Showing 28 changed files with 53 additions and 59 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/application/lookup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/coercion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/puppet/defaults.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions lib/puppet/external/dot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/indirector/facts/facter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/network/http/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/lookup/hiera_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/dpkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/package/puppetserver_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/provider/package/windows/msi_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/package/windows/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/service/debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/service/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/service/redhat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/service/smf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/provider/service/systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/service/upstart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/provider/user/directoryservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/resource/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/type/file/data_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/util/package/version/pip.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/util/posix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/selinux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8d42434

Please sign in to comment.