Skip to content

Commit 4513a58

Browse files
committed
(CONT-773) Rubocop Auto Fixes 11-15
- RSpec/ExampleWording - RSpec/ImplicitSubject - Style/IfUnlessModifier - Style/QuotedSymbols - Style/RedundantRegexpEscape
1 parent ec7f4e2 commit 4513a58

File tree

18 files changed

+320
-370
lines changed

18 files changed

+320
-370
lines changed

.rubocop_todo.yml

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2023-04-21 09:13:34 UTC using RuboCop version 1.48.1.
3+
# on 2023-04-21 12:46:34 UTC using RuboCop version 1.48.1.
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
@@ -87,18 +87,22 @@ RSpec/ExampleWording:
8787
Exclude:
8888
- 'spec/acceptance/apt_key_provider_spec.rb'
8989

90-
# Offense count: 2
91-
# This cop supports safe autocorrection (--autocorrect).
92-
RSpec/ExcessiveDocstringSpacing:
90+
# Offense count: 3
91+
RSpec/LeakyConstantDeclaration:
9392
Exclude:
9493
- 'spec/defines/key_compat_spec.rb'
95-
- 'spec/defines/setting_spec.rb'
94+
- 'spec/defines/source_compat_spec.rb'
95+
- 'spec/defines/source_spec.rb'
96+
97+
# Offense count: 3
98+
# Configuration parameters: AllowSubject.
99+
RSpec/MultipleMemoizedHelpers:
100+
Max: 6
96101

97102
# Offense count: 204
98-
# This cop supports safe autocorrection (--autocorrect).
99-
# Configuration parameters: EnforcedStyle.
100-
# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit
101-
RSpec/ImplicitSubject:
103+
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
104+
# SupportedStyles: always, named_only
105+
RSpec/NamedSubject:
102106
Exclude:
103107
- 'spec/classes/apt_backports_spec.rb'
104108
- 'spec/classes/apt_spec.rb'
@@ -114,18 +118,6 @@ RSpec/ImplicitSubject:
114118
- 'spec/defines/source_spec.rb'
115119
- 'spec/unit/facter/apt_update_last_success_spec.rb'
116120

117-
# Offense count: 3
118-
RSpec/LeakyConstantDeclaration:
119-
Exclude:
120-
- 'spec/defines/key_compat_spec.rb'
121-
- 'spec/defines/source_compat_spec.rb'
122-
- 'spec/defines/source_spec.rb'
123-
124-
# Offense count: 3
125-
# Configuration parameters: AllowSubject.
126-
RSpec/MultipleMemoizedHelpers:
127-
Max: 6
128-
129121
# Offense count: 2
130122
# Configuration parameters: AllowedGroups.
131123
RSpec/NestedGroups:
@@ -170,33 +162,11 @@ Style/GlobalStdStream:
170162
Exclude:
171163
- 'tasks/init.rb'
172164

173-
# Offense count: 10
174-
# This cop supports safe autocorrection (--autocorrect).
175-
Style/IfUnlessModifier:
176-
Exclude:
177-
- 'lib/facter/apt_updates.rb'
178-
- 'lib/puppet/provider/apt_key/apt_key.rb'
179-
- 'lib/puppet/type/apt_key.rb'
180-
181165
# Offense count: 1
182166
Style/MixinUsage:
183167
Exclude:
184168
- 'spec/spec_helper.rb'
185169

186-
# Offense count: 3
187-
# This cop supports safe autocorrection (--autocorrect).
188-
# Configuration parameters: EnforcedStyle.
189-
# SupportedStyles: same_as_string_literals, single_quotes, double_quotes
190-
Style/QuotedSymbols:
191-
Exclude:
192-
- 'spec/unit/puppet/provider/apt_key_spec.rb'
193-
194-
# Offense count: 4
195-
# This cop supports safe autocorrection (--autocorrect).
196-
Style/RedundantRegexpEscape:
197-
Exclude:
198-
- 'lib/puppet/type/apt_key.rb'
199-
200170
# Offense count: 1
201171
# This cop supports safe autocorrection (--autocorrect).
202172
# Configuration parameters: EnforcedStyle.

lib/facter/apt_updates.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def get_updates(upgrade_option)
2323
%r{ gNewSense[^\s]+-security[, ]},
2424
]
2525
re = Regexp.union(security_matches)
26-
if line.match(re)
27-
apt_updates[1].push(package)
28-
end
26+
apt_updates[1].push(package) if line.match(re)
2927
end
3028
end
3129
end
@@ -36,19 +34,15 @@ def get_updates(upgrade_option)
3634
confine osfamily: 'Debian'
3735
setcode do
3836
apt_package_updates = get_updates('upgrade')
39-
if !apt_package_updates.nil? && apt_package_updates.length == 2
40-
apt_package_updates != [[], []]
41-
end
37+
apt_package_updates != [[], []] if !apt_package_updates.nil? && apt_package_updates.length == 2
4238
end
4339
end
4440

4541
Facter.add('apt_has_dist_updates') do
4642
confine osfamily: 'Debian'
4743
setcode do
4844
apt_dist_updates = get_updates('dist-upgrade')
49-
if !apt_dist_updates.nil? && apt_dist_updates.length == 2
50-
apt_dist_updates != [[], []]
51-
end
45+
apt_dist_updates != [[], []] if !apt_dist_updates.nil? && apt_dist_updates.length == 2
5246
end
5347
end
5448

lib/puppet/provider/apt_key/apt_key.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ def self.instances
4949

5050
expired = false
5151

52-
if line_hash[:key_expiry]
53-
expired = Time.now >= line_hash[:key_expiry]
54-
end
52+
expired = Time.now >= line_hash[:key_expiry] if line_hash[:key_expiry]
5553

5654
new(
5755
name: line_hash[:key_fingerprint],
@@ -171,9 +169,7 @@ def tempfile(content)
171169

172170
found_match = false
173171
extracted_key.each_line do |line|
174-
if line.chomp == name
175-
found_match = true
176-
end
172+
found_match = true if line.chomp == name
177173
end
178174
unless found_match
179175
raise(_('The id in your manifest %{_resource} and the fingerprint from content/source don\'t match. Check for an error in the id and content/source is legitimate.') % { _resource: resource[:name] }) # rubocop:disable Layout/LineLength
@@ -196,9 +192,7 @@ def create
196192
# Breaking up the command like this is needed because it blows up
197193
# if --recv-keys isn't the last argument.
198194
command.push('adv', '--no-tty', '--keyserver', resource[:server])
199-
unless resource[:options].nil?
200-
command.push('--keyserver-options', resource[:options])
201-
end
195+
command.push('--keyserver-options', resource[:options]) unless resource[:options].nil?
202196
command.push('--recv-keys', resource[:id])
203197
elsif resource[:content]
204198
key_file = tempfile(resource[:content])

lib/puppet/type/apt_key.rb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,10 @@
2525
ensurable
2626

2727
validate do
28-
if self[:refresh] == true && self[:ensure] == :absent
29-
raise(_('ensure => absent and refresh => true are mutually exclusive'))
30-
end
31-
if self[:content] && self[:source]
32-
raise(_('The properties content and source are mutually exclusive.'))
33-
end
28+
raise(_('ensure => absent and refresh => true are mutually exclusive')) if self[:refresh] == true && self[:ensure] == :absent
29+
raise(_('The properties content and source are mutually exclusive.')) if self[:content] && self[:source]
3430

35-
if self[:id].length < 40
36-
warning(_('The id should be a full fingerprint (40 characters), see README.'))
37-
end
31+
warning(_('The id should be a full fingerprint (40 characters), see README.')) if self[:id].length < 40
3832
end
3933

4034
newparam(:id, namevar: true) do
@@ -62,16 +56,14 @@
6256
end
6357

6458
autorequire(:file) do
65-
if self[:source] && Pathname.new(self[:source]).absolute?
66-
self[:source]
67-
end
59+
self[:source] if self[:source] && Pathname.new(self[:source]).absolute?
6860
end
6961

7062
newparam(:server) do
7163
desc 'The key server to fetch the key from based on the ID. It can either be a domain name or url.'
7264
defaultto :'keyserver.ubuntu.com'
7365

74-
newvalues(%r{\A((hkp|hkps|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?(\/[a-zA-Z\d\-_.]+)*\/?$})
66+
newvalues(%r{\A((hkp|hkps|http|https)://)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?(/[a-zA-Z\d\-_.]+)*/?$})
7567
end
7668

7769
newparam(:options) do

spec/classes/apt_backports_spec.rb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
end
2626

2727
it {
28-
is_expected.to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian',
29-
repos: 'main contrib non-free',
30-
release: 'stretch-backports',
31-
pin: { 'priority' => 200, 'release' => 'stretch-backports' })
28+
expect(subject).to contain_apt__source('backports').with(location: 'http://deb.debian.org/debian',
29+
repos: 'main contrib non-free',
30+
release: 'stretch-backports',
31+
pin: { 'priority' => 200, 'release' => 'stretch-backports' })
3232
}
3333
end
3434

@@ -51,11 +51,11 @@
5151
end
5252

5353
it {
54-
is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu',
55-
key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
56-
repos: 'main universe multiverse restricted',
57-
release: 'bionac-backports',
58-
pin: { 'priority' => 200, 'release' => 'bionac-backports' })
54+
expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu',
55+
key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
56+
repos: 'main universe multiverse restricted',
57+
release: 'bionac-backports',
58+
pin: { 'priority' => 200, 'release' => 'bionac-backports' })
5959
}
6060
end
6161

@@ -87,11 +87,11 @@
8787
end
8888

8989
it {
90-
is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu-test',
91-
key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
92-
repos: 'main',
93-
release: 'vivid',
94-
pin: { 'priority' => 90, 'release' => 'vivid' })
90+
expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu-test',
91+
key: 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553',
92+
repos: 'main',
93+
release: 'vivid',
94+
pin: { 'priority' => 90, 'release' => 'vivid' })
9595
}
9696
end
9797

@@ -124,8 +124,8 @@
124124
end
125125

126126
it {
127-
is_expected.to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
128-
pin: { 'priority' => '90' })
127+
expect(subject).to contain_apt__source('backports').with(key: { 'id' => 'A1BD8E9D78F7FE5C3E65D8AF8B48AD6246925553' },
128+
pin: { 'priority' => '90' })
129129
}
130130
end
131131
end
@@ -159,11 +159,11 @@
159159
end
160160

161161
it {
162-
is_expected.to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu',
163-
key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
164-
repos: 'main universe multiverse restricted',
165-
release: 'trusty-backports',
166-
pin: { 'priority' => 200, 'release' => 'trusty-backports' })
162+
expect(subject).to contain_apt__source('backports').with(location: 'http://archive.ubuntu.com/ubuntu',
163+
key: '630239CC130E1A7FD81A27B140976EAF437D05B5',
164+
repos: 'main universe multiverse restricted',
165+
release: 'trusty-backports',
166+
pin: { 'priority' => 200, 'release' => 'trusty-backports' })
167167
}
168168
end
169169

@@ -177,7 +177,7 @@
177177
end
178178

179179
it do
180-
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
180+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
181181
end
182182
end
183183

@@ -191,7 +191,7 @@
191191
end
192192

193193
it do
194-
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
194+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
195195
end
196196
end
197197

@@ -205,7 +205,7 @@
205205
end
206206

207207
it do
208-
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
208+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
209209
end
210210
end
211211

@@ -219,7 +219,7 @@
219219
end
220220

221221
it do
222-
is_expected.to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
222+
expect(subject).to raise_error(Puppet::Error, %r{If not on Debian or Ubuntu, you must explicitly pass location, release, repos, and key})
223223
end
224224
end
225225
end
@@ -250,7 +250,7 @@
250250
end
251251

252252
it do
253-
is_expected.to raise_error(Puppet::Error, %r{expects a})
253+
expect(subject).to raise_error(Puppet::Error, %r{expects a})
254254
end
255255
end
256256

@@ -262,7 +262,7 @@
262262
end
263263

264264
it do
265-
is_expected.to raise_error(Puppet::Error, %r{expects a})
265+
expect(subject).to raise_error(Puppet::Error, %r{expects a})
266266
end
267267
end
268268

@@ -274,7 +274,7 @@
274274
end
275275

276276
it do
277-
is_expected.to raise_error(Puppet::Error, %r{expects a})
277+
expect(subject).to raise_error(Puppet::Error, %r{expects a})
278278
end
279279
end
280280

@@ -286,7 +286,7 @@
286286
end
287287

288288
it do
289-
is_expected.to raise_error(Puppet::Error, %r{expects a})
289+
expect(subject).to raise_error(Puppet::Error, %r{expects a})
290290
end
291291
end
292292

@@ -298,7 +298,7 @@
298298
end
299299

300300
it do
301-
is_expected.to raise_error(Puppet::Error, %r{expects a})
301+
expect(subject).to raise_error(Puppet::Error, %r{expects a})
302302
end
303303
end
304304
end

0 commit comments

Comments
 (0)