Skip to content

Commit 4d27abc

Browse files
committed
Rubocop upgrade and safe autocorrectable fixes
1 parent eaef6a5 commit 4d27abc

File tree

14 files changed

+110
-37
lines changed

14 files changed

+110
-37
lines changed

.rubocop.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ inherit_from: .rubocop_todo.yml
33

44
require: rubocop-rspec
55
AllCops:
6-
TargetRubyVersion: '2.5'
6+
NewCops: enable
7+
TargetRubyVersion: '3.1'
78
Include:
89
- "**/*.rb"
910
Exclude:

.rubocop_todo.yml

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-12-19 10:44:38 UTC using RuboCop version 1.48.1.
3+
# on 2025-03-10 20:03:26 UTC using RuboCop version 1.70.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9+
# Offense count: 19
10+
# Configuration parameters: AllowComments, AllowEmptyLambdas.
11+
Lint/EmptyBlock:
12+
Exclude:
13+
- 'lib/puppet/resource_api/value_creator.rb'
14+
- 'spec/puppet/resource_api/base_context_spec.rb'
15+
16+
# Offense count: 12
17+
# Configuration parameters: AllowComments.
18+
Lint/EmptyClass:
19+
Exclude:
20+
- 'lib/puppet/resource_api/type_definition.rb'
21+
- 'lib/puppet/util/network_device/simple/device.rb'
22+
- 'spec/puppet/provider/test_provider/test_provider.rb'
23+
- 'spec/puppet/resource_api/transport/wrapper_spec.rb'
24+
- 'spec/puppet/resource_api/transport_spec.rb'
25+
- 'spec/puppet/resource_api_spec.rb'
26+
27+
# Offense count: 12
28+
# This cop supports unsafe autocorrection (--autocorrect-all).
29+
RSpec/BeEq:
30+
Exclude:
31+
- 'spec/puppet/resource_api/parameter_spec.rb'
32+
- 'spec/puppet/resource_api/property_spec.rb'
33+
- 'spec/puppet/resource_api/read_only_parameter_spec.rb'
34+
- 'spec/puppet/resource_api/transport/wrapper_spec.rb'
35+
- 'spec/puppet/resource_api/value_creator_spec.rb'
36+
937
# Offense count: 25
1038
# Configuration parameters: IgnoredMetadata.
1139
RSpec/DescribeClass:
1240
Enabled: false
1341

14-
# Offense count: 33
42+
# Offense count: 37
1543
# Configuration parameters: CountAsOne.
1644
RSpec/ExampleLength:
1745
Max: 16
@@ -23,7 +51,7 @@ RSpec/InstanceVariable:
2351
- 'spec/acceptance/namevar_spec.rb'
2452
- 'spec/puppet/resource_api/data_type_handling_spec.rb'
2553

26-
# # Offense count: 15
54+
# Offense count: 15
2755
RSpec/LeakyConstantDeclaration:
2856
Exclude:
2957
- 'spec/puppet/resource_api/base_context_spec.rb'
@@ -49,3 +77,47 @@ RSpec/NestedGroups:
4977
RSpec/SubjectStub:
5078
Exclude:
5179
- 'spec/puppet/resource_api/base_context_spec.rb'
80+
81+
# Offense count: 24
82+
# This cop supports unsafe autocorrection (--autocorrect-all).
83+
# Configuration parameters: EnforcedStyle.
84+
# SupportedStyles: constant, string
85+
RSpec/VerifiedDoubleReference:
86+
Exclude:
87+
- 'spec/integration/resource_api_spec.rb'
88+
- 'spec/puppet/resource_api/property_spec.rb'
89+
- 'spec/puppet/resource_api/puppet_context_spec.rb'
90+
- 'spec/puppet/resource_api/simple_provider_spec.rb'
91+
- 'spec/puppet/resource_api/transport_spec.rb'
92+
- 'spec/puppet/resource_api/type_definition_spec.rb'
93+
- 'spec/puppet/resource_api_spec.rb'
94+
95+
# Offense count: 1
96+
# This cop supports unsafe autocorrection (--autocorrect-all).
97+
# Configuration parameters: AllowedReceivers.
98+
Style/CollectionCompact:
99+
Exclude:
100+
- 'lib/puppet/resource_api.rb'
101+
102+
# Offense count: 3
103+
# This cop supports unsafe autocorrection (--autocorrect-all).
104+
# Configuration parameters: AllowSplatArgument.
105+
Style/HashConversion:
106+
Exclude:
107+
- 'lib/puppet/resource_api.rb'
108+
- 'lib/puppet/resource_api/glue.rb'
109+
- 'lib/puppet/resource_api/simple_provider.rb'
110+
111+
# Offense count: 2
112+
# This cop supports unsafe autocorrection (--autocorrect-all).
113+
# Configuration parameters: AllowedReceivers.
114+
# AllowedReceivers: Thread.current
115+
Style/HashEachMethods:
116+
Exclude:
117+
- 'lib/puppet/resource_api/type_definition.rb'
118+
119+
# Offense count: 1
120+
# This cop supports unsafe autocorrection (--autocorrect-all).
121+
Style/SlicingWithRange:
122+
Exclude:
123+
- 'lib/puppet/resource_api.rb'

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ group :tests do
1919
# since the Resource API runs inside the puppetserver, test against the JRuby versions we ship
2020
# these require special dependencies to have everything load properly
2121
# rubocop 1.48 supports JRuby 9.3+, which includes coverage for versions we support
22-
gem 'rubocop', '~> 1.48.1', require: false
22+
gem 'rubocop', '~> 1.70.0', require: false
2323
gem 'rubocop-rspec', '~> 2.20.0', require: false
2424
gem 'rubocop-performance', '~> 1.17.1', require: false
2525
end

contrib/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Code modified from: https://gist.github.com/hanloong/9849098
55
require 'English'
66

7-
changed_files = `git diff --name-only --cached --diff-filter=ACM`.split(/\n/)
7+
changed_files = `git diff --name-only --cached --diff-filter=ACM`.split("\n")
88
changed_files = changed_files.select do |file_name|
99
File.extname(file_name) == '.rb'
1010
end.join(' ')

lib/puppet/resource_api.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def initialize(attributes)
104104
attributes[:title] = @title if attributes[:title].nil? && !type_definition.namevars.empty?
105105
end
106106

107-
super(attributes)
107+
super
108108
end
109109

110110
def name
@@ -541,8 +541,8 @@ def load_provider(type_name)
541541
end
542542
rescue NameError
543543
if device_name # line too long # rubocop:disable Style/GuardClause
544-
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name}"\
545-
" nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
544+
raise Puppet::DevError, "Found neither the device-specific provider class Puppet::Provider::#{class_name}::#{device_class_name} in puppet/provider/#{type_name}/#{device_name} " \
545+
"nor the generic provider class Puppet::Provider::#{class_name}::#{class_name} in puppet/provider/#{type_name}/#{type_name}"
546546
else
547547
raise Puppet::DevError, "provider class Puppet::Provider::#{class_name}::#{class_name} not found in puppet/provider/#{type_name}/#{type_name}"
548548
end

lib/puppet/resource_api/data_type_handling.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def self.boolean_munge(value)
142142
# @private
143143
def self.ambiguous_error_msg(error_msg_prefix, value, type)
144144
"#{error_msg_prefix} #{value.inspect} is not unabiguously convertable to " \
145-
"#{type}"
145+
"#{type}"
146146
end
147147

148148
# Validates the `value` against the specified `type`.
@@ -195,9 +195,9 @@ def self.parse_puppet_type(attr_name, type)
195195
Puppet::Pops::Types::TypeParser.singleton.parse(type)
196196
rescue Puppet::ParseErrorWithIssue => e
197197
raise Puppet::DevError, "The type of the `#{attr_name}` attribute " \
198-
"`#{type}` could not be parsed: #{e.message}"
198+
"`#{type}` could not be parsed: #{e.message}"
199199
rescue Puppet::ParseError => e
200200
raise Puppet::DevError, "The type of the `#{attr_name}` attribute " \
201-
"`#{type}` is not recognised: #{e.message}"
201+
"`#{type}` is not recognised: #{e.message}"
202202
end
203203
end

lib/puppet/resource_api/transport.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def self.validate(name, connection_info)
9494
transport_schema = transports[name]
9595
raise Puppet::DevError, format('Transport for `%<target>s` not registered with `%<environment>s`', target: name, environment: current_environment_name) if transport_schema.nil?
9696

97-
clean_bolt_attributes(transport_schema, connection_info) if connection_info.key?(:"remote-transport")
97+
clean_bolt_attributes(transport_schema, connection_info) if connection_info.key?(:'remote-transport')
9898

9999
apply_defaults(transport_schema, connection_info)
100100
message_prefix = 'The connection info provided does not match the Transport Schema'

lib/puppet/resource_api/transport/wrapper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ def respond_to_missing?(name, _include_private)
4141
(@transport.respond_to? name) || super
4242
end
4343

44-
def method_missing(method_name, *args, &block)
44+
def method_missing(method_name, ...)
4545
if @transport.respond_to? method_name
46-
@transport.send(method_name, *args, &block)
46+
@transport.send(method_name, ...)
4747
else
4848
super
4949
end

lib/puppet/resource_api/type_definition.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def title_patterns
2525
end
2626

2727
def validate_schema(definition, attr_key)
28-
super(definition, attr_key)
28+
super
2929
%i[title provider alias audit before consume export loglevel noop notify require schedule stage subscribe tag].each do |name|
3030
raise Puppet::DevError, format('must not define an attribute called `%<name>s`', name: name.inspect) if definition[attr_key].key? name
3131
end
@@ -234,7 +234,7 @@ def check_schema_values(resource)
234234
next unless attributes[key]
235235

236236
type = @data_type_cache[attributes[key][:type]]
237-
is_sensitive = (attributes[key].key?(:sensitive) && (attributes[key][:sensitive] == true))
237+
is_sensitive = attributes[key].key?(:sensitive) && (attributes[key][:sensitive] == true)
238238
error_message = Puppet::ResourceApi::DataTypeHandling.try_validate(
239239
type,
240240
value,

spec/acceptance/device_spec.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
RSpec.describe 'exercising a device provider' do
99
let(:common_args) { '--verbose --trace --strict=error --modulepath spec/fixtures' }
1010
let(:default_type_values) do
11-
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF '\
12-
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 '\
13-
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
11+
'string="meep" boolean=true integer=15 float=1.23 ensure=present variant_pattern=AE321EEF ' \
12+
'url="http://www.puppet.com" boolean_param=false integer_param=99 float_param=3.21 ' \
13+
'ensure_param=present variant_pattern_param=0xAE321EEF url_param="https://www.google.com"'
1414
end
1515

1616
before(:all) do # rubocop:disable RSpec/BeforeAfterAll
@@ -32,8 +32,8 @@
3232

3333
it 'deals with canonicalized resources correctly' do
3434
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
35-
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
36-
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
35+
stdmatch = 'Error: /Device_provider\[wibble\]: Could not evaluate: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
36+
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
3737
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
3838
expect(stdout_str).to match(/#{stdmatch}/)
3939
expect(status).not_to be_success
@@ -45,8 +45,8 @@
4545

4646
it 'deals with canonicalized resources correctly' do
4747
stdout_str, status = Open3.capture2e("puppet resource #{common_args} device_provider wibble ensure=present #{default_type_values}")
48-
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n'\
49-
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n'\
48+
stdmatch = 'Warning: device_provider\[wibble\]#get has not provided canonicalized values.\n' \
49+
'Returned values: \{:name=>"wibble", :ensure=>"present", :string=>"sample", :string_ro=>"fixed"\}\n' \
5050
'Canonicalized values: \{:name=>"wibble", :ensure=>"present", :string=>"changed", :string_ro=>"fixed"\}'
5151
expect(stdout_str).to match(/#{stdmatch}/)
5252
expect(status).to be_success
@@ -155,9 +155,9 @@ def is_device_apply_supported?
155155
it 'applies the catalog successfully' do
156156
Tempfile.create('fact_set') do |f|
157157
f.write 'device_provider{ "foo":' \
158-
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", '\
159-
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, '\
160-
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
158+
'ensure => "present", boolean => true, integer => 15, float => 1.23, variant_pattern => "0x1234ABCD", ' \
159+
'url => "http://www.google.com", boolean_param => false, integer_param => 99, float_param => 3.21, ' \
160+
'ensure_param => "present", variant_pattern_param => "9A2222ED", url_param => "http://www.puppet.com" }'
161161
f.close
162162

163163
stdout_str, _status = Open3.capture2e("puppet device #{common_args} --deviceconfig #{device_conf.path} --apply #{f.path}")

0 commit comments

Comments
 (0)