Skip to content

Commit 0e3e5b1

Browse files
committed
(CONT-801) Autocorrect unsafe group 2
1 parent 2d78851 commit 0e3e5b1

File tree

9 files changed

+23
-57
lines changed

9 files changed

+23
-57
lines changed

.rubocop_todo.yml

Lines changed: 9 additions & 45 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-05-17 10:40:49 UTC using RuboCop version 1.48.1.
3+
# on 2023-05-18 13:42:01 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
@@ -41,28 +41,28 @@ Lint/SuppressedException:
4141
- 'lib/puppet/functions/merge.rb'
4242
- 'lib/puppet/parser/functions/has_interface_with.rb'
4343

44-
# Offense count: 6
44+
# Offense count: 5
4545
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
4646
Metrics/AbcSize:
4747
Max: 44
4848

49-
# Offense count: 19
49+
# Offense count: 18
5050
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
5151
# AllowedMethods: refine
5252
Metrics/BlockLength:
53-
Max: 152
53+
Max: 150
5454

55-
# Offense count: 5
55+
# Offense count: 4
5656
# Configuration parameters: AllowedMethods, AllowedPatterns.
5757
Metrics/CyclomaticComplexity:
5858
Max: 15
5959

60-
# Offense count: 9
60+
# Offense count: 8
6161
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
6262
Metrics/MethodLength:
6363
Max: 35
6464

65-
# Offense count: 4
65+
# Offense count: 3
6666
# Configuration parameters: AllowedMethods, AllowedPatterns.
6767
Metrics/PerceivedComplexity:
6868
Max: 19
@@ -175,29 +175,13 @@ RSpec/StubbedMock:
175175
- 'spec/functions/reverse_spec.rb'
176176
- 'spec/functions/squeeze_spec.rb'
177177

178-
# Offense count: 2
179-
# This cop supports unsafe autocorrection (--autocorrect-all).
180-
Style/CollectionCompact:
181-
Exclude:
182-
- 'lib/puppet/functions/to_json_pretty.rb'
183-
184-
# Offense count: 5
178+
# Offense count: 1
185179
# This cop supports unsafe autocorrection (--autocorrect-all).
186180
# Configuration parameters: EnforcedStyle.
187181
# SupportedStyles: always, always_true, never
188182
Style/FrozenStringLiteralComment:
189183
Exclude:
190-
- 'lib/puppet_x/stdlib.rb'
191184
- 'lib/puppet_x/stdlib/toml_dumper.rb'
192-
- 'spec/functions/stdlib_deferrable_epp_spec.rb'
193-
- 'spec/type_aliases/http__method_spec.rb'
194-
- 'spec/type_aliases/http__status_spec.rb'
195-
196-
# Offense count: 1
197-
# This cop supports unsafe autocorrection (--autocorrect-all).
198-
Style/HashTransformKeys:
199-
Exclude:
200-
- 'lib/puppet/functions/to_json_pretty.rb'
201185

202186
# Offense count: 4
203187
# This cop supports unsafe autocorrection (--autocorrect-all).
@@ -210,11 +194,10 @@ Style/IfWithBooleanLiteralBranches:
210194
- 'lib/puppet/parser/functions/shuffle.rb'
211195
- 'lib/puppet/provider/file_line/ruby.rb'
212196

213-
# Offense count: 3
197+
# Offense count: 2
214198
# This cop supports unsafe autocorrection (--autocorrect-all).
215199
Style/MapToHash:
216200
Exclude:
217-
- 'lib/puppet/functions/to_json_pretty.rb'
218201
- 'lib/puppet/parser/functions/prefix.rb'
219202
- 'lib/puppet/parser/functions/suffix.rb'
220203

@@ -241,25 +224,6 @@ Style/OptionalBooleanParameter:
241224
- 'lib/puppet/functions/to_json_pretty.rb'
242225
- 'lib/puppet_x/stdlib/toml_dumper.rb'
243226

244-
# Offense count: 2
245-
# This cop supports unsafe autocorrection (--autocorrect-all).
246-
# Configuration parameters: Methods.
247-
Style/RedundantArgument:
248-
Exclude:
249-
- 'lib/puppet/provider/file_line/ruby.rb'
250-
251-
# Offense count: 1
252-
# This cop supports unsafe autocorrection (--autocorrect-all).
253-
Style/SelectByRegexp:
254-
Exclude:
255-
- 'lib/puppet/parser/functions/reject.rb'
256-
257-
# Offense count: 1
258-
# This cop supports unsafe autocorrection (--autocorrect-all).
259-
Style/SlicingWithRange:
260-
Exclude:
261-
- 'spec/functions/validate_x509_rsa_key_pair_spec.rb'
262-
263227
# Offense count: 2
264228
# This cop supports unsafe autocorrection (--autocorrect-all).
265229
Style/StringChars:

lib/puppet/functions/to_json_pretty.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,12 @@ def to_json_pretty(data, skip_undef = false, opts = nil)
6161
# It's not possible to make an abstract type that can be either a boolean
6262
# false or an integer, so we use -1 as the falsey value
6363
if opts
64-
opts = opts.map { |k, v| [k.to_sym, v] }.to_h
64+
opts = opts.transform_keys { |k| k.to_sym }
6565

6666
opts[:max_nesting] = false if opts[:max_nesting] == -1
6767
end
6868

69-
if skip_undef
70-
if data.is_a? Array
71-
data = data.reject { |value| value.nil? }
72-
elsif data.is_a? Hash
73-
data = data.reject { |_, value| value.nil? }
74-
end
75-
end
69+
data = data.compact if skip_undef && (data.is_a?(Array) || Hash)
7670
# Call ::JSON to ensure it references the JSON library from Ruby's standard library
7771
# instead of a random JSON namespace that might be in scope due to user code.
7872
JSON.pretty_generate(data, opts) << "\n"

lib/puppet/parser/functions/reject.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module Puppet::Parser::Functions
3131
ary = args[0]
3232
pattern = Regexp.new(args[1])
3333

34-
ary.reject { |e| e =~ pattern }
34+
ary.grep_v(pattern)
3535
end
3636
end
3737

lib/puppet/provider/file_line/ruby.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ def handle_destroy_with_match
152152
raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'" if match_count > 1 && resource[:multiple].to_s != 'true'
153153

154154
local_lines = lines
155-
File.write(resource[:path], local_lines.reject { |line| match_regex.match(line) }.join(''))
155+
File.write(resource[:path], local_lines.reject { |line| match_regex.match(line) }.join)
156156
end
157157

158158
def handle_destroy_line
159159
local_lines = lines
160-
File.write(resource[:path], local_lines.reject { |line| line.chomp == resource[:line] }.join(''))
160+
File.write(resource[:path], local_lines.reject { |line| line.chomp == resource[:line] }.join)
161161
end
162162

163163
def handle_append_line

lib/puppet_x/stdlib.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'puppet_x'
24

35
# common PuppetX::Stdlib module definition

spec/functions/stdlib_deferrable_epp_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
describe 'stdlib::deferrable_epp' do

spec/functions/validate_x509_rsa_key_pair_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ def truncate_middle(string)
174174
start_pos = middle - (chars_to_truncate / 2)
175175
end_pos = middle + (chars_to_truncate / 2)
176176

177-
string[0..start_pos] + string[end_pos..-1]
177+
string[0..start_pos] + string[end_pos..]
178178
end
179179
end

spec/type_aliases/http__method_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
describe 'Stdlib::Http::Method' do

spec/type_aliases/http__status_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'spec_helper'
24

35
describe 'Stdlib::Http::Status' do

0 commit comments

Comments
 (0)