Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout Cops #9203

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
db3e94f
Layout/SpaceAfterNot
mhashizume Jan 8, 2024
75a68f1
Layout/SpaceAfterSemicolon
mhashizume Jan 8, 2024
22e071a
Layout/SpaceAroundBlockParameters
mhashizume Jan 8, 2024
9fd6354
Layout/SpaceAroundEqualsInParameterDefault
mhashizume Jan 8, 2024
f6dfecb
Layout/SpaceAroundKeyword
mhashizume Jan 8, 2024
7b33fc3
Layout/SpaceAroundMethodCallOperator
mhashizume Jan 8, 2024
cf4a606
Disable Layout cops on == method
mhashizume Jan 9, 2024
9f8fb93
Layout/SpaceAroundOperators
mhashizume Jan 8, 2024
5a1b67d
Layout/SpaceBeforeBlockBraces
mhashizume Jan 8, 2024
4be9889
Layout/SpaceBeforeBrackets
mhashizume Jan 8, 2024
4a53dea
Layout/SpaceBeforeComma
mhashizume Jan 8, 2024
d9e983a
Use parens for Gettext translation
mhashizume Jan 8, 2024
2c6855e
Layout/SpaceBeforeFirstArg
mhashizume Jan 8, 2024
7275de4
Layout/SpaceBeforeSemicolon
mhashizume Jan 8, 2024
4d45b79
Simplify sequential arrays to ranges
mhashizume Jan 8, 2024
b26d640
Layout/SpaceInsideArrayLiteralBrackets
mhashizume Jan 8, 2024
735ec34
Layout/SpaceInsideBlockBraces
mhashizume Jan 8, 2024
f140c82
Layout/SpaceInsideHashLiteralBraces
mhashizume Jan 8, 2024
e298c24
Layout/SpaceInsideParens
mhashizume Jan 8, 2024
89aa3f8
Layout/SpaceInsidePercentLiteralDelimiters
mhashizume Jan 8, 2024
5279caa
Layout/SpaceInsideRangeLiteral
mhashizume Jan 8, 2024
fec7703
Layout/SpaceInsideReferenceBrackets
mhashizume Jan 8, 2024
23f0018
Layout/SpaceInsideStringInterpolation
mhashizume Jan 8, 2024
39bb919
Layout/TrailingEmptyLines
mhashizume Jan 8, 2024
6cb3b8c
Layout/TrailingWhitespace
mhashizume Jan 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ Layout/IndentationWidth:
Layout/LineEndStringConcatenationIndentation:
Enabled: true

# Explicitly enables this cop new in 1.7
Layout/SpaceBeforeBrackets:
Enabled: true

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

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

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAfterSemicolon:
Exclude:
- 'lib/puppet/util/retry_action.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyleInsidePipes.
# SupportedStylesInsidePipes: space, no_space
Layout/SpaceAroundBlockParameters:
Exclude:
- 'lib/puppet/functions/dig.rb'
- 'lib/puppet/functions/filter.rb'
- 'lib/puppet/node/environment.rb'
- 'lib/puppet/pal/pal_impl.rb'
- 'lib/puppet/pops/evaluator/compare_operator.rb'
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
- 'lib/puppet/pops/functions/dispatcher.rb'
- 'lib/puppet/pops/types/string_converter.rb'
- 'lib/puppet/provider/package/openbsd.rb'
- 'lib/puppet/provider/package/pkg.rb'
- 'lib/puppet/provider/package/yum.rb'
- 'lib/puppet/resource/catalog.rb'
- 'lib/puppet/type.rb'
- 'lib/puppet/util.rb'
- 'lib/puppet/util/docs.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceAroundEqualsInParameterDefault:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAroundKeyword:
Exclude:
- 'lib/puppet/functions/max.rb'
- 'lib/puppet/functions/min.rb'
- 'lib/puppet/pops/evaluator/evaluator_impl.rb'
- 'lib/puppet/pops/lookup/global_data_provider.rb'
- 'lib/puppet/pops/lookup/hiera_config.rb'
- 'lib/puppet/pops/parser/slurp_support.rb'
- 'lib/puppet/pops/types/p_object_type.rb'
- 'lib/puppet/pops/types/type_calculator.rb'
- 'lib/puppet/pops/validation/checker4_0.rb'
- 'lib/puppet/util/diff.rb'
- 'lib/puppet/util/windows/daemon.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceAroundMethodCallOperator:
Exclude:
- 'lib/puppet/network/formats.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator.
# SupportedStylesForExponentOperator: space, no_space
Layout/SpaceAroundOperators:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceBeforeBlockBraces:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceBeforeComma:
Exclude:
- 'lib/puppet/application/lookup.rb'
- 'lib/puppet/external/dot.rb'
- 'lib/puppet/face/parser.rb'
- 'lib/puppet/indirector/file_bucket_file/file.rb'
- 'lib/puppet/parser/compiler.rb'
- 'lib/puppet/parser/script_compiler.rb'
- 'lib/puppet/pops/lookup/global_data_provider.rb'
- 'lib/puppet/pops/parser/lexer2.rb'
- 'lib/puppet/provider/package/windows.rb'
- 'lib/puppet/provider/package/windows/exe_package.rb'
- 'lib/puppet/util/windows/monkey_patches/process.rb'
- 'lib/puppet/util/windows/user.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowForAlignment.
Layout/SpaceBeforeFirstArg:
Exclude:
- 'lib/puppet/file_serving/configuration.rb'
- 'lib/puppet/functions/defined.rb'
- 'lib/puppet/parser/type_loader.rb'
- 'lib/puppet/pops/types/types.rb'
- 'lib/puppet/provider/package/aix.rb'
- 'lib/puppet/provider/package/nim.rb'
- 'lib/puppet/provider/package/rug.rb'
- 'lib/puppet/type/service.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceBeforeSemicolon:
Exclude:
- 'lib/puppet/functions.rb'
- 'lib/puppet/network/http/connection.rb'
- 'lib/puppet/pops/model/model_label_provider.rb'
- 'lib/puppet/pops/parser/slurp_support.rb'
- 'lib/puppet/pops/types/class_loader.rb'
- 'lib/puppet/pops/types/type_formatter.rb'
- 'lib/puppet/settings/errors.rb'
- 'lib/puppet/util/network_device/base.rb'
- 'lib/puppet/util/windows.rb'
- 'lib/puppet/util/windows/eventlog.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBrackets: space, no_space
Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces.
# SupportedStyles: space, no_space, compact
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideHashLiteralBraces:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, compact, no_space
Layout/SpaceInsideParens:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceInsidePercentLiteralDelimiters:
Exclude:
- 'ext/windows/service/daemon.rb'
- 'lib/puppet/interface/documentation.rb'
- 'lib/puppet/pops/parser/slurp_support.rb'

# This cop supports safe auto-correction (--auto-correct).
Layout/SpaceInsideRangeLiteral:
Exclude:
- 'lib/puppet/pops/validation/checker4_0.rb'
- 'lib/puppet/util/command_line/trollop.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBrackets: space, no_space
Layout/SpaceInsideReferenceBrackets:
Exclude:
- 'lib/puppet/application.rb'
- 'lib/puppet/functions/unique.rb'
- 'lib/puppet/parser/scope.rb'
- 'lib/puppet/pops/evaluator/access_operator.rb'
- 'lib/puppet/pops/evaluator/deferred_resolver.rb'
- 'lib/puppet/pops/lookup/hiera_config.rb'
- 'lib/puppet/pops/parser/locator.rb'
- 'lib/puppet/pops/types/string_converter.rb'
- 'lib/puppet/resource/type_collection.rb'
- 'lib/puppet/util/windows/adsi.rb'
- 'lib/puppet/util/windows/process.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: space, no_space
Layout/SpaceInsideStringInterpolation:
Exclude:
- 'lib/puppet/ssl/ssl_provider.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingEmptyLines:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowInHeredoc.
Layout/TrailingWhitespace:
Enabled: false

# Configuration parameters: AllowedMethods.
# AllowedMethods: enums
Lint/ConstantDefinitionInBlock:
Expand Down
4 changes: 2 additions & 2 deletions ext/windows/service/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def report_windows_event(type, id, message)

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

def parse_log_level(puppet_path, cmdline_debug)
begin
loglevel = %x{ #{puppet_path} config --section agent --log_level notice print log_level }.chomp
loglevel = %x{#{puppet_path} config --section agent --log_level notice print log_level}.chomp
unless loglevel && respond_to?("log_#{loglevel}")
loglevel = :notice
log_err("Failed to determine loglevel, defaulting to #{loglevel}")
Expand Down
4 changes: 2 additions & 2 deletions lib/hiera/puppet_function.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def lookup(scope, key, default, has_default, override, &default_block)
unless Puppet[:strict] == :off
# 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 }
message += ' ' + _("See https://puppet.com/docs/puppet/%{minor_version}/deprecated_language.html") %
{ minor_version: Puppet.minor_version }
Puppet.warn_once('deprecations', self.class.name, message)
end
lookup_invocation = Puppet::Pops::Lookup::Invocation.new(scope, {}, {})
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera/scope.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def safe_lookupvar(key)
# do nothing
when :warning
Puppet.warn_once(Puppet::Parser::Scope::UNDEFINED_VARIABLES_KIND, _("Variable: %{name}") % { name: key },
_("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason } )
_("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason })
when :error
raise ArgumentError, _("Undefined variable '%{name}'; %{reason}") % { name: key, reason: reason }
end
Expand Down
1 change: 0 additions & 1 deletion lib/hiera_puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,3 @@ def hiera_config_file
end
end
end

4 changes: 2 additions & 2 deletions lib/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ def self.clear

def self.debug=(value)
if value
Puppet::Util::Log.level=(:debug)
Puppet::Util::Log.level = (:debug)
else
Puppet::Util::Log.level=(:notice)
Puppet::Util::Log.level = (:notice)
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/puppet/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RunTimeoutError < Exception # rubocop:disable Lint/InheritException

attr_reader :client_class, :client, :should_fork

def initialize(client_class, should_fork=true)
def initialize(client_class, should_fork = true)
@should_fork = can_fork? && should_fork
@client_class = client_class
end
Expand Down Expand Up @@ -99,13 +99,13 @@ def run(client_options = {})
nil
else
Puppet.info _("Another puppet instance is already running; --waitforlock flag used, waiting for running instance to finish.")
Puppet.info _("Will try again in %{time} seconds.") % {time: Puppet[:waitforlock]}
Puppet.info _("Will try again in %{time} seconds.") % { time: Puppet[:waitforlock] }
sleep Puppet[:waitforlock]
retry
end
rescue RunTimeoutError => detail
Puppet.log_exception(detail, _("Execution of %{client_class} did not complete within %{runtimeout} seconds and was terminated.") %
{client_class: client_class, runtimeout: Puppet[:runtimeout]})
{ client_class: client_class, runtimeout: Puppet[:runtimeout] })
nil
rescue StandardError => detail
Puppet.log_exception(detail, _("Could not run %{client_class}: %{detail}") % { client_class: client_class, detail: detail })
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/agent/disabler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def enable
end

# Stop the daemon from making any catalog runs.
def disable(msg=nil)
def disable(msg = nil)
data = {}
Puppet.notice _("Disabling Puppet.")
if (! msg.nil?)
if (!msg.nil?)
data[DISABLED_MESSAGE_JSON_KEY] = msg
end
disable_lockfile.lock(data)
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Application
require_relative '../puppet/util'
include Puppet::Util

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

@loader = Puppet::Util::Autoload.new(self, 'puppet/application')
Expand Down 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 @@ -287,7 +287,7 @@ def run_mode(mode_name = nil)
return @run_mode if @run_mode and not mode_name

require_relative '../puppet/util/run_mode'
@run_mode = Puppet::Util::RunMode[ mode_name || Puppet.settings.preferred_run_mode ]
@run_mode = Puppet::Util::RunMode[mode_name || Puppet.settings.preferred_run_mode]
end

# Sets environment_mode name. When acting as a compiler, the environment mode
Expand Down Expand Up @@ -501,7 +501,7 @@ def configure_indirector_routes
# to log. Intended to be passed to super by subclasses.
# @return [void]
# @api public
def log_runtime_environment(extra_info=nil)
def log_runtime_environment(extra_info = nil)
runtime_info = {
'puppet_version' => Puppet.version,
'ruby_version' => RUBY_VERSION,
Expand All @@ -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
Loading