Skip to content

Commit

Permalink
Merge pull request puppetlabs#9187 from mhashizume/PUP-11768/main/mor…
Browse files Browse the repository at this point in the history
…e-layout-cops

(PUP-11768) More Rubocop layout cops
  • Loading branch information
mhashizume committed Dec 19, 2023
2 parents 4ae7055 + e7492be commit 9ceca21
Show file tree
Hide file tree
Showing 1,009 changed files with 2,272 additions and 964 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ Layout/BeginEndAlignment:
Exclude:
- 'lib/puppet/provider/package/*.rb'

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

# 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
93 changes: 0 additions & 93 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,99 +22,6 @@ I18n/GetText/DecorateStringFormattingUsingPercent:
I18n/RailsI18n/DecorateString:
Enabled: false

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

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

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: leading, trailing
Layout/DotPosition:
Enabled: false

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

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

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

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Enabled: false

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

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: around, only_before
Layout/EmptyLinesAroundAccessModifier:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Layout/EmptyLinesAroundArguments:
Exclude:
- 'lib/puppet/defaults.rb'
- 'lib/puppet/parser/functions/sprintf.rb'
- 'lib/puppet/settings.rb'
- 'lib/puppet/type.rb'
- 'lib/puppet/type/schedule.rb'
- 'lib/puppet/util/diff.rb'
- 'lib/puppet/util/rdoc/generators/puppet_generator.rb'
- 'lib/puppet/util/rdoc/generators/template/puppet/puppet.rb'
- 'lib/puppet/util/windows/com.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowAliasSyntax, AllowedMethods.
# AllowedMethods: alias_method, public, protected, private
Layout/EmptyLinesAroundAttributeAccessor:
Enabled: false

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

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, no_empty_lines
Layout/EmptyLinesAroundBlockBody:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only
Layout/EmptyLinesAroundClassBody:
Enabled: false

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

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

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines
Layout/EmptyLinesAroundModuleBody:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyleAlignWith, Severity.
# SupportedStylesAlignWith: keyword, variable, start_of_line
Expand Down
1 change: 0 additions & 1 deletion ext/windows/service/daemon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def service_main(*argsv)
end
end
@run_thread.join

rescue Exception => e
log_exception(e)
ensure
Expand Down
1 change: 1 addition & 0 deletions lib/hiera/puppet_function.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'hiera_puppet'

# Provides the base class for the puppet functions hiera, hiera_array, hiera_hash, and hiera_include.
Expand Down
2 changes: 1 addition & 1 deletion lib/hiera/scope.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'forwardable'
class Hiera
class Scope
Expand Down Expand Up @@ -86,6 +87,5 @@ def find_hostclass(scope)

# This is needed for type conversion to work
def_delegators :@real, :call_function

end
end
1 change: 1 addition & 0 deletions lib/hiera_puppet.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

Puppet.features.hiera?
require 'hiera/scope'
require_relative 'puppet'
Expand Down
1 change: 1 addition & 0 deletions lib/puppet.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative 'puppet/version'
require_relative 'puppet/concurrent/synchronized'

Expand Down
1 change: 1 addition & 0 deletions lib/puppet/agent.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../puppet/application'
require_relative '../puppet/error'
require_relative '../puppet/util/at_fork'
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/agent/disabler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/util/json_lockfile'

# This module is responsible for encapsulating the logic for
Expand Down Expand Up @@ -41,10 +42,10 @@ def disable_message
if data.has_key?(DISABLED_MESSAGE_JSON_KEY)
return data[DISABLED_MESSAGE_JSON_KEY]
end

nil
end


def disable_lockfile
@disable_lockfile ||= Puppet::Util::JsonLockfile.new(Puppet[:agent_disabled_lockfile])

Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/agent/locker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/util/pidlock'
require_relative '../../puppet/error'

Expand Down Expand Up @@ -42,6 +43,4 @@ def lockfile
@lockfile
end
private :lockfile


end
7 changes: 4 additions & 3 deletions lib/puppet/application.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# frozen_string_literal: true

require 'optparse'
require_relative '../puppet/util/command_line'
require_relative '../puppet/util/constant_inflector'
require_relative '../puppet/error'
require_relative '../puppet/application_support'

module Puppet

# Defines an abstract Puppet application.
#
# # Usage
Expand Down Expand Up @@ -170,6 +170,7 @@ def clear?
# Thus, long-running background processes can potentially finish their work before a restart.
def controlled_run(&block)
return unless clear?

result = block.call
Process.kill(:HUP, $PID) if restart_requested?
result
Expand Down Expand Up @@ -304,6 +305,7 @@ def run_mode(mode_name = nil)
# @api public
def environment_mode(mode_name)
raise Puppet::Error, _("Invalid environment mode '%{mode_name}'") % { mode_name: mode_name } unless [:local, :remote, :not_required].include?(mode_name)

@environment_mode = mode_name
end

Expand Down Expand Up @@ -364,7 +366,7 @@ def initialize(command_line = Puppet::Util::CommandLine.new)
def app_defaults
Puppet::Settings.app_defaults_for_run_mode(self.class.run_mode).merge(
:name => name
)
)
end

# Initialize application defaults. It's usually not necessary to override this method.
Expand Down Expand Up @@ -399,7 +401,6 @@ def deprecated?
# @return [void]
# @api public
def run

# I don't really like the names of these lifecycle phases. It would be nice to change them to some more meaningful
# names, and make deprecated aliases. --cprice 2012-03-16

Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/application/agent.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/application'
require_relative '../../puppet/daemon'
require_relative '../../puppet/util/pidlock'
Expand All @@ -7,7 +8,6 @@
require_relative '../../puppet/ssl/oids'

class Puppet::Application::Agent < Puppet::Application

run_mode :agent

def app_defaults
Expand Down Expand Up @@ -405,6 +405,7 @@ def log_config

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}")
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/puppet/application/apply.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/application'
require_relative '../../puppet/configurer'
require_relative '../../puppet/util/profiler/aggregate'
Expand Down Expand Up @@ -310,7 +311,6 @@ def setup

Puppet.settings.use :main, :agent, :ssl


if Puppet[:catalog_cache_terminus]
Puppet::Resource::Catalog.indirection.cache_class = Puppet[:catalog_cache_terminus]
end
Expand Down Expand Up @@ -382,6 +382,7 @@ def get_facts()
def get_node()
node = Puppet::Node.indirection.find(Puppet[:node_name_value])
raise _("Could not find node %{node}") % { node: Puppet[:node_name_value] } unless node

node
end

Expand All @@ -395,6 +396,7 @@ def get_manifest()
else
manifest = command_line.args.shift
raise _("Could not find file %{manifest}") % { manifest: manifest } unless Puppet::FileSystem.exist?(manifest)

Puppet.warning(_("Only one file can be applied per run. Skipping %{files}") % { files: command_line.args.join(', ') }) if command_line.args.size > 0
end
manifest
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/catalog.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/application/indirection_base'

class Puppet::Application::Catalog < Puppet::Application::IndirectionBase
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/config.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/application/face_base'

class Puppet::Application::Config < Puppet::Application::FaceBase
Expand Down
8 changes: 3 additions & 5 deletions lib/puppet/application/describe.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# frozen_string_literal: true

require_relative '../../puppet/application'

class Formatter

def initialize(width)
@width = width
end

def wrap(txt, opts)
return "" unless txt && !txt.empty?

work = (opts[:scrub] ? scrub(txt) : txt)
indent = (opts[:indent] ? opts[:indent] : 0)
textLen = @width - indent
Expand Down Expand Up @@ -48,17 +49,16 @@ def scrub(text)
return text
end
end

end

class TypeDoc

def initialize
@format = Formatter.new(76)
@types = {}
Puppet::Type.loadall
Puppet::Type.eachtype { |type|
next if type.name == :component

@types[type.name] = type
}
end
Expand Down Expand Up @@ -160,7 +160,6 @@ def list_providers(type)
list = type.providers.sort_by(&:to_s).join(", ")
puts @format.wrap(list, :indent => 4)
end

end

class Puppet::Application::Describe < Puppet::Application
Expand Down Expand Up @@ -250,5 +249,4 @@ def setup
handle_help(nil) unless options[:list] || options[:types].size > 0
$stderr.puts "Warning: ignoring types when listing all types" if options[:list] && options[:types].size > 0
end

end
4 changes: 2 additions & 2 deletions lib/puppet/application/device.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require_relative '../../puppet/application'
require_relative '../../puppet/configurer'
require_relative '../../puppet/util/network_device'
require_relative '../../puppet/ssl/oids'

class Puppet::Application::Device < Puppet::Application

run_mode :agent

attr_accessor :args, :agent, :host
Expand Down Expand Up @@ -227,14 +227,14 @@ def help
HELP
end


def main
if options[:resource] and !options[:target]
raise _("resource command requires target")
end
if options[:facts] and !options[:target]
raise _("facts command requires target")
end

unless options[:apply].nil?
raise _("missing argument: --target is required when using --apply") if options[:target].nil?
raise _("%{file} does not exist, cannot apply") % { file: options[:apply] } unless File.file?(options[:apply])
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/doc.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/application'

class Puppet::Application::Doc < Puppet::Application
Expand Down
1 change: 1 addition & 0 deletions lib/puppet/application/epp.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require_relative '../../puppet/application/face_base'
require_relative '../../puppet/face'

Expand Down
Loading

0 comments on commit 9ceca21

Please sign in to comment.