Skip to content

Commit

Permalink
Merge pull request #9197 from mhashizume/PUP-11768/main/layout-cops-h…
Browse files Browse the repository at this point in the history
…ypercube

(PUP-11768) Layout cops
  • Loading branch information
joshcooper authored Jan 8, 2024
2 parents 272abb9 + 8433171 commit 3b42e7d
Show file tree
Hide file tree
Showing 282 changed files with 1,013 additions and 1,039 deletions.
17 changes: 4 additions & 13 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,20 @@ AllCops:
- 'tasks/**/*'
- 'ext/suse/puppet.spec'
- 'lib/puppet/vendor/**/*'
- 'lib/puppet/pops/model/ast.rb'
- 'lib/puppet/pops/parser/eparser.rb'

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

# The confine statements in package providers unexpectedly affect this cop.
Layout/BeginEndAlignment:
Enabled: true
Exclude:
- 'lib/puppet/provider/package/*.rb'

Layout/ElseAlignment:
Enabled: true
Exclude:
- 'lib/puppet/provider/package/*.rb'

# We don't mind when module and class keywords are aligned.
Layout/IndentationWidth:
AllowedPatterns: ['^\s*module']
Exclude:
- 'lib/puppet/provider/package/*.rb'

Layout/LineEndStringConcatenationIndentation:
Enabled: true

# puppet uses symbol booleans in types and providers to work around long standing
# bugs when trying to manage falsey pararameters and properties
Expand Down
102 changes: 0 additions & 102 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,108 +22,6 @@ I18n/GetText/DecorateStringFormattingUsingPercent:
I18n/RailsI18n/DecorateString:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/LeadingEmptyLines:
Exclude:
- 'lib/puppet/functions/yaml_data.rb'
- 'lib/puppet/info_service.rb'
- 'lib/puppet/parser/abstract_compiler.rb'
- 'lib/puppet/pops/loader/loader_paths.rb'
- 'lib/puppet/pops/parser/code_merger.rb'
- 'lib/puppet/pops/parser/lexer_support.rb'
- 'lib/puppet/pops/types/type_assertion_error.rb'
- 'lib/puppet/pops/types/type_conversion_error.rb'
- 'lib/puppet/provider/network_device.rb'
- 'lib/puppet/type/component.rb'
- 'lib/puppet/type/file/ensure.rb'
- 'lib/puppet/util/network_device/transport/base.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineArrayBraceLayout:
Exclude:
- 'lib/puppet/pops/model/ast.rb'
- 'lib/puppet/pops/types/iterable.rb'
- 'lib/puppet/pops/types/types.rb'
- 'lib/puppet/type/file/content.rb'
- 'lib/puppet/util/log/destinations.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/MultilineBlockLayout:
Exclude:
- 'lib/puppet/provider/service/freebsd.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineHashBraceLayout:
Exclude:
- 'lib/puppet/configurer.rb'
- 'lib/puppet/defaults.rb'
- 'lib/puppet/face/facts.rb'
- 'lib/puppet/file_serving/metadata.rb'
- 'lib/puppet/indirector/catalog/compiler.rb'
- 'lib/puppet/info_service/class_information_service.rb'
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
- 'lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb'
- 'lib/puppet/pops/parser/lexer_support.rb'
- 'lib/puppet/ssl/ssl_provider.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodCallBraceLayout:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented, indented_relative_to_receiver
Layout/MultilineMethodCallIndentation:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: symmetrical, new_line, same_line
Layout/MultilineMethodDefinitionBraceLayout:
Exclude:
- 'lib/puppet/pal/pal_impl.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: aligned, indented
Layout/MultilineOperationIndentation:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, IndentationWidth.
# SupportedStyles: with_first_parameter, with_fixed_indentation
Layout/ParameterAlignment:
Exclude:
- 'lib/puppet/pal/pal_impl.rb'
- 'lib/puppet/util/windows/file.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/RescueEnsureAlignment:
Exclude:
- 'lib/puppet/provider/package/apt.rb'
- 'lib/puppet/provider/package/aptrpm.rb'
- 'lib/puppet/provider/package/dnf.rb'
- 'lib/puppet/provider/package/rpm.rb'
- 'lib/puppet/provider/package/tdnf.rb'
- 'lib/puppet/provider/package/yum.rb'
- 'lib/puppet/provider/service/daemontools.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAfterColon:
Exclude:
- 'lib/puppet/configurer.rb'
- 'lib/puppet/error.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAfterComma:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAfterNot:
Enabled: false
Expand Down
8 changes: 4 additions & 4 deletions ext/windows/service/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def service_main(*argsv)

if (@LOG_TO_FILE)
FileUtils.mkdir_p(File.dirname(LOG_FILE))
args = args.gsub("--logtofile","")
args = args.gsub("--logtofile", "")
end

base_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
Expand Down Expand Up @@ -141,7 +141,7 @@ def log(msg, level)
end
end

def report_windows_event(type,id,message)
def report_windows_event(type, id, message)
begin
eventlog = nil
eventlog = Puppet::Util::Windows::EventLog.open("Puppet")
Expand Down Expand Up @@ -174,7 +174,7 @@ def parse_runinterval(puppet_path)
runinterval
end

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

# ENV that uses forward slashes
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet','lib')};#{ENV['RUBYLIB']}"
ENV['RUBYLIB'] = "#{File.join(base_dir, 'puppet', 'lib')};#{ENV['RUBYLIB']}"
rescue => e
log_exception(e)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/hiera/puppet_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def self.init_dispatch

dispatch :hiera_no_default do
scope_param
param 'String',:key
param 'String', :key
end

dispatch :hiera_with_default do
scope_param
param 'String',:key
param 'String', :key
param 'Any', :default
optional_param 'Any', :override
end
Expand Down Expand Up @@ -65,7 +65,7 @@ def lookup(scope, key, default, has_default, override, &default_block)
# TRANSLATORS 'lookup' is a puppet function and should not be translated
message = _("The function '%{class_name}' is deprecated in favor of using 'lookup'.") % { class_name: self.class.name }
message += ' '+ _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
{ minor_version: Puppet.minor_version }
{ minor_version: Puppet.minor_version }
Puppet.warn_once('deprecations', self.class.name, message)
end
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {})
Expand Down
11 changes: 6 additions & 5 deletions lib/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def self.[](param)
require_relative 'puppet/feature/base'

# setting access and stuff
def self.[]=(param,value)
def self.[]=(param, value)
@@settings[param] = value
end

Expand Down Expand Up @@ -151,9 +151,9 @@ def self.vendored_modules
dir = Puppet[:vendormoduledir]
if dir && File.directory?(dir)
Dir.entries(dir)
.reject { |f| f =~ /^\./ }
.map { |f| File.join(dir, f, "lib") }
.select { |d| FileTest.directory?(d) }
.reject { |f| f =~ /^\./ }
.map { |f| File.join(dir, f, "lib") }
.select { |d| FileTest.directory?(d) }
else
[]
end
Expand Down Expand Up @@ -227,7 +227,8 @@ def self.base_context(settings)
loaders << Puppet::Environments::StaticPrivate.new(
Puppet::Node::Environment.create(default_environment,
modulepath,
Puppet::Node::Environment::NO_MANIFEST))
Puppet::Node::Environment::NO_MANIFEST)
)
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def controlled_run(&block)

# used to declare code that handle an option
def option(*options, &block)
long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1' ).tr('-','_')
long = options.find { |opt| opt =~ /^--/ }.gsub(/^--(?:\[no-\])?([^ =]+).*$/, '\1' ).tr('-', '_')
fname = "handle_#{long}".intern
if (block_given?)
define_method(fname, &block)
Expand Down Expand Up @@ -514,7 +514,7 @@ def log_runtime_environment(extra_info=nil)
runtime_info['default_encoding'] = Encoding.default_external
runtime_info.merge!(extra_info) unless extra_info.nil?

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

# Options defined with the `option` method are parsed from settings and the command line.
Expand Down Expand Up @@ -576,7 +576,7 @@ def self.exit(code)
end

def name
self.class.to_s.sub(/.*::/,"").downcase.to_sym
self.class.to_s.sub(/.*::/, "").downcase.to_sym
end

# Return the text to display when running `puppet help`.
Expand Down
12 changes: 6 additions & 6 deletions lib/puppet/application/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def preinit
:fingerprint => false,
:sourceaddress => nil,
:start_time => Time.now,
}.each do |opt,val|
}.each do |opt, val|
options[opt] = val
end

Expand All @@ -54,10 +54,10 @@ def preinit
end

option("--enable")
option("--debug","-d")
option("--fqdn FQDN","-f")
option("--test","-t")
option("--verbose","-v")
option("--debug", "-d")
option("--fqdn FQDN", "-f")
option("--test", "-t")
option("--verbose", "-v")

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

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

Puppet.debug("Using setting: #{k}=#{v}")
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/application/apply.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class Puppet::Application::Apply < Puppet::Application
require_relative '../../puppet/util/splayer'
include Puppet::Util::Splayer

option("--debug","-d")
option("--execute EXECUTE","-e") do |arg|
option("--debug", "-d")
option("--execute EXECUTE", "-e") do |arg|
options[:code] = arg
end
option("--loadclasses","-L")
option("--test","-t")
option("--verbose","-v")
option("--loadclasses", "-L")
option("--test", "-t")
option("--verbose", "-v")
option("--use-nodes")
option("--detailed-exitcodes")

Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/application/describe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def scrub(text)
# indent from every line.
if text =~ /^(\s+)/
indent = $1
return text.gsub(/^#{indent}/,'')
return text.gsub(/^#{indent}/, '')
else
return text
end
Expand Down Expand Up @@ -126,7 +126,7 @@ def format_attrs(type, attrs)
docs[name] = type.attrclass(name).doc if attrs.include?(kind) && name != :provider
end

docs.sort { |a,b|
docs.sort { |a, b|
a[0].to_s <=> b[0].to_s
}.each { |name, doc|
print "\n- **#{name}**"
Expand Down Expand Up @@ -169,9 +169,9 @@ class Puppet::Application::Describe < Puppet::Application
options[:parameters] = false
end

option("--providers","-p")
option("--providers", "-p")
option("--list", "-l")
option("--meta","-m")
option("--meta", "-m")

def summary
_("Display help about resource types")
Expand Down
16 changes: 8 additions & 8 deletions lib/puppet/application/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ def preinit
:facts => false,
:target => nil,
:to_yaml => false,
}.each do |opt,val|
}.each do |opt, val|
options[opt] = val
end

@args = {}
end

option("--centrallogging")
option("--debug","-d")
option("--resource","-r")
option("--facts","-f")
option("--to_yaml","-y")
option("--verbose","-v")
option("--debug", "-d")
option("--resource", "-r")
option("--facts", "-f")
option("--to_yaml", "-y")
option("--verbose", "-v")

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

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

Expand Down Expand Up @@ -261,7 +261,7 @@ def main
exit(1)
end
end
devices.collect do |_devicename,device|
devices.collect do |_devicename, device|
# TODO when we drop support for ruby < 2.5 we can remove the extra block here
begin
device_url = URI.parse(device.url)
Expand Down
Loading

0 comments on commit 3b42e7d

Please sign in to comment.