Skip to content

Commit e30f3b0

Browse files
committed
(PUP-11993) Style/OrAssignment
This commit enables the Style/OrAssignment cop and fixes 9 autocorrectable offenses.
1 parent 2fa6252 commit e30f3b0

File tree

9 files changed

+9
-23
lines changed

9 files changed

+9
-23
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -640,18 +640,6 @@ Style/NumericPredicate:
640640
Style/OptionalBooleanParameter:
641641
Enabled: false
642642

643-
# This cop supports safe auto-correction (--auto-correct).
644-
Style/OrAssignment:
645-
Exclude:
646-
- 'lib/puppet/application/lookup.rb'
647-
- 'lib/puppet/file_system/windows.rb'
648-
- 'lib/puppet/pops/parser/lexer2.rb'
649-
- 'lib/puppet/pops/types/types.rb'
650-
- 'lib/puppet/provider/user/directoryservice.rb'
651-
- 'lib/puppet/ssl/base.rb'
652-
- 'lib/puppet/util/errors.rb'
653-
- 'util/rspec_grouper'
654-
655643
# This cop supports safe auto-correction (--auto-correct).
656644
Style/ParallelAssignment:
657645
Exclude:

lib/puppet/application/lookup.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def generate_scope
354354
given_facts = Puppet::Util::Yaml.safe_load_file(fact_file)
355355
else
356356
given_facts = Puppet::Util::Json.load_file_if_valid(fact_file)
357-
given_facts = Puppet::Util::Yaml.safe_load_file_if_valid(fact_file) unless given_facts
357+
given_facts ||= Puppet::Util::Yaml.safe_load_file_if_valid(fact_file)
358358
end
359359

360360
unless given_facts.instance_of?(Hash)

lib/puppet/file_system/windows.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def replace_file(path, mode = nil)
133133
end
134134

135135
current_sid = Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_user_name)
136-
current_sid = Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_sam_compatible_user_name) unless current_sid
136+
current_sid ||= Puppet::Util::Windows::SID.name_to_sid(Puppet::Util::Windows::ADSI::User.current_sam_compatible_user_name)
137137

138138
dacl = case mode
139139
when 0o644

lib/puppet/pops/parser/lexer2.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def initialize
526526
end
527527
end
528528
scn.pos = before
529-
invalid_number = scn.peek(after - before) unless invalid_number
529+
invalid_number ||= scn.peek(after - before)
530530
end
531531
assert_numeric(invalid_number, before)
532532
scn.pos = before + 1

lib/puppet/pops/types/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ def alter_type_array(types, method, *method_args)
400400
modified = false
401401
modified_types = types.map do |t|
402402
t_mod = t.send(method, *method_args)
403-
modified = !t.equal?(t_mod) unless modified
403+
modified ||= !t.equal?(t_mod)
404404
t_mod
405405
end
406406
if modified

lib/puppet/provider/user/directoryservice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ def set_salted_sha512(users_plist, shadow_hash_data, value)
661661
# the user's plist itself, and the shadow_hash_data hash containing the
662662
# existing PBKDF2 values.
663663
def set_salted_pbkdf2(users_plist, shadow_hash_data, field, value)
664-
shadow_hash_data = Hash.new unless shadow_hash_data
664+
shadow_hash_data ||= Hash.new
665665
shadow_hash_data['SALTED-SHA512-PBKDF2'] = Hash.new unless shadow_hash_data['SALTED-SHA512-PBKDF2']
666666
case field
667667
when 'salt', 'entropy'

lib/puppet/ssl/base.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ def fingerprint(md = :SHA256)
119119
end
120120

121121
def digest(algorithm = nil)
122-
unless algorithm
123-
algorithm = digest_algorithm
124-
end
122+
algorithm ||= digest_algorithm
125123

126124
Puppet::SSL::Digest.new(algorithm, content.to_der)
127125
end

lib/puppet/util/errors.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def self.error_location_with_space(file, line = nil, column = nil)
8787
def self.error_location_with_unknowns(file, line)
8888
file = nil if (file.is_a?(String) && file.empty?)
8989
line = nil if (line.is_a?(String) && line.empty?)
90-
file = _('unknown') unless file
91-
line = _('unknown') unless line
90+
file ||= _('unknown')
91+
line ||= _('unknown')
9292
error_location(file, line)
9393
end
9494

util/rspec_grouper

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module Parallel
4242
group = nil
4343
example_count = 0
4444
@files.each do |file, count|
45-
group = [] unless group
45+
group ||= []
4646
group << file
4747
next unless (example_count += count) > group_size
4848

0 commit comments

Comments
 (0)