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

(PUP-11771) Rubocop Naming Cops #9183

Merged
merged 16 commits into from
Dec 19, 2023
83 changes: 83 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,86 @@ Metrics/ParameterLists:

Metrics/PerceivedComplexity:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

Naming/BinaryOperatorParameterName:
Enabled: false

Naming/BlockParameterName:
Exclude:
- 'lib/puppet/util/windows/daemon.rb'
- 'lib/puppet/util/windows/user.rb'

Naming/ClassAndModuleCamelCase:
Exclude:
- 'lib/puppet/ffi/windows/structs.rb'
- 'lib/puppet/pops/validation/checker4_0.rb'
- 'lib/puppet/pops/validation/validator_factory_4_0.rb'
- 'lib/puppet/util/windows/root_certs.rb'
- 'lib/puppet/util/windows/security.rb'
- 'lib/puppet/util/windows/user.rb'

Naming/ConstantName:
Exclude:
- 'lib/puppet/graph/relationship_graph.rb'
- 'lib/puppet/indirector/hiera.rb'
- 'lib/puppet/provider/package/sun.rb'
- 'lib/puppet/resource/type.rb'
- 'lib/puppet/type/schedule.rb'
- 'lib/puppet/type/tidy.rb'
- 'lib/puppet/util.rb'
- 'lib/puppet/util/colors.rb'
- 'lib/puppet/util/execution.rb'
- 'lib/puppet/util/symbolic_file_mode.rb'
- 'lib/puppet/util/tagging.rb'
- 'lib/puppet/util/windows/adsi.rb'
- 'lib/puppet/util/windows/sid.rb'
- 'lib/puppet/util/yaml.rb'

Naming/HeredocDelimiterNaming:
Enabled: false

# Exclude existing violations to avoid breaking changes
Naming/MemoizedInstanceVariableName:
Exclude:
- 'lib/puppet/module_tool/applications/installer.rb'
- 'lib/puppet/pops/types/type_factory.rb'
- 'lib/puppet/provider/package/portage.rb'
- 'lib/puppet/resource.rb'

Naming/MethodName:
Exclude:
- 'lib/puppet/functions/**/*'
- 'lib/puppet/parser/ast/pops_bridge.rb'
- 'lib/puppet/pops/**/*'
- 'lib/puppet/util/windows/**/*'

Naming/MethodParameterName:
Enabled: false

Naming/PredicateName:
ForbiddenPrefixes: []

Naming/RescuedExceptionsVariableName:
Enabled: false

Naming/VariableName:
Exclude:
- 'ext/windows/service/daemon.rb'
- 'lib/puppet/agent.rb'
- 'lib/puppet/application/describe.rb'
- 'lib/puppet/pops/lookup/hiera_config.rb'
- 'lib/puppet/pops/validation/checker4_0.rb'
- 'lib/puppet/provider/package/pip.rb'
- 'lib/puppet/provider/package/windows/exe_package.rb'
- 'lib/puppet/provider/package/windows/msi_package.rb'
- 'lib/puppet/ssl/ssl_provider.rb'
- 'lib/puppet/util/windows/adsi.rb'
- 'lib/puppet/util/windows/daemon.rb'
- 'lib/puppet/util/windows/error.rb'
- 'lib/puppet/util/windows/user.rb'

Naming/VariableNumber:
Enabled: false
98 changes: 0 additions & 98 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -643,104 +643,6 @@ Lint/ToJSON:
Lint/UnusedMethodArgument:
Enabled: false

Naming/AccessorMethodName:
Enabled: false

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

# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
Naming/BlockParameterName:
Exclude:
- 'lib/puppet/util/windows/daemon.rb'
- 'lib/puppet/util/windows/user.rb'

# Configuration parameters: AllowedNames.
# AllowedNames: module_parent
Naming/ClassAndModuleCamelCase:
Exclude:
- 'lib/puppet/ffi/windows/structs.rb'
- 'lib/puppet/pops/validation/checker4_0.rb'
- 'lib/puppet/pops/validation/validator_factory_4_0.rb'
- 'lib/puppet/util/windows/root_certs.rb'
- 'lib/puppet/util/windows/security.rb'
- 'lib/puppet/util/windows/user.rb'

Naming/ConstantName:
Exclude:
- 'lib/puppet/graph/relationship_graph.rb'
- 'lib/puppet/indirector/hiera.rb'
- 'lib/puppet/provider/package/sun.rb'
- 'lib/puppet/resource/type.rb'
- 'lib/puppet/type/schedule.rb'
- 'lib/puppet/type/tidy.rb'
- 'lib/puppet/util.rb'
- 'lib/puppet/util/colors.rb'
- 'lib/puppet/util/execution.rb'
- 'lib/puppet/util/symbolic_file_mode.rb'
- 'lib/puppet/util/tagging.rb'
- 'lib/puppet/util/windows/adsi.rb'
- 'lib/puppet/util/windows/sid.rb'
- 'lib/puppet/util/yaml.rb'

# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Enabled: false

# Configuration parameters: EnforcedStyleForLeadingUnderscores.
# SupportedStylesForLeadingUnderscores: disallowed, required, optional
Naming/MemoizedInstanceVariableName:
Enabled: false

# Configuration parameters: EnforcedStyle, AllowedPatterns, IgnoredPatterns.
# SupportedStyles: snake_case, camelCase
Naming/MethodName:
Enabled: false

# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to
Naming/MethodParameterName:
Enabled: false

# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
# NamePrefix: is_, has_, have_
# ForbiddenPrefixes: is_, has_, have_
# AllowedMethods: is_a?
# MethodDefinitionMacros: define_method, define_singleton_method
Naming/PredicateName:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: PreferredName.
Naming/RescuedExceptionsVariableName:
Enabled: false

# Configuration parameters: EnforcedStyle, AllowedIdentifiers.
# SupportedStyles: snake_case, camelCase
Naming/VariableName:
Exclude:
- 'ext/windows/service/daemon.rb'
- 'lib/puppet/agent.rb'
- 'lib/puppet/application/describe.rb'
- 'lib/puppet/pops/lookup/hiera_config.rb'
- 'lib/puppet/pops/validation/checker4_0.rb'
- 'lib/puppet/provider/package/pip.rb'
- 'lib/puppet/provider/package/windows/exe_package.rb'
- 'lib/puppet/provider/package/windows/msi_package.rb'
- 'lib/puppet/ssl/ssl_provider.rb'
- 'lib/puppet/util/windows/adsi.rb'
- 'lib/puppet/util/windows/daemon.rb'
- 'lib/puppet/util/windows/error.rb'
- 'lib/puppet/util/windows/user.rb'

# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339
Naming/VariableNumber:
Enabled: false

# Configuration parameters: EnforcedStyle, AllowModifiersOnSymbols.
# SupportedStyles: inline, group
Style/AccessModifierDeclarations:
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/etc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def group
# these fields as well. API compatible with Etc::Passwd. Because Struct.new
# defines a new Class object, we memoize to avoid superfluous extra Class
# instantiations.
# rubocop:disable Naming/MemoizedInstanceVariableName
def puppet_etc_passwd_class
@password_class ||= Struct.new(*Etc::Passwd.members, *Etc::Passwd.members.map { |member| "canonical_#{member}".to_sym })
end
Expand All @@ -145,6 +146,7 @@ def puppet_etc_passwd_class
def puppet_etc_group_class
@group_class ||= Struct.new(*Etc::Group.members, *Etc::Group.members.map { |member| "canonical_#{member}".to_sym })
end
# rubocop:enable Naming/MemoizedInstanceVariableName

# Utility method for overriding the String values of a struct returned by
# the Etc module to UTF-8. Structs returned by the ruby Etc module contain
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/feature/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module WindowsSymlink
require 'ffi'
extend FFI::Library

def self.is_implemented
def self.is_implemented # rubocop:disable Naming/PredicateName
begin
ffi_lib :kernel32
attach_function :CreateSymbolicLinkW, [:lpwstr, :lpwstr, :dword], :boolean
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/forge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ def prepare
# Obtain a suitable temporary path for unpacking tarballs
#
# @return [Pathname] path to temporary unpacking location
# rubocop:disable Naming/MemoizedInstanceVariableName
def tmpdir
@dir ||= Dir.mktmpdir(name, Puppet::Forge::Cache.base_path)
end
Expand All @@ -204,6 +205,7 @@ def tmpfile
f.binmode
end
end
# rubocop:enable Naming/MemoizedInstanceVariableName

def download(uri, destination)
response = @source.make_http_request(uri, destination)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/functions/defined.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
required_repeated_param 'Variant[String, Type[CatalogEntry], Type[Type[CatalogEntry]]]', :vals
end

def is_defined(scope, *vals)
def is_defined(scope, *vals) # rubocop:disable Naming/PredicateName
vals.any? do |val|
case val
when String
Expand Down
12 changes: 0 additions & 12 deletions lib/puppet/module_tool/applications/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,18 +395,6 @@ def resolve_install_conflicts(graph, is_dependency = false)
end
end
end

#
# Check if a file is a vaild module package.
# ---
# FIXME: Checking for a valid module package should be more robust and
# use the actual metadata contained in the package. 03132012 - Hightower
# +++
#
def is_module_package?(name)
filename = File.expand_path(name)
filename =~ /.tar.gz$/
end
end
end
end
2 changes: 2 additions & 0 deletions lib/puppet/module_tool/applications/unpacker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ def move_into(dir)
#
# @api private
# @return [String] path to temporary unpacking location
# rubocop:disable Naming/MemoizedInstanceVariableName
def tmpdir
@dir ||= Dir.mktmpdir('tmp', Puppet::Forge::Cache.base_path)
end
# rubocop:enable Naming/MemoizedInstanceVariableName
end
end
end
2 changes: 2 additions & 0 deletions lib/puppet/module_tool/applications/upgrader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,15 @@ def installed_release.priority
end

private
# rubocop:disable Naming/MemoizedInstanceVariableName
def module_repository
@repo ||= Puppet::Forge.new(Puppet[:module_repository])
end

def installed_modules_source
@installed ||= Puppet::ModuleTool::InstalledModules.new(@environment)
end
# rubocop:enable Naming/MemoizedInstanceVariableName

def installed_modules
installed_modules_source.modules
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/module_tool/local_tarball.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ def prepare
# Obtain a suitable temporary path for unpacking tarballs
#
# @return [String] path to temporary unpacking location
# rubocop:disable Naming/MemoizedInstanceVariableName
def tmpdir
@dir ||= Dir.mktmpdir('local-tarball', Puppet::Forge::Cache.base_path)
end
# rubocop:enable Naming/MemoizedInstanceVariableName

def unpack(file, destination)
begin
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/pal/json_catalog_encoder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ def encode_resource(type, title)
# or the catalog itself if filtering was not needed.
# The result is cached.
# @api private
#
# rubocop:disable Naming/MemoizedInstanceVariableName
def possibly_filtered_catalog
@filtered ||= (exclude_virtual ? catalog.filter { |r| r.virtual? } : catalog)
end
private :possibly_filtered_catalog
# rubocop:enable Naming/MemoizedInstanceVariableName
end
end
end
2 changes: 2 additions & 0 deletions lib/puppet/parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,15 @@ def defaultto(value = nil, &block)
end
end

# rubocop:disable Naming/PredicateName
def sensitive(value = nil, &block)
if block
define_method(:is_sensitive, &block)
else
define_method(:is_sensitive) do value end
end
end
# rubocop:enable Naming/PredicateName

# Produces a documentation string.
# If an enumeration of _valid values_ has been defined, it is appended to the documentation
Expand Down
3 changes: 2 additions & 1 deletion lib/puppet/pops/adaptable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ def self.type_name
# Adapter#instance_var_name and then cached.
# @return [String] the instance variable name for _name_
# @api private
#
# rubocop:disable Naming/MemoizedInstanceVariableName
def self.self_attr_name
@attr_name_sym ||= :"@#{instance_var_name(type_name)}"
end
# rubocop:enable Naming/MemoizedInstanceVariableName
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/pops/evaluator/closure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,11 @@ def return_type
end

# @api public
# rubocop:disable Naming/MemoizedInstanceVariableName
def type
@callable ||= create_callable_type
end
# rubocop:enable Naming/MemoizedInstanceVariableName

# @api public
def params_struct
Expand Down
6 changes: 0 additions & 6 deletions lib/puppet/pops/evaluator/runtime3_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,12 +460,6 @@ def is_true?(value, o)
end
end

# Utility method for TrueClass || FalseClass
# @param x [Object] the object to test if it is instance of TrueClass or FalseClass
def is_boolean? x
x.is_a?(TrueClass) || x.is_a?(FalseClass)
end

def extract_file_line(o)
o.is_a?(Model::Positioned) ? [o.file, o.line] : [nil, -1]
end
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/pops/lookup/invocation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ def emit_debug_info(preamble)
@explainer.emit_debug_info(preamble) if @explainer.is_a?(DebugExplainer)
end

# rubocop:disable Naming/MemoizedInstanceVariableName
def lookup_adapter
@adapter ||= @adapter_class.adapt(scope.compiler)
end
# rubocop:enable Naming/MemoizedInstanceVariableName

# This method is overridden by the special Invocation used while resolving interpolations in a
# Hiera configuration file (hiera.yaml) where it's used for collecting and remembering the current
Expand Down
2 changes: 2 additions & 0 deletions lib/puppet/pops/lookup/key_recorder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ class Puppet::Pops::Lookup::KeyRecorder
def initialize()
end

# rubocop:disable Naming/MemoizedInstanceVariableName
def self.singleton
@null_recorder ||= self.new
end
# rubocop:enable Naming/MemoizedInstanceVariableName

# Records a key
# (This implementation does nothing)
Expand Down
Loading