Skip to content

Commit 3b42e7d

Browse files
authored
Merge pull request #9197 from mhashizume/PUP-11768/main/layout-cops-hypercube
(PUP-11768) Layout cops
2 parents 272abb9 + 8433171 commit 3b42e7d

File tree

282 files changed

+1013
-1039
lines changed

Some content is hidden

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

282 files changed

+1013
-1039
lines changed

.rubocop.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,20 @@ AllCops:
1515
- 'tasks/**/*'
1616
- 'ext/suse/puppet.spec'
1717
- 'lib/puppet/vendor/**/*'
18+
- 'lib/puppet/pops/model/ast.rb'
1819
- 'lib/puppet/pops/parser/eparser.rb'
1920

2021
# The formatting of defaults is unusual, so let's skip layout cops.
2122
Layout:
2223
Exclude:
2324
- 'lib/puppet/defaults.rb'
2425

25-
# The confine statements in package providers unexpectedly affect this cop.
26-
Layout/BeginEndAlignment:
27-
Enabled: true
28-
Exclude:
29-
- 'lib/puppet/provider/package/*.rb'
30-
31-
Layout/ElseAlignment:
32-
Enabled: true
33-
Exclude:
34-
- 'lib/puppet/provider/package/*.rb'
35-
3626
# We don't mind when module and class keywords are aligned.
3727
Layout/IndentationWidth:
3828
AllowedPatterns: ['^\s*module']
39-
Exclude:
40-
- 'lib/puppet/provider/package/*.rb'
29+
30+
Layout/LineEndStringConcatenationIndentation:
31+
Enabled: true
4132

4233
# puppet uses symbol booleans in types and providers to work around long standing
4334
# bugs when trying to manage falsey pararameters and properties

.rubocop_todo.yml

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

25-
# This cop supports safe auto-correction (--auto-correct).
26-
Layout/LeadingEmptyLines:
27-
Exclude:
28-
- 'lib/puppet/functions/yaml_data.rb'
29-
- 'lib/puppet/info_service.rb'
30-
- 'lib/puppet/parser/abstract_compiler.rb'
31-
- 'lib/puppet/pops/loader/loader_paths.rb'
32-
- 'lib/puppet/pops/parser/code_merger.rb'
33-
- 'lib/puppet/pops/parser/lexer_support.rb'
34-
- 'lib/puppet/pops/types/type_assertion_error.rb'
35-
- 'lib/puppet/pops/types/type_conversion_error.rb'
36-
- 'lib/puppet/provider/network_device.rb'
37-
- 'lib/puppet/type/component.rb'
38-
- 'lib/puppet/type/file/ensure.rb'
39-
- 'lib/puppet/util/network_device/transport/base.rb'
40-
41-
# This cop supports safe auto-correction (--auto-correct).
42-
# Configuration parameters: EnforcedStyle.
43-
# SupportedStyles: symmetrical, new_line, same_line
44-
Layout/MultilineArrayBraceLayout:
45-
Exclude:
46-
- 'lib/puppet/pops/model/ast.rb'
47-
- 'lib/puppet/pops/types/iterable.rb'
48-
- 'lib/puppet/pops/types/types.rb'
49-
- 'lib/puppet/type/file/content.rb'
50-
- 'lib/puppet/util/log/destinations.rb'
51-
52-
# This cop supports safe auto-correction (--auto-correct).
53-
Layout/MultilineBlockLayout:
54-
Exclude:
55-
- 'lib/puppet/provider/service/freebsd.rb'
56-
57-
# This cop supports safe auto-correction (--auto-correct).
58-
# Configuration parameters: EnforcedStyle.
59-
# SupportedStyles: symmetrical, new_line, same_line
60-
Layout/MultilineHashBraceLayout:
61-
Exclude:
62-
- 'lib/puppet/configurer.rb'
63-
- 'lib/puppet/defaults.rb'
64-
- 'lib/puppet/face/facts.rb'
65-
- 'lib/puppet/file_serving/metadata.rb'
66-
- 'lib/puppet/indirector/catalog/compiler.rb'
67-
- 'lib/puppet/info_service/class_information_service.rb'
68-
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
69-
- 'lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb'
70-
- 'lib/puppet/pops/parser/lexer_support.rb'
71-
- 'lib/puppet/ssl/ssl_provider.rb'
72-
73-
# This cop supports safe auto-correction (--auto-correct).
74-
# Configuration parameters: EnforcedStyle.
75-
# SupportedStyles: symmetrical, new_line, same_line
76-
Layout/MultilineMethodCallBraceLayout:
77-
Enabled: false
78-
79-
# This cop supports safe auto-correction (--auto-correct).
80-
# Configuration parameters: EnforcedStyle, IndentationWidth.
81-
# SupportedStyles: aligned, indented, indented_relative_to_receiver
82-
Layout/MultilineMethodCallIndentation:
83-
Enabled: false
84-
85-
# This cop supports safe auto-correction (--auto-correct).
86-
# Configuration parameters: EnforcedStyle.
87-
# SupportedStyles: symmetrical, new_line, same_line
88-
Layout/MultilineMethodDefinitionBraceLayout:
89-
Exclude:
90-
- 'lib/puppet/pal/pal_impl.rb'
91-
92-
# This cop supports safe auto-correction (--auto-correct).
93-
# Configuration parameters: EnforcedStyle, IndentationWidth.
94-
# SupportedStyles: aligned, indented
95-
Layout/MultilineOperationIndentation:
96-
Enabled: false
97-
98-
# This cop supports safe auto-correction (--auto-correct).
99-
# Configuration parameters: EnforcedStyle, IndentationWidth.
100-
# SupportedStyles: with_first_parameter, with_fixed_indentation
101-
Layout/ParameterAlignment:
102-
Exclude:
103-
- 'lib/puppet/pal/pal_impl.rb'
104-
- 'lib/puppet/util/windows/file.rb'
105-
106-
# This cop supports safe auto-correction (--auto-correct).
107-
Layout/RescueEnsureAlignment:
108-
Exclude:
109-
- 'lib/puppet/provider/package/apt.rb'
110-
- 'lib/puppet/provider/package/aptrpm.rb'
111-
- 'lib/puppet/provider/package/dnf.rb'
112-
- 'lib/puppet/provider/package/rpm.rb'
113-
- 'lib/puppet/provider/package/tdnf.rb'
114-
- 'lib/puppet/provider/package/yum.rb'
115-
- 'lib/puppet/provider/service/daemontools.rb'
116-
117-
# This cop supports safe auto-correction (--auto-correct).
118-
Layout/SpaceAfterColon:
119-
Exclude:
120-
- 'lib/puppet/configurer.rb'
121-
- 'lib/puppet/error.rb'
122-
123-
# This cop supports safe auto-correction (--auto-correct).
124-
Layout/SpaceAfterComma:
125-
Enabled: false
126-
12725
# This cop supports safe auto-correction (--auto-correct).
12826
Layout/SpaceAfterNot:
12927
Enabled: false

ext/windows/service/daemon.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def service_main(*argsv)
3838

3939
if (@LOG_TO_FILE)
4040
FileUtils.mkdir_p(File.dirname(LOG_FILE))
41-
args = args.gsub("--logtofile","")
41+
args = args.gsub("--logtofile", "")
4242
end
4343

4444
base_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
@@ -141,7 +141,7 @@ def log(msg, level)
141141
end
142142
end
143143

144-
def report_windows_event(type,id,message)
144+
def report_windows_event(type, id, message)
145145
begin
146146
eventlog = nil
147147
eventlog = Puppet::Util::Windows::EventLog.open("Puppet")
@@ -174,7 +174,7 @@ def parse_runinterval(puppet_path)
174174
runinterval
175175
end
176176

177-
def parse_log_level(puppet_path,cmdline_debug)
177+
def parse_log_level(puppet_path, cmdline_debug)
178178
begin
179179
loglevel = %x{ #{puppet_path} config --section agent --log_level notice print log_level }.chomp
180180
unless loglevel && respond_to?("log_#{loglevel}")
@@ -206,7 +206,7 @@ def load_env(base_dir)
206206
].join(';').tr('/', '\\') + ';' + ENV['Path']
207207

208208
# ENV that uses forward slashes
209-
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet','lib')};#{ENV['RUBYLIB']}"
209+
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV['RUBYLIB']}"
210210
rescue => e
211211
log_exception(e)
212212
end

lib/hiera/puppet_function.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def self.init_dispatch
1616

1717
dispatch :hiera_no_default do
1818
scope_param
19-
param 'String',:key
19+
param 'String', :key
2020
end
2121

2222
dispatch :hiera_with_default do
2323
scope_param
24-
param 'String',:key
24+
param 'String', :key
2525
param 'Any', :default
2626
optional_param 'Any', :override
2727
end
@@ -65,7 +65,7 @@ def lookup(scope, key, default, has_default, override, &default_block)
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 }
6767
message += ' '+ _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
68-
{ minor_version: Puppet.minor_version }
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/puppet.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def self.[](param)
9191
require_relative 'puppet/feature/base'
9292

9393
# setting access and stuff
94-
def self.[]=(param,value)
94+
def self.[]=(param, value)
9595
@@settings[param] = value
9696
end
9797

@@ -151,9 +151,9 @@ def self.vendored_modules
151151
dir = Puppet[:vendormoduledir]
152152
if dir && File.directory?(dir)
153153
Dir.entries(dir)
154-
.reject { |f| f =~ /^\./ }
155-
.map { |f| File.join(dir, f, "lib") }
156-
.select { |d| FileTest.directory?(d) }
154+
.reject { |f| f =~ /^\./ }
155+
.map { |f| File.join(dir, f, "lib") }
156+
.select { |d| FileTest.directory?(d) }
157157
else
158158
[]
159159
end
@@ -227,7 +227,8 @@ def self.base_context(settings)
227227
loaders << Puppet::Environments::StaticPrivate.new(
228228
Puppet::Node::Environment.create(default_environment,
229229
modulepath,
230-
Puppet::Node::Environment::NO_MANIFEST))
230+
Puppet::Node::Environment::NO_MANIFEST)
231+
)
231232
end
232233
end
233234

lib/puppet/application.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
@@ -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.
@@ -576,7 +576,7 @@ def self.exit(code)
576576
end
577577

578578
def name
579-
self.class.to_s.sub(/.*::/,"").downcase.to_sym
579+
self.class.to_s.sub(/.*::/, "").downcase.to_sym
580580
end
581581

582582
# Return the text to display when running `puppet help`.

lib/puppet/application/agent.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def preinit
4141
:fingerprint => false,
4242
:sourceaddress => nil,
4343
:start_time => Time.now,
44-
}.each do |opt,val|
44+
}.each do |opt, val|
4545
options[opt] = val
4646
end
4747

@@ -54,10 +54,10 @@ def preinit
5454
end
5555

5656
option("--enable")
57-
option("--debug","-d")
58-
option("--fqdn FQDN","-f")
59-
option("--test","-t")
60-
option("--verbose","-v")
57+
option("--debug", "-d")
58+
option("--fqdn FQDN", "-f")
59+
option("--test", "-t")
60+
option("--verbose", "-v")
6161

6262
option("--fingerprint")
6363
option("--digest DIGEST")
@@ -403,7 +403,7 @@ def log_config
403403
# skip also config reading and parsing if debug is not enabled
404404
return unless Puppet::Util::Log.sendlevel?(:debug)
405405

406-
Puppet.settings.stringify_settings(:agent, :all).each_pair do |k,v|
406+
Puppet.settings.stringify_settings(:agent, :all).each_pair do |k, v|
407407
next if k.include?("password") || v.to_s.empty?
408408

409409
Puppet.debug("Using setting: #{k}=#{v}")

lib/puppet/application/apply.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ class Puppet::Application::Apply < Puppet::Application
88
require_relative '../../puppet/util/splayer'
99
include Puppet::Util::Splayer
1010

11-
option("--debug","-d")
12-
option("--execute EXECUTE","-e") do |arg|
11+
option("--debug", "-d")
12+
option("--execute EXECUTE", "-e") do |arg|
1313
options[:code] = arg
1414
end
15-
option("--loadclasses","-L")
16-
option("--test","-t")
17-
option("--verbose","-v")
15+
option("--loadclasses", "-L")
16+
option("--test", "-t")
17+
option("--verbose", "-v")
1818
option("--use-nodes")
1919
option("--detailed-exitcodes")
2020

lib/puppet/application/describe.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def scrub(text)
4444
# indent from every line.
4545
if text =~ /^(\s+)/
4646
indent = $1
47-
return text.gsub(/^#{indent}/,'')
47+
return text.gsub(/^#{indent}/, '')
4848
else
4949
return text
5050
end
@@ -126,7 +126,7 @@ def format_attrs(type, attrs)
126126
docs[name] = type.attrclass(name).doc if attrs.include?(kind) && name != :provider
127127
end
128128

129-
docs.sort { |a,b|
129+
docs.sort { |a, b|
130130
a[0].to_s <=> b[0].to_s
131131
}.each { |name, doc|
132132
print "\n- **#{name}**"
@@ -169,9 +169,9 @@ class Puppet::Application::Describe < Puppet::Application
169169
options[:parameters] = false
170170
end
171171

172-
option("--providers","-p")
172+
option("--providers", "-p")
173173
option("--list", "-l")
174-
option("--meta","-m")
174+
option("--meta", "-m")
175175

176176
def summary
177177
_("Display help about resource types")

lib/puppet/application/device.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ def preinit
3838
:facts => false,
3939
:target => nil,
4040
:to_yaml => false,
41-
}.each do |opt,val|
41+
}.each do |opt, val|
4242
options[opt] = val
4343
end
4444

4545
@args = {}
4646
end
4747

4848
option("--centrallogging")
49-
option("--debug","-d")
50-
option("--resource","-r")
51-
option("--facts","-f")
52-
option("--to_yaml","-y")
53-
option("--verbose","-v")
49+
option("--debug", "-d")
50+
option("--resource", "-r")
51+
option("--facts", "-f")
52+
option("--to_yaml", "-y")
53+
option("--verbose", "-v")
5454

5555
option("--detailed-exitcodes") do |_arg|
5656
options[:detailed_exitcodes] = true
@@ -72,7 +72,7 @@ def preinit
7272
options[:waitforcert] = arg.to_i
7373
end
7474

75-
option("--port PORT","-p") do |arg|
75+
option("--port PORT", "-p") do |arg|
7676
@args[:Port] = arg
7777
end
7878

@@ -261,7 +261,7 @@ def main
261261
exit(1)
262262
end
263263
end
264-
devices.collect do |_devicename,device|
264+
devices.collect do |_devicename, device|
265265
# TODO when we drop support for ruby < 2.5 we can remove the extra block here
266266
begin
267267
device_url = URI.parse(device.url)

0 commit comments

Comments
 (0)