Skip to content

Commit e1a809d

Browse files
committed
(CONT-801) Autocorrect safe group 8
1 parent e2c3f6a commit e1a809d

19 files changed

+41
-97
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -302,17 +302,6 @@ Style/SlicingWithRange:
302302
Exclude:
303303
- 'spec/functions/validate_x509_rsa_key_pair_spec.rb'
304304

305-
# Offense count: 6
306-
# This cop supports safe autocorrection (--autocorrect).
307-
# Configuration parameters: AllowModifier.
308-
Style/SoleNestedConditional:
309-
Exclude:
310-
- 'lib/puppet/parser/functions/convert_base.rb'
311-
- 'lib/puppet/parser/functions/getparam.rb'
312-
- 'lib/puppet/parser/functions/prefix.rb'
313-
- 'lib/puppet/parser/functions/suffix.rb'
314-
- 'lib/puppet/type/file_line.rb'
315-
316305
# Offense count: 2
317306
# This cop supports unsafe autocorrection (--autocorrect-all).
318307
Style/StringChars:
@@ -339,36 +328,3 @@ Style/SymbolProc:
339328
- 'lib/puppet/parser/functions/fqdn_uuid.rb'
340329
- 'lib/puppet/parser/functions/shell_join.rb'
341330
- 'lib/puppet/parser/functions/squeeze.rb'
342-
343-
# Offense count: 1
344-
# This cop supports safe autocorrection (--autocorrect).
345-
# Configuration parameters: EnforcedStyle, AllowSafeAssignment.
346-
# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex
347-
Style/TernaryParentheses:
348-
Exclude:
349-
- 'spec/unit/facter/root_home_spec.rb'
350-
351-
# Offense count: 31
352-
# This cop supports safe autocorrection (--autocorrect).
353-
# Configuration parameters: EnforcedStyleForMultiline.
354-
# SupportedStylesForMultiline: comma, consistent_comma, no_comma
355-
Style/TrailingCommaInHashLiteral:
356-
Exclude:
357-
- 'lib/puppet/parser/functions/pw_hash.rb'
358-
- 'lib/puppet/parser/functions/str2saltedpbkdf2.rb'
359-
- 'spec/classes/manage_spec.rb'
360-
- 'spec/functions/has_interface_with_spec.rb'
361-
- 'spec/functions/has_ip_address_spec.rb'
362-
- 'spec/functions/has_ip_network_spec.rb'
363-
- 'spec/functions/os_version_gte_spec.rb'
364-
- 'spec/spec_helper.rb'
365-
- 'spec/unit/puppet/provider/file_line/ruby_spec.rb'
366-
- 'spec/unit/puppet/provider/file_line/ruby_spec_alter.rb'
367-
- 'spec/unit/puppet/provider/file_line/ruby_spec_use_cases.rb'
368-
369-
# Offense count: 3
370-
# This cop supports safe autocorrection (--autocorrect).
371-
Style/UnpackFirst:
372-
Exclude:
373-
- 'lib/puppet/parser/functions/str2saltedpbkdf2.rb'
374-
- 'lib/puppet/parser/functions/str2saltedsha512.rb'

lib/puppet/parser/functions/convert_base.rb

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,9 @@ module Puppet::Parser::Functions
3232
raise Puppet::ParseError, 'convert_base(): First argument must be either a string or an integer' unless args[0].is_a?(Integer) || args[0].is_a?(String)
3333
raise Puppet::ParseError, 'convert_base(): Second argument must be either a string or an integer' unless args[1].is_a?(Integer) || args[1].is_a?(String)
3434

35-
if args[0].is_a?(String)
36-
raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless %r{^[0-9]+$}.match?(args[0])
37-
end
35+
raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' if args[0].is_a?(String) && !%r{^[0-9]+$}.match?(args[0])
3836

39-
if args[1].is_a?(String)
40-
raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' unless %r{^[0-9]+$}.match?(args[1])
41-
end
37+
raise Puppet::ParseError, 'convert_base(): First argument must be an integer or a string corresponding to an integer in base 10' if args[1].is_a?(String) && !%r{^[0-9]+$}.match?(args[1])
4238

4339
number_to_convert = args[0]
4440
new_base = args[1]

lib/puppet/parser/functions/getparam.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@
5151
return '' if param.empty?
5252

5353
resource = findresource(reference.to_s)
54-
if resource
55-
return resource[param] unless resource[param].nil?
56-
end
54+
return resource[param] if resource && !resource[param].nil?
5755

5856
return ''
5957
end

lib/puppet/parser/functions/prefix.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ module Puppet::Parser::Functions
2929

3030
prefix = arguments[1] if arguments[1]
3131

32-
if prefix
33-
raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{prefix.inspect}" unless prefix.is_a?(String)
34-
end
32+
raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{prefix.inspect}" if prefix && !prefix.is_a?(String)
3533

3634
result = if enumerable.is_a?(Array)
3735
# Turn everything into string same as join would do ...

lib/puppet/parser/functions/pw_hash.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
'bcrypt' => { prefix: '2b', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} },
5555
'bcrypt-a' => { prefix: '2a', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} },
5656
'bcrypt-x' => { prefix: '2x', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} },
57-
'bcrypt-y' => { prefix: '2y', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} },
57+
'bcrypt-y' => { prefix: '2y', salt: %r{^(0[4-9]|[12][0-9]|3[01])\$[./A-Za-z0-9]{22}} }
5858
}
5959

6060
raise ArgumentError, 'pw_hash(): first argument must be a string' unless args[0].is_a?(String) || args[0].nil?

lib/puppet/parser/functions/str2saltedpbkdf2.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ module Puppet::Parser::Functions
6262
hash = OpenSSL::PKCS5.pbkdf2_hmac(password, salt, iterations, keylen, digest)
6363

6464
{
65-
'password_hex' => hash.unpack('H*').first,
66-
'salt_hex' => salt.unpack('H*').first,
67-
'iterations' => iterations,
65+
'password_hex' => hash.unpack1('H*'),
66+
'salt_hex' => salt.unpack1('H*'),
67+
'iterations' => iterations
6868
}
6969
end
7070
end

lib/puppet/parser/functions/str2saltedsha512.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module Puppet::Parser::Functions
2929
seedint = rand((2**31) - 1)
3030
seedstring = Array(seedint).pack('L')
3131
saltedpass = Digest::SHA512.digest(seedstring + password)
32-
(seedstring + saltedpass).unpack('H*')[0]
32+
(seedstring + saltedpass).unpack1('H*')
3333
end
3434
end
3535

lib/puppet/parser/functions/suffix.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ module Puppet::Parser::Functions
3333

3434
suffix = arguments[1] if arguments[1]
3535

36-
if suffix
37-
raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}" unless suffix.is_a? String
38-
end
36+
raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}" if suffix && !(suffix.is_a? String)
3937

4038
result = if enumerable.is_a?(Array)
4139
# Turn everything into string same as join would do ...

lib/puppet/type/file_line.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ def retrieve
188188
raise(Puppet::Error, 'multiple must be true when replace_all_matches_not_matching_line is true') if self[:replace_all_matches_not_matching_line].to_s == 'true' && self[:multiple].to_s == 'false'
189189
raise(Puppet::Error, 'replace must be true when replace_all_matches_not_matching_line is true') if self[:replace_all_matches_not_matching_line].to_s == 'true' && self[:replace].to_s == 'false'
190190

191-
unless self[:line]
192-
raise(Puppet::Error, 'line is a required attribute') unless (self[:ensure].to_s == 'absent') && (self[:match_for_absence].to_s == 'true') && self[:match]
193-
end
191+
raise(Puppet::Error, 'line is a required attribute') if !self[:line] && !((self[:ensure].to_s == 'absent') && (self[:match_for_absence].to_s == 'true') && self[:match])
194192
raise(Puppet::Error, 'path is a required attribute') unless self[:path]
195193
end
196194
end

spec/classes/manage_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
'file' => {
2525
'/etc/motd.d/hello' => {
2626
'content' => 'I say Hi',
27-
'notify' => 'Service[sshd]',
27+
'notify' => 'Service[sshd]'
2828
}
2929
},
3030
'package' => {
3131
'example' => {
3232
'ensure' => 'installed',
33-
'subscribe' => ['Service[sshd]', 'File[/etc/motd.d]'],
33+
'subscribe' => ['Service[sshd]', 'File[/etc/motd.d]']
3434
}
3535
}
3636
}

spec/functions/has_interface_with_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
'network' => '127.0.0.0',
4343
'network6' => '::1',
4444
'scope6' => 'host'
45-
},
45+
}
4646
}
4747
}
4848
}
@@ -129,8 +129,8 @@
129129
'network' => '127.0.0.0',
130130
'network6' => '::1'
131131
}
132-
},
133-
},
132+
}
133+
}
134134
}
135135
end
136136

spec/functions/has_ip_address_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
interfaces: 'eth0,lo',
1414
ipaddress: '10.0.0.1',
1515
ipaddress_lo: '127.0.0.1',
16-
ipaddress_eth0: '10.0.0.1',
16+
ipaddress_eth0: '10.0.0.1'
1717
}
1818
end
1919

spec/functions/has_ip_network_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{
1313
interfaces: 'eth0,lo',
1414
network_lo: '127.0.0.0',
15-
network_eth0: '10.0.0.0',
15+
network_eth0: '10.0.0.0'
1616
}
1717
end
1818

spec/functions/os_version_gte_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{
99
os: {
1010
name: 'Debian',
11-
release: { major: '9' },
11+
release: { major: '9' }
1212
}
1313
}
1414
end
@@ -26,7 +26,7 @@
2626
{
2727
os: {
2828
name: 'Ubuntu',
29-
release: { major: '16.04' },
29+
release: { major: '16.04' }
3030
}
3131
}
3232
end
@@ -45,7 +45,7 @@
4545
{
4646
os: {
4747
name: 'Ubuntu',
48-
release: { major: '16.04' },
48+
release: { major: '16.04' }
4949
}
5050
}
5151
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
default_facts = {
1515
puppetversion: Puppet.version,
16-
facterversion: Facter.version,
16+
facterversion: Facter.version
1717
}
1818

1919
default_fact_files = [

spec/unit/facter/root_home_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
end
1515

1616
context 'when non-Windows', if: Facter.value(:kernel) != 'Windows' do
17-
let(:expected) { Facter.value(:kernel) == 'Darwin' ? '/var/root' : '/root' }
17+
let(:expected) { (Facter.value(:kernel) == 'Darwin') ? '/var/root' : '/root' }
1818

1919
it { expect(subject.value).to eq(expected) }
2020
end

spec/unit/puppet/provider/file_line/ruby_spec.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Puppet::Type::File_line.new({
2121
name: 'foo',
2222
path: tmpfile,
23-
line: 'foo',
23+
line: 'foo'
2424
}.merge(params))
2525
end
2626
let :provider do
@@ -115,7 +115,7 @@
115115
let(:params) do
116116
{
117117
append_on_no_match: false,
118-
match: '^foo1$',
118+
match: '^foo1$'
119119
}
120120
end
121121

@@ -146,7 +146,7 @@
146146
let(:params) do
147147
{
148148
replace_all_matches_not_matching_line: true,
149-
replace: false,
149+
replace: false
150150
}
151151
end
152152

@@ -160,7 +160,7 @@
160160
{
161161
replace_all_matches_not_matching_line: true,
162162
match: '^foo',
163-
multiple: true,
163+
multiple: true
164164
}
165165
end
166166
let(:content) { "foo\nfoo bar\nbar\nfoo baz" }
@@ -180,7 +180,7 @@
180180
{
181181
replace_all_matches_not_matching_line: true,
182182
match: '^foo',
183-
multiple: true,
183+
multiple: true
184184
}
185185
end
186186
let(:content) { "foo\nfoo\nbar" }
@@ -195,7 +195,7 @@
195195
{
196196
replace_all_matches_not_matching_line: true,
197197
match: '^bar',
198-
multiple: true,
198+
multiple: true
199199
}
200200
end
201201
let(:content) { "foo\nfoo bar\nbar\nbar baz" }
@@ -215,7 +215,7 @@
215215
{
216216
replace_all_matches_not_matching_line: true,
217217
match: '^bar',
218-
multiple: true,
218+
multiple: true
219219
}
220220
end
221221
let(:content) { "foo\nfoo\nbar\nbar baz" }
@@ -236,7 +236,7 @@
236236
{
237237
replace_all_matches_not_matching_line: true,
238238
match: '^bar',
239-
multiple: true,
239+
multiple: true
240240
}
241241
end
242242
let(:content) { "foo\nfoo bar" }
@@ -251,7 +251,7 @@
251251
{
252252
replace_all_matches_not_matching_line: true,
253253
match: '^bar',
254-
multiple: true,
254+
multiple: true
255255
}
256256
end
257257
let(:content) { 'foo bar' }

spec/unit/puppet/provider/file_line/ruby_spec_alter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Puppet::Type::File_line.new({
2121
name: 'foo',
2222
path: tmpfile,
23-
line: 'foo',
23+
line: 'foo'
2424
}.merge(params))
2525
end
2626
let :provider do
@@ -37,7 +37,7 @@
3737
{
3838
line: 'foo = bar',
3939
match: '^foo\s*=.*$',
40-
replace: false,
40+
replace: false
4141
}
4242
end
4343
let(:content) { "foo1\nfoo=blah\nfoo2\nfoo3" }

0 commit comments

Comments
 (0)