Skip to content

Commit e05d91c

Browse files
authored
Merge pull request #9222 from mhashizume/maint/main/rubocop-update
Update Rubocop
2 parents bf7710c + b00d968 commit e05d91c

Some content is hidden

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

46 files changed

+171
-62
lines changed

.rubocop.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require:
77
- rubocop-rspec
88

99
AllCops:
10-
TargetRubyVersion: 2.5
10+
TargetRubyVersion: 3.1
1111
Include:
1212
- 'lib/**/*.rb'
1313
- 'ext/**/*.rb'

.rubocop_todo.yml

+99
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ I18n/GetText/DecorateStringFormattingUsingPercent:
2222
I18n/RailsI18n/DecorateString:
2323
Enabled: false
2424

25+
Lint/AmbiguousAssignment: # new in 1.7
26+
Enabled: false
27+
28+
Lint/AmbiguousOperatorPrecedence: # new in 1.21
29+
Enabled: false
30+
31+
Lint/AmbiguousRange: # new in 1.19
32+
Enabled: false
33+
2534
# Configuration parameters: AllowedMethods.
2635
# AllowedMethods: enums
2736
Lint/ConstantDefinitionInBlock:
@@ -42,9 +51,51 @@ Lint/ConstantDefinitionInBlock:
4251
- 'lib/puppet/type/schedule.rb'
4352
- 'lib/puppet/type/tidy.rb'
4453

54+
Lint/ConstantOverwrittenInRescue: # new in 1.31
55+
Enabled: false
56+
57+
Lint/DeprecatedConstants: # new in 1.8
58+
Enabled: false
59+
60+
Lint/DuplicateBranch: # new in 1.3
61+
Enabled: false
62+
63+
Lint/DuplicateMagicComment: # new in 1.37
64+
Enabled: false
65+
66+
Lint/DuplicateMatchPattern: # new in 1.50
67+
Enabled: false
68+
69+
Lint/DuplicateRegexpCharacterClassElement: # new in 1.1
70+
Enabled: false
71+
72+
Lint/EmptyBlock: # new in 1.1
73+
Enabled: false
74+
75+
Lint/EmptyClass: # new in 1.3
76+
Enabled: false
77+
78+
Lint/EmptyInPattern: # new in 1.16
79+
Enabled: false
80+
81+
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
82+
Enabled: false
83+
84+
Lint/ItWithoutArgumentsInBlock: # new in 1.59
85+
Enabled: false
86+
87+
Lint/LambdaWithoutLiteralBlock: # new in 1.8
88+
Enabled: false
89+
90+
Lint/LiteralAssignmentInCondition: # new in 1.58
91+
Enabled: false
92+
4593
Lint/MissingSuper:
4694
Enabled: false
4795

96+
Lint/MixedCaseRange: # new in 1.53
97+
Enabled: false
98+
4899
Lint/NestedMethodDefinition:
49100
Exclude:
50101
- 'lib/puppet/pops/types/p_binary_type.rb'
@@ -59,6 +110,33 @@ Lint/NestedMethodDefinition:
59110
- 'lib/puppet/pops/types/types.rb'
60111
- 'lib/puppet/type.rb'
61112

113+
Lint/NonAtomicFileOperation: # new in 1.31
114+
Enabled: false
115+
116+
Lint/NoReturnInBeginEndBlocks: # new in 1.2
117+
Enabled: false
118+
119+
Lint/NumberedParameterAssignment: # new in 1.9
120+
Enabled: false
121+
122+
Lint/OrAssignmentToConstant: # new in 1.9
123+
Enabled: false
124+
125+
Lint/RedundantDirGlobSort: # new in 1.8
126+
Enabled: false
127+
128+
Lint/RedundantRegexpQuantifiers: # new in 1.53
129+
Enabled: false
130+
131+
Lint/RefinementImportMethods: # new in 1.27
132+
Enabled: false
133+
134+
Lint/RequireRangeParentheses: # new in 1.32
135+
Enabled: false
136+
137+
Lint/RequireRelativeSelfPath: # new in 1.22
138+
Enabled: false
139+
62140
Lint/RescueException:
63141
Exclude:
64142
- 'ext/windows/service/daemon.rb'
@@ -88,18 +166,39 @@ Lint/SuppressedException:
88166
- 'lib/puppet/util/execution.rb'
89167
- 'util/rspec_grouper'
90168

169+
Lint/SymbolConversion: # new in 1.9
170+
Enabled: false
171+
172+
Lint/ToEnumArguments: # new in 1.1
173+
Enabled: false
174+
91175
# This cop supports safe auto-correction (--auto-correct).
92176
Lint/ToJSON:
93177
Exclude:
94178
- 'lib/puppet/module_tool/metadata.rb'
95179
- 'lib/puppet/network/http/error.rb'
96180
- 'lib/puppet/pops/serialization/json.rb'
97181

182+
Lint/TripleQuotes: # new in 1.9
183+
Enabled: false
184+
185+
Lint/UnexpectedBlockArity: # new in 1.5
186+
Enabled: false
187+
188+
Lint/UnmodifiedReduceAccumulator: # new in 1.1
189+
Enabled: false
190+
98191
# This cop supports safe auto-correction (--auto-correct).
99192
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods.
100193
Lint/UnusedMethodArgument:
101194
Enabled: false
102195

196+
Lint/UselessRescue: # new in 1.43
197+
Enabled: false
198+
199+
Lint/UselessRuby2Keywords: # new in 1.23
200+
Enabled: false
201+
103202
Performance/BlockGivenWithExplicitBlock: # new in 1.9
104203
Enabled: false
105204

Gemfile

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ group(:test) do
4747
gem 'webrick', '~> 1.7', require: false
4848
gem 'yard', require: false
4949

50-
gem 'rubocop', '1.28.0', require: false, platforms: [:ruby]
50+
gem 'rubocop', '~> 1.0', require: false, platforms: [:ruby]
5151
gem 'rubocop-i18n', '~> 3.0', require: false, platforms: [:ruby]
52-
gem 'rubocop-performance', '1.13.3', require: false, platforms: [:ruby]
53-
gem 'rubocop-rake', '0.6.0', require: false, platforms: [:ruby]
54-
gem 'rubocop-rspec', '2.10.0', require: false, platforms: [:ruby]
52+
gem 'rubocop-performance', '~> 1.0', require: false, platforms: [:ruby]
53+
gem 'rubocop-rake', '~> 0.6', require: false, platforms: [:ruby]
54+
gem 'rubocop-rspec', '~> 2.0', require: false, platforms: [:ruby]
5555
end
5656

5757
group(:development, optional: true) do

lib/puppet/application/agent.rb

+2
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ def log_config
410410
end
411411
end
412412

413+
# rubocop:disable Lint/RedundantStringCoercion
413414
def fingerprint
414415
Puppet::Util::Log.newdestination(:console)
415416
cert_provider = Puppet::X509::CertProvider.new
@@ -429,6 +430,7 @@ def fingerprint
429430
Puppet.log_exception(e, _("Failed to generate fingerprint: %{message}") % { message: e.message })
430431
exit(1)
431432
end
433+
# rubocop:enable Lint/RedundantStringCoercion
432434

433435
def onetime(daemon)
434436
begin

lib/puppet/application/face_base.rb

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require_relative '../../puppet/application'
44
require_relative '../../puppet/face'
55
require 'optparse'
6-
require 'pp'
76

87
class Puppet::Application::FaceBase < Puppet::Application
98
option("--debug", "-d") do |_arg|

lib/puppet/application/filebucket.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Puppet::Application::Filebucket < Puppet::Application
1313
option("--remote", "-r")
1414
option("--verbose", "-v")
1515

16-
attr :args
16+
attr_reader :args
1717

1818
def summary
1919
_("Store and retrieve files in a filebucket")

lib/puppet/file_bucket/file.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Puppet::FileBucket::File
1313
extend Puppet::Indirector
1414
indirects :file_bucket_file, :terminus_class => :selector
1515

16-
attr :bucket_path
16+
attr_reader :bucket_path
1717

1818
def self.supported_formats
1919
[:binary]

lib/puppet/functions/getvar.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_from_navigation(scope, navigation, default_value = nil, &block)
6969
matches = navigation.match(/^((::)?(\w+::)*\w+)(.*)\z/)
7070
navigation = matches[4]
7171
if navigation[0] == '.'
72-
navigation = navigation[1..-1]
72+
navigation = navigation[1..]
7373
else
7474
unless navigation.empty?
7575
raise ArgumentError, _("First character after var name in get string must be a '.' - got %{char}") % { char: navigation[0] }

lib/puppet/metatype/manager.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def allclear
2828
#
2929
def clear_misses
3030
unless @types.nil?
31-
@types.delete_if { |_, v| v.nil? }
31+
@types.compact
3232
end
3333
end
3434

lib/puppet/module_tool/errors/shared.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ def initialize(options)
106106
@requested_module = options[:requested_module]
107107
@requested_version = options[:requested_version]
108108
@conditions = options[:conditions]
109-
@source = options[:source][1..-1]
109+
@source = options[:source][1..]
110110

111111
super _("'%{module_name}' (%{version}) requested; Invalid dependency cycle") % { module_name: @requested_module, version: v(@requested_version) }
112112
end
113113

114114
def multiline
115115
dependency_list = []
116116
dependency_list << _("You specified '%{name}' (%{version})") % { name: @source.first[:name], version: v(@requested_version) }
117-
dependency_list += @source[1..-1].map do |m|
117+
dependency_list += @source[1..].map do |m|
118118
# TRANSLATORS This message repeats as separate lines as a list under the heading "You specified '%{name}' (%{version})\n"
119119
_("This depends on '%{name}' (%{version})") % { name: m[:name], version: v(m[:version]) }
120120
end

lib/puppet/network/http/api/indirected_routes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def call(request, response)
5757

5858
def uri2indirection(http_method, uri, params)
5959
# the first field is always nil because of the leading slash,
60-
indirection_type, version, indirection_name, key = uri.split("/", 5)[1..-1]
60+
indirection_type, version, indirection_name, key = uri.split("/", 5)[1..]
6161
url_prefix = "/#{indirection_type}/#{version}"
6262
environment = params.delete(:environment)
6363

lib/puppet/network/http/connection.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def to_url(path)
266266

267267
def normalize_path(path)
268268
if path[0] == '/'
269-
path[1..-1]
269+
path[1..]
270270
else
271271
path
272272
end

lib/puppet/parser/functions/sprintf.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
This statement produces a notice of `value is : 42`."
4646
) do |args|
4747
fmt = args[0]
48-
args = args[1..-1]
48+
args = args[1..]
4949
begin
5050
return sprintf(fmt, *args)
5151
rescue KeyError => e

lib/puppet/parser/scope.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ def lookupvar(name, options = EMPTY_HASH)
496496
# If name has '::' in it, it is resolved as a qualified variable
497497
unless (idx = name.index('::')).nil?
498498
# Always drop leading '::' if present as that is how the values are keyed.
499-
return lookup_qualified_variable(idx == 0 ? name[2..-1] : name, options)
499+
return lookup_qualified_variable(idx == 0 ? name[2..] : name, options)
500500
end
501501

502502
# At this point, search is for a non qualified (simple) name
@@ -609,7 +609,7 @@ def lookup_qualified_variable(fqn, options)
609609
# not found - search inherited scope for class
610610
leaf_index = fqn.rindex('::')
611611
unless leaf_index.nil?
612-
leaf_name = fqn[(leaf_index + 2)..-1]
612+
leaf_name = fqn[(leaf_index + 2)..]
613613
class_name = fqn[0, leaf_index]
614614
begin
615615
qs = qualified_scope(class_name)
@@ -898,9 +898,9 @@ def to_s
898898
# check module paths first since they may be in the environment (i.e. they are longer)
899899
module_path = environment.full_modulepath.detect { |m_path| path.start_with?(m_path) }
900900
if module_path
901-
path = "<module>" + path[module_path.length..-1]
901+
path = "<module>" + path[module_path.length..]
902902
elsif env_path && path && path.start_with?(env_path)
903-
path = "<env>" + path[env_path.length..-1]
903+
path = "<env>" + path[env_path.length..]
904904
end
905905
# Make the output appear as "Scope(path, line)"
906906
"Scope(#{[path, detail[1]].join(', ')})"

lib/puppet/pops/evaluator/access_operator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ def access_PClassType(o, scope, keys)
703703

704704
name = c.downcase
705705
# Remove leading '::' since all references are global, and 3x runtime does the wrong thing
706-
name = name[2..-1] if name[0, 2] == NS
706+
name = name[2..] if name[0, 2] == NS
707707

708708
fail(Issues::ILLEGAL_NAME, @semantic.keys[i], { :name => c }) unless name =~ Patterns::NAME
709709

lib/puppet/pops/evaluator/closure.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def combine_values_with_parameters(scope, args)
266266
given_argument = args[index]
267267
if param_captures
268268
# get excess arguments
269-
value = args[(parameter_count - 1)..-1]
269+
value = args[(parameter_count - 1)..]
270270
# If the input was a single nil, or undef, and there is a default, use the default
271271
# This supports :undef in case it was used in a 3x data structure and it is passed as an arg
272272
#

lib/puppet/pops/evaluator/deferred_resolver.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def resolve_future(f)
161161
mapped_arguments = map_arguments(f.arguments)
162162
# if name starts with $ then this is a call to dig
163163
if func_name[0] == DOLLAR
164-
var_name = func_name[1..-1]
164+
var_name = func_name[1..]
165165
func_name = DIG
166166
mapped_arguments.insert(0, @scope[var_name])
167167
end

lib/puppet/pops/evaluator/epp_evaluator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def self.evaluate(parser, func_name, scope, use_global_scope_only, parse_result,
8686
filtered_args = {}
8787
template_args.each_pair do |k, v|
8888
if k =~ /::/
89-
k = k[2..-1] if k.start_with?('::')
89+
k = k[2..] if k.start_with?('::')
9090
scope[k] = v
9191
else
9292
filtered_args[k] = v

lib/puppet/pops/functions/dispatch.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def weave(scope, args)
9595
# parameter values in the received
9696
if knit < 0
9797
idx = -knit - 1
98-
new_args += args[idx..-1] if idx < args.size
98+
new_args += args[idx..] if idx < args.size
9999
else
100100
new_args << args[knit] if knit < args.size
101101
end

lib/puppet/pops/loader/loader_paths.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def effective_path(typed_name, start_index_in_name)
147147
if start_index_in_name > 0
148148
return nil if start_index_in_name >= parts.size
149149

150-
parts = parts[start_index_in_name..-1]
150+
parts = parts[start_index_in_name..]
151151
end
152152
"#{File.join(generic_path, parts)}#{extension}"
153153
end
@@ -371,7 +371,7 @@ def effective_path(typed_name, start_index_in_name)
371371
if start_index_in_name > 0
372372
return nil if start_index_in_name >= parts.size
373373

374-
parts = parts[start_index_in_name..-1]
374+
parts = parts[start_index_in_name..]
375375
end
376376
basename = File.join(generic_path, parts)
377377
@extensions.map { |ext| "#{basename}#{ext}" }

lib/puppet/pops/loader/typed_name.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def initialize(type, name, name_authority = Pcore::RUNTIME_NAME_AUTHORITY)
2121
parts = name.to_s.split(DOUBLE_COLON)
2222
if parts[0].empty?
2323
parts.shift
24-
@name = name[2..-1]
24+
@name = name[2..]
2525
else
2626
@name = name
2727
end

lib/puppet/pops/lookup/lookup_adapter.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def convert_result(key, lookup_options, lookup_invocation, the_lookup)
111111
end
112112
end
113113
begin
114-
result = lookup_invocation.scope.call_function(NEW, [convert_to[0], result, *convert_to[1..-1]])
114+
result = lookup_invocation.scope.call_function(NEW, [convert_to[0], result, *convert_to[1..]])
115115
# TRANSLATORS 'lookup_options', 'convert_to' and args_string variable should not be translated,
116116
args_string = Puppet::Pops::Types::StringConverter.singleton.convert(convert_to)
117117
lookup_invocation.report_text { _("Applying convert_to lookup_option with arguments %{args}") % { args: args_string } }

lib/puppet/pops/parser/lexer2.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def initialize
458458
before = scn.pos
459459
value = scn.scan(PATTERN_DOLLAR_VAR)
460460
if value
461-
emit_completed([:VARIABLE, value[1..-1].freeze, scn.pos - before], before)
461+
emit_completed([:VARIABLE, value[1..].freeze, scn.pos - before], before)
462462
else
463463
# consume the $ and let higher layer complain about the error instead of getting a syntax error
464464
emit(TOKEN_VARIABLE_EMPTY, before)

0 commit comments

Comments
 (0)