Skip to content

Commit 07b14b4

Browse files
authored
Merge pull request #9279 from AriaXLi/PUP-11993/more_style_cops
(PUP-11993) More Style cops!
2 parents d068941 + 4ef4d31 commit 07b14b4

File tree

119 files changed

+331
-315
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+331
-315
lines changed

.rubocop.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ Layout/IndentationWidth:
3333
Layout/LineEndStringConcatenationIndentation:
3434
Enabled: true
3535

36+
# Enabling this cop will remove raising RuntimeErrors and cause spec test
37+
# failures
38+
Style/RedundantException:
39+
Exclude:
40+
- 'lib/puppet/file_bucket/dipper.rb'
41+
- 'lib/puppet/forge.rb'
42+
- 'lib/puppet/module_tool/applications/unpacker.rb'
43+
- 'lib/puppet/module_tool/local_tarball.rb'
44+
- 'lib/puppet/module_tool/tar.rb'
45+
- 'lib/puppet/pops/types/class_loader.rb'
46+
47+
# Enabling this cop causes a plethora of failed rspec tests, mostly
48+
# Errno::ENAMETOOLONG and Puppet::Context::UndefinedBindingError: Unable to
49+
# lookup 'environments' errors
50+
Style/RedundantSelfAssignment:
51+
Exclude:
52+
- 'lib/puppet/context.rb'
53+
3654
# Explicitly enables this cop new in 1.7
3755
Layout/SpaceBeforeBrackets:
3856
Enabled: true

.rubocop_todo.yml

Lines changed: 6 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ Lint/RedundantDirGlobSort: # new in 1.8
128128
Lint/RedundantRegexpQuantifiers: # new in 1.53
129129
Enabled: false
130130

131+
# Unsure how the changes in portage.rb from Lint/RedundantSplatExpansion impact
132+
# the code
133+
Lint/RedundantSplatExpansion:
134+
Exclude:
135+
- 'lib/puppet/provider/package/portage.rb'
136+
131137
Lint/RefinementImportMethods: # new in 1.27
132138
Enabled: false
133139

@@ -646,76 +652,10 @@ Style/OptionalBooleanParameter:
646652
Style/PreferredHashMethods:
647653
Enabled: false
648654

649-
# This cop supports safe auto-correction (--auto-correct).
650-
Style/RedundantConditional:
651-
Exclude:
652-
- 'lib/puppet/type/exec.rb'
653-
- 'lib/puppet/type/file.rb'
654-
655-
# This cop supports safe auto-correction (--auto-correct).
656-
Style/RedundantException:
657-
Exclude:
658-
- 'lib/puppet/file_bucket/dipper.rb'
659-
- 'lib/puppet/forge.rb'
660-
- 'lib/puppet/module_tool/applications/unpacker.rb'
661-
- 'lib/puppet/module_tool/local_tarball.rb'
662-
- 'lib/puppet/module_tool/tar.rb'
663-
- 'lib/puppet/pops/types/class_loader.rb'
664-
665655
# This cop supports unsafe auto-correction (--auto-correct-all).
666-
# Configuration parameters: SafeForConstants.
667-
Style/RedundantFetchBlock:
668-
Exclude:
669-
- 'lib/puppet/pops/types/p_sem_ver_range_type.rb'
670-
671-
# This cop supports safe auto-correction (--auto-correct).
672-
Style/RedundantFileExtensionInRequire:
673-
Exclude:
674-
- 'lib/puppet/parser.rb'
675-
- 'lib/puppet/type/file/content.rb'
676-
- 'lib/puppet/util/rdoc/parser.rb'
677-
- 'lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb'
678-
679-
# This cop supports safe auto-correction (--auto-correct).
680656
Style/RedundantInterpolation:
681657
Enabled: false
682658

683-
# This cop supports safe auto-correction (--auto-correct).
684-
Style/RedundantParentheses:
685-
Enabled: false
686-
687-
# This cop supports safe auto-correction (--auto-correct).
688-
Style/RedundantPercentQ:
689-
Exclude:
690-
- 'lib/puppet/defaults.rb'
691-
- 'lib/puppet/indirector/catalog/store_configs.rb'
692-
- 'lib/puppet/indirector/facts/store_configs.rb'
693-
- 'lib/puppet/indirector/node/store_configs.rb'
694-
- 'lib/puppet/indirector/resource/store_configs.rb'
695-
- 'lib/puppet/provider/package/dpkg.rb'
696-
- 'lib/puppet/provider/package/rpm.rb'
697-
- 'lib/puppet/type.rb'
698-
- 'lib/puppet/util/at_fork/solaris.rb'
699-
700-
# This cop supports safe auto-correction (--auto-correct).
701-
Style/RedundantRegexpCharacterClass:
702-
Exclude:
703-
- 'lib/puppet/application/apply.rb'
704-
- 'lib/puppet/module.rb'
705-
- 'lib/puppet/pops/lookup/interpolation.rb'
706-
- 'lib/puppet/pops/parser/lexer2.rb'
707-
- 'lib/puppet/pops/parser/slurp_support.rb'
708-
- 'lib/puppet/pops/patterns.rb'
709-
- 'lib/puppet/pops/pcore.rb'
710-
- 'lib/puppet/provider/package/openbsd.rb'
711-
- 'lib/puppet/settings/config_file.rb'
712-
- 'lib/puppet/type/exec.rb'
713-
- 'lib/puppet/util/command_line/trollop.rb'
714-
715-
# This cop supports safe auto-correction (--auto-correct).
716-
Style/RedundantRegexpEscape:
717-
Enabled: false
718-
719659
# This cop supports safe auto-correction (--auto-correct).
720660
# Configuration parameters: AllowMultipleReturnValues.
721661
Style/RedundantReturn:
@@ -725,44 +665,6 @@ Style/RedundantReturn:
725665
Style/RedundantSelf:
726666
Enabled: false
727667

728-
# This cop supports unsafe auto-correction (--auto-correct-all).
729-
Style/RedundantSelfAssignment:
730-
Exclude:
731-
- 'lib/puppet/context.rb'
732-
733-
# This cop supports unsafe auto-correction (--auto-correct-all).
734-
Style/RedundantSort:
735-
Exclude:
736-
- 'lib/puppet/interface/face_collection.rb'
737-
- 'lib/puppet/module/plan.rb'
738-
- 'lib/puppet/module_tool/applications/unpacker.rb'
739-
- 'lib/puppet/provider/package/apt.rb'
740-
- 'lib/puppet/provider/package/yum.rb'
741-
- 'lib/puppet/provider/package/zypper.rb'
742-
743-
# This cop supports safe auto-correction (--auto-correct).
744-
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
745-
# SupportedStyles: slashes, percent_r, mixed
746-
Style/RegexpLiteral:
747-
Enabled: false
748-
749-
# This cop supports safe auto-correction (--auto-correct).
750-
Style/RescueModifier:
751-
Exclude:
752-
- 'lib/puppet/file_serving/metadata.rb'
753-
- 'lib/puppet/file_system/uniquefile.rb'
754-
- 'lib/puppet/file_system/windows.rb'
755-
- 'lib/puppet/module_tool/applications/application.rb'
756-
- 'lib/puppet/module_tool/applications/installer.rb'
757-
- 'lib/puppet/module_tool/applications/upgrader.rb'
758-
- 'lib/puppet/module_tool/metadata.rb'
759-
- 'lib/puppet/module_tool/shared_behaviors.rb'
760-
- 'lib/puppet/provider/file/posix.rb'
761-
- 'lib/puppet/util.rb'
762-
- 'lib/puppet/util/execution.rb'
763-
- 'lib/puppet/util/reference.rb'
764-
- 'lib/puppet/util/windows/adsi.rb'
765-
766668
# This cop supports safe auto-correction (--auto-correct).
767669
# Configuration parameters: EnforcedStyle.
768670
# SupportedStyles: implicit, explicit

lib/puppet/application/agent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def enable_disable_client(agent)
509509
end
510510

511511
def setup_agent
512-
agent = Puppet::Agent.new(Puppet::Configurer, (!(Puppet[:onetime])))
512+
agent = Puppet::Agent.new(Puppet::Configurer, !(Puppet[:onetime]))
513513

514514
enable_disable_client(agent) if options[:enable] or options[:disable]
515515

lib/puppet/application/apply.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def main
224224
$stderr.puts _("%{file} is not readable") % { file: file }
225225
exit(63)
226226
end
227-
node.classes = Puppet::FileSystem.read(file, :encoding => 'utf-8').split(/[\s]+/)
227+
node.classes = Puppet::FileSystem.read(file, :encoding => 'utf-8').split(/\s+/)
228228
end
229229
end
230230

lib/puppet/application/describe.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def wrap(txt, opts)
1111
return "" unless txt && !txt.empty?
1212

1313
work = (opts[:scrub] ? scrub(txt) : txt)
14-
indent = (opts[:indent] || 0)
14+
indent = opts[:indent] || 0
1515
textLen = @width - indent
1616
patt = Regexp.new("\\A(.{0,#{textLen}})[ \n]")
1717
prefix = " " * indent

lib/puppet/application/face_base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def setup
205205
@arguments << options
206206

207207
# If we don't have a rendering format, set one early.
208-
self.render_as ||= (@action.render_as || :console)
208+
self.render_as ||= @action.render_as || :console
209209
end
210210

211211
def main

lib/puppet/defaults.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def self.default_vendormoduledir
7777
# see the docs for Settings.define_settings
7878
############################################################################################
7979

80-
AS_DURATION = %q{This setting can be a time interval in seconds (30 or 30s), minutes (30m), hours (6h), days (2d), or years (5y).}
80+
AS_DURATION = 'This setting can be a time interval in seconds (30 or 30s), minutes (30m), hours (6h), days (2d), or years (5y).'
8181

8282
# @api public
8383
# @param args [Puppet::Settings] the settings object to define default settings for
@@ -489,7 +489,7 @@ def self.initialize_default_settings!(settings)
489489
},
490490
:daemonize => {
491491
:type => :boolean,
492-
:default => (!Puppet::Util::Platform.windows?),
492+
:default => !Puppet::Util::Platform.windows?,
493493
:desc => "Whether to send the process into the background. This defaults
494494
to true on POSIX systems, and to false on Windows (where Puppet
495495
currently cannot daemonize).",
@@ -650,7 +650,7 @@ def self.initialize_default_settings!(settings)
650650
:http_proxy_password =>{
651651
:default => "none",
652652
:hook => proc do |value|
653-
if value =~ /[@!# \/]/
653+
if value =~ %r{[@!# /]}
654654
raise "Passwords set in the http_proxy_password setting must be valid as part of a URL, and any reserved characters must be URL-encoded. We received: #{value}"
655655
end
656656
end,

lib/puppet/face/help.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def erb(name)
147147
# Return a list of applications that are not simply just stubs for Faces.
148148
def legacy_applications
149149
Puppet::Application.available_application_names.reject do |appname|
150-
(is_face_app?(appname)) or (exclude_from_docs?(appname))
150+
is_face_app?(appname) or exclude_from_docs?(appname)
151151
end.sort
152152
end
153153

@@ -208,7 +208,7 @@ def horribly_extract_summary_from(appname)
208208
# formatted. If we can't match the pattern we expect we return the empty
209209
# string to ensure we don't blow up in the summary. --daniel 2011-04-11
210210
while line = help.shift do # rubocop:disable Lint/AssignmentInCondition
211-
md = /^puppet-#{appname}\([^\)]+\) -- (.*)$/.match(line)
211+
md = /^puppet-#{appname}\([^)]+\) -- (.*)$/.match(line)
212212
if md
213213
return md[1]
214214
end

lib/puppet/file_serving/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def split_path(request)
5656

5757
mount_name, path = request.key.split(File::Separator, 2)
5858

59-
raise(ArgumentError, _("Cannot find file: Invalid mount '%{mount_name}'") % { mount_name: mount_name }) unless mount_name =~ %r{^[-\w]+$}
59+
raise(ArgumentError, _("Cannot find file: Invalid mount '%{mount_name}'") % { mount_name: mount_name }) unless mount_name =~ /^[-\w]+$/
6060
raise(ArgumentError, _("Cannot find file: Invalid relative path '%{path}'") % { path: path }) if path and path.split('/').include?('..')
6161

6262
mount = find_mount(mount_name, request.environment)
@@ -71,7 +71,7 @@ def split_path(request)
7171
path = nil
7272
elsif path
7373
# Remove any double slashes that might have occurred
74-
path = path.gsub(/\/+/, "/")
74+
path = path.gsub(%r{/+}, "/")
7575
end
7676

7777
return mount, path

lib/puppet/file_serving/fileset.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.merge(*filesets)
2929
def initialize(path, options = {})
3030
if Puppet::Util::Platform.windows?
3131
# REMIND: UNC path
32-
path = path.chomp(File::SEPARATOR) unless path =~ /^[A-Za-z]:\/$/
32+
path = path.chomp(File::SEPARATOR) unless path =~ %r{^[A-Za-z]:/$}
3333
else
3434
path = path.chomp(File::SEPARATOR) unless path == File::SEPARATOR
3535
end

0 commit comments

Comments
 (0)