Skip to content

Commit 050c7b4

Browse files
authored
Merge pull request #9203 from mhashizume/PUP-11768/main/layout-and-cops-6
Layout Cops
2 parents 6fd9af4 + 6cb3b8c commit 050c7b4

File tree

484 files changed

+2541
-2780
lines changed

Some content is hidden

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

484 files changed

+2541
-2780
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ Layout/IndentationWidth:
3030
Layout/LineEndStringConcatenationIndentation:
3131
Enabled: true
3232

33+
# Explicitly enables this cop new in 1.7
34+
Layout/SpaceBeforeBrackets:
35+
Enabled: true
36+
3337
# puppet uses symbol booleans in types and providers to work around long standing
3438
# bugs when trying to manage falsey pararameters and properties
3539
Lint/BooleanSymbol:

.rubocop_todo.yml

Lines changed: 0 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -22,194 +22,6 @@ I18n/GetText/DecorateStringFormattingUsingPercent:
2222
I18n/RailsI18n/DecorateString:
2323
Enabled: false
2424

25-
# This cop supports safe auto-correction (--auto-correct).
26-
Layout/SpaceAfterNot:
27-
Enabled: false
28-
29-
# This cop supports safe auto-correction (--auto-correct).
30-
Layout/SpaceAfterSemicolon:
31-
Exclude:
32-
- 'lib/puppet/util/retry_action.rb'
33-
34-
# This cop supports safe auto-correction (--auto-correct).
35-
# Configuration parameters: EnforcedStyleInsidePipes.
36-
# SupportedStylesInsidePipes: space, no_space
37-
Layout/SpaceAroundBlockParameters:
38-
Exclude:
39-
- 'lib/puppet/functions/dig.rb'
40-
- 'lib/puppet/functions/filter.rb'
41-
- 'lib/puppet/node/environment.rb'
42-
- 'lib/puppet/pal/pal_impl.rb'
43-
- 'lib/puppet/pops/evaluator/compare_operator.rb'
44-
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
45-
- 'lib/puppet/pops/functions/dispatcher.rb'
46-
- 'lib/puppet/pops/types/string_converter.rb'
47-
- 'lib/puppet/provider/package/openbsd.rb'
48-
- 'lib/puppet/provider/package/pkg.rb'
49-
- 'lib/puppet/provider/package/yum.rb'
50-
- 'lib/puppet/resource/catalog.rb'
51-
- 'lib/puppet/type.rb'
52-
- 'lib/puppet/util.rb'
53-
- 'lib/puppet/util/docs.rb'
54-
55-
# This cop supports safe auto-correction (--auto-correct).
56-
# Configuration parameters: EnforcedStyle.
57-
# SupportedStyles: space, no_space
58-
Layout/SpaceAroundEqualsInParameterDefault:
59-
Enabled: false
60-
61-
# This cop supports safe auto-correction (--auto-correct).
62-
Layout/SpaceAroundKeyword:
63-
Exclude:
64-
- 'lib/puppet/functions/max.rb'
65-
- 'lib/puppet/functions/min.rb'
66-
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
67-
- 'lib/puppet/pops/lookup/global_data_provider.rb'
68-
- 'lib/puppet/pops/lookup/hiera_config.rb'
69-
- 'lib/puppet/pops/parser/slurp_support.rb'
70-
- 'lib/puppet/pops/types/p_object_type.rb'
71-
- 'lib/puppet/pops/types/type_calculator.rb'
72-
- 'lib/puppet/pops/validation/checker4_0.rb'
73-
- 'lib/puppet/util/diff.rb'
74-
- 'lib/puppet/util/windows/daemon.rb'
75-
76-
# This cop supports safe auto-correction (--auto-correct).
77-
Layout/SpaceAroundMethodCallOperator:
78-
Exclude:
79-
- 'lib/puppet/network/formats.rb'
80-
81-
# This cop supports safe auto-correction (--auto-correct).
82-
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
83-
# SupportedStylesForExponentOperator: space, no_space
84-
Layout/SpaceAroundOperators:
85-
Enabled: false
86-
87-
# This cop supports safe auto-correction (--auto-correct).
88-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
89-
# SupportedStyles: space, no_space
90-
# SupportedStylesForEmptyBraces: space, no_space
91-
Layout/SpaceBeforeBlockBraces:
92-
Enabled: false
93-
94-
# This cop supports safe auto-correction (--auto-correct).
95-
Layout/SpaceBeforeComma:
96-
Exclude:
97-
- 'lib/puppet/application/lookup.rb'
98-
- 'lib/puppet/external/dot.rb'
99-
- 'lib/puppet/face/parser.rb'
100-
- 'lib/puppet/indirector/file_bucket_file/file.rb'
101-
- 'lib/puppet/parser/compiler.rb'
102-
- 'lib/puppet/parser/script_compiler.rb'
103-
- 'lib/puppet/pops/lookup/global_data_provider.rb'
104-
- 'lib/puppet/pops/parser/lexer2.rb'
105-
- 'lib/puppet/provider/package/windows.rb'
106-
- 'lib/puppet/provider/package/windows/exe_package.rb'
107-
- 'lib/puppet/util/windows/monkey_patches/process.rb'
108-
- 'lib/puppet/util/windows/user.rb'
109-
110-
# This cop supports safe auto-correction (--auto-correct).
111-
# Configuration parameters: AllowForAlignment.
112-
Layout/SpaceBeforeFirstArg:
113-
Exclude:
114-
- 'lib/puppet/file_serving/configuration.rb'
115-
- 'lib/puppet/functions/defined.rb'
116-
- 'lib/puppet/parser/type_loader.rb'
117-
- 'lib/puppet/pops/types/types.rb'
118-
- 'lib/puppet/provider/package/aix.rb'
119-
- 'lib/puppet/provider/package/nim.rb'
120-
- 'lib/puppet/provider/package/rug.rb'
121-
- 'lib/puppet/type/service.rb'
122-
123-
# This cop supports safe auto-correction (--auto-correct).
124-
Layout/SpaceBeforeSemicolon:
125-
Exclude:
126-
- 'lib/puppet/functions.rb'
127-
- 'lib/puppet/network/http/connection.rb'
128-
- 'lib/puppet/pops/model/model_label_provider.rb'
129-
- 'lib/puppet/pops/parser/slurp_support.rb'
130-
- 'lib/puppet/pops/types/class_loader.rb'
131-
- 'lib/puppet/pops/types/type_formatter.rb'
132-
- 'lib/puppet/settings/errors.rb'
133-
- 'lib/puppet/util/network_device/base.rb'
134-
- 'lib/puppet/util/windows.rb'
135-
- 'lib/puppet/util/windows/eventlog.rb'
136-
137-
# This cop supports safe auto-correction (--auto-correct).
138-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
139-
# SupportedStyles: space, no_space, compact
140-
# SupportedStylesForEmptyBrackets: space, no_space
141-
Layout/SpaceInsideArrayLiteralBrackets:
142-
Enabled: false
143-
144-
# This cop supports safe auto-correction (--auto-correct).
145-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
146-
# SupportedStyles: space, no_space
147-
# SupportedStylesForEmptyBraces: space, no_space
148-
Layout/SpaceInsideBlockBraces:
149-
Enabled: false
150-
151-
# This cop supports safe auto-correction (--auto-correct).
152-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
153-
# SupportedStyles: space, no_space, compact
154-
# SupportedStylesForEmptyBraces: space, no_space
155-
Layout/SpaceInsideHashLiteralBraces:
156-
Enabled: false
157-
158-
# This cop supports safe auto-correction (--auto-correct).
159-
# Configuration parameters: EnforcedStyle.
160-
# SupportedStyles: space, compact, no_space
161-
Layout/SpaceInsideParens:
162-
Enabled: false
163-
164-
# This cop supports safe auto-correction (--auto-correct).
165-
Layout/SpaceInsidePercentLiteralDelimiters:
166-
Exclude:
167-
- 'ext/windows/service/daemon.rb'
168-
- 'lib/puppet/interface/documentation.rb'
169-
- 'lib/puppet/pops/parser/slurp_support.rb'
170-
171-
# This cop supports safe auto-correction (--auto-correct).
172-
Layout/SpaceInsideRangeLiteral:
173-
Exclude:
174-
- 'lib/puppet/pops/validation/checker4_0.rb'
175-
- 'lib/puppet/util/command_line/trollop.rb'
176-
177-
# This cop supports safe auto-correction (--auto-correct).
178-
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
179-
# SupportedStyles: space, no_space
180-
# SupportedStylesForEmptyBrackets: space, no_space
181-
Layout/SpaceInsideReferenceBrackets:
182-
Exclude:
183-
- 'lib/puppet/application.rb'
184-
- 'lib/puppet/functions/unique.rb'
185-
- 'lib/puppet/parser/scope.rb'
186-
- 'lib/puppet/pops/evaluator/access_operator.rb'
187-
- 'lib/puppet/pops/evaluator/deferred_resolver.rb'
188-
- 'lib/puppet/pops/lookup/hiera_config.rb'
189-
- 'lib/puppet/pops/parser/locator.rb'
190-
- 'lib/puppet/pops/types/string_converter.rb'
191-
- 'lib/puppet/resource/type_collection.rb'
192-
- 'lib/puppet/util/windows/adsi.rb'
193-
- 'lib/puppet/util/windows/process.rb'
194-
195-
# This cop supports safe auto-correction (--auto-correct).
196-
# Configuration parameters: EnforcedStyle.
197-
# SupportedStyles: space, no_space
198-
Layout/SpaceInsideStringInterpolation:
199-
Exclude:
200-
- 'lib/puppet/ssl/ssl_provider.rb'
201-
202-
# This cop supports safe auto-correction (--auto-correct).
203-
# Configuration parameters: EnforcedStyle.
204-
# SupportedStyles: final_newline, final_blank_line
205-
Layout/TrailingEmptyLines:
206-
Enabled: false
207-
208-
# This cop supports safe auto-correction (--auto-correct).
209-
# Configuration parameters: AllowInHeredoc.
210-
Layout/TrailingWhitespace:
211-
Enabled: false
212-
21325
# Configuration parameters: AllowedMethods.
21426
# AllowedMethods: enums
21527
Lint/ConstantDefinitionInBlock:

ext/windows/service/daemon.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def report_windows_event(type, id, message)
161161

162162
def parse_runinterval(puppet_path)
163163
begin
164-
runinterval = %x{ #{puppet_path} config --section agent --log_level notice print runinterval }.to_i
164+
runinterval = %x{#{puppet_path} config --section agent --log_level notice print runinterval}.to_i
165165
if runinterval == 0
166166
runinterval = 1800
167167
log_err("Failed to determine runinterval, defaulting to #{runinterval} seconds")
@@ -176,7 +176,7 @@ def parse_runinterval(puppet_path)
176176

177177
def parse_log_level(puppet_path, cmdline_debug)
178178
begin
179-
loglevel = %x{ #{puppet_path} config --section agent --log_level notice print log_level }.chomp
179+
loglevel = %x{#{puppet_path} config --section agent --log_level notice print log_level}.chomp
180180
unless loglevel && respond_to?("log_#{loglevel}")
181181
loglevel = :notice
182182
log_err("Failed to determine loglevel, defaulting to #{loglevel}")

lib/hiera/puppet_function.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def lookup(scope, key, default, has_default, override, &default_block)
6464
unless Puppet[:strict] == :off
6565
# TRANSLATORS 'lookup' is a puppet function and should not be translated
6666
message = _("The function '%{class_name}' is deprecated in favor of using 'lookup'.") % { class_name: self.class.name }
67-
message += ' '+ _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
68-
{ minor_version: Puppet.minor_version }
67+
message += ' ' + _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
68+
{ minor_version: Puppet.minor_version }
6969
Puppet.warn_once('deprecations', self.class.name, message)
7070
end
7171
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {})

lib/hiera/scope.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def safe_lookupvar(key)
4646
# do nothing
4747
when :warning
4848
Puppet.warn_once(Puppet::Parser::Scope::UNDEFINED_VARIABLES_KIND, _("Variable: %{name}") % { name: key },
49-
_("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason } )
49+
_("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason })
5050
when :error
5151
raise ArgumentError, _("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason }
5252
end

lib/hiera_puppet.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,3 @@ def hiera_config_file
7676
end
7777
end
7878
end
79-

lib/puppet.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ def self.clear
101101

102102
def self.debug=(value)
103103
if value
104-
Puppet::Util::Log.level=(:debug)
104+
Puppet::Util::Log.level = (:debug)
105105
else
106-
Puppet::Util::Log.level=(:notice)
106+
Puppet::Util::Log.level = (:notice)
107107
end
108108
end
109109

lib/puppet/agent.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RunTimeoutError < Exception # rubocop:disable Lint/InheritException
2424

2525
attr_reader :client_class, :client, :should_fork
2626

27-
def initialize(client_class, should_fork=true)
27+
def initialize(client_class, should_fork = true)
2828
@should_fork = can_fork? && should_fork
2929
@client_class = client_class
3030
end
@@ -99,13 +99,13 @@ def run(client_options = {})
9999
nil
100100
else
101101
Puppet.info _("Another puppet instance is already running; --waitforlock flag used, waiting for running instance to finish.")
102-
Puppet.info _("Will try again in %{time} seconds.") % {time: Puppet[:waitforlock]}
102+
Puppet.info _("Will try again in %{time} seconds.") % { time: Puppet[:waitforlock] }
103103
sleep Puppet[:waitforlock]
104104
retry
105105
end
106106
rescue RunTimeoutError => detail
107107
Puppet.log_exception(detail, _("Execution of %{client_class} did not complete within %{runtimeout} seconds and was terminated.") %
108-
{client_class: client_class, runtimeout: Puppet[:runtimeout]})
108+
{ client_class: client_class, runtimeout: Puppet[:runtimeout] })
109109
nil
110110
rescue StandardError => detail
111111
Puppet.log_exception(detail, _("Could not run %{client_class}: %{detail}") % { client_class: client_class, detail: detail })

lib/puppet/agent/disabler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ def enable
2323
end
2424

2525
# Stop the daemon from making any catalog runs.
26-
def disable(msg=nil)
26+
def disable(msg = nil)
2727
data = {}
2828
Puppet.notice _("Disabling Puppet.")
29-
if (! msg.nil?)
29+
if (!msg.nil?)
3030
data[DISABLED_MESSAGE_JSON_KEY] = msg
3131
end
3232
disable_lockfile.lock(data)

lib/puppet/application.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class Application
109109
require_relative '../puppet/util'
110110
include Puppet::Util
111111

112-
DOCPATTERN = ::File.expand_path(::File.dirname(__FILE__) + "/util/command_line/*" )
112+
DOCPATTERN = ::File.expand_path(::File.dirname(__FILE__) + "/util/command_line/*")
113113
CommandLineArgs = Struct.new(:subcommand_name, :args)
114114

115115
@loader = Puppet::Util::Autoload.new(self, 'puppet/application')
@@ -178,7 +178,7 @@ def controlled_run(&block)
178178

179179
# used to declare code that handle an option
180180
def option(*options, &block)
181-
long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1' ).tr('-', '_')
181+
long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1').tr('-', '_')
182182
fname = "handle_#{long}".intern
183183
if (block_given?)
184184
define_method(fname, &block)
@@ -287,7 +287,7 @@ def run_mode(mode_name = nil)
287287
return @run_mode if @run_mode and not mode_name
288288

289289
require_relative '../puppet/util/run_mode'
290-
@run_mode = Puppet::Util::RunMode[ mode_name || Puppet.settings.preferred_run_mode ]
290+
@run_mode = Puppet::Util::RunMode[mode_name || Puppet.settings.preferred_run_mode]
291291
end
292292

293293
# Sets environment_mode name. When acting as a compiler, the environment mode
@@ -501,7 +501,7 @@ def configure_indirector_routes
501501
# to log. Intended to be passed to super by subclasses.
502502
# @return [void]
503503
# @api public
504-
def log_runtime_environment(extra_info=nil)
504+
def log_runtime_environment(extra_info = nil)
505505
runtime_info = {
506506
'puppet_version' => Puppet.version,
507507
'ruby_version' => RUBY_VERSION,
@@ -514,7 +514,7 @@ def log_runtime_environment(extra_info=nil)
514514
runtime_info['default_encoding'] = Encoding.default_external
515515
runtime_info.merge!(extra_info) unless extra_info.nil?
516516

517-
Puppet.debug 'Runtime environment: ' + runtime_info.map{|k, v| k + '=' + v.to_s}.join(', ')
517+
Puppet.debug 'Runtime environment: ' + runtime_info.map { |k, v| k + '=' + v.to_s }.join(', ')
518518
end
519519

520520
# Options defined with the `option` method are parsed from settings and the command line.

0 commit comments

Comments
 (0)