Skip to content

Commit 131c4ab

Browse files
committed
(PUP-11993) Style/SelfAssignment
This commit enables the Style/SelfAssignment cop and fixes 13 autocorrectable fixes.
1 parent 62b1cd6 commit 131c4ab

File tree

10 files changed

+13
-26
lines changed

10 files changed

+13
-26
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -664,19 +664,6 @@ Style/RescueStandardError:
664664
Style/SafeNavigation:
665665
Enabled: false
666666

667-
# This cop supports safe auto-correction (--auto-correct).
668-
Style/SelfAssignment:
669-
Exclude:
670-
- 'lib/puppet/pops/evaluator/access_operator.rb'
671-
- 'lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb'
672-
- 'lib/puppet/pops/evaluator/epp_evaluator.rb'
673-
- 'lib/puppet/pops/parser/epp_parser.rb'
674-
- 'lib/puppet/pops/parser/parser_support.rb'
675-
- 'lib/puppet/pops/time/timestamp.rb'
676-
- 'lib/puppet/pops/types/recursion_guard.rb'
677-
- 'lib/puppet/property/ordered_list.rb'
678-
- 'lib/puppet/util/autoload.rb'
679-
680667
# This cop supports safe auto-correction (--auto-correct).
681668
# Configuration parameters: AllowAsExpressionSeparator.
682669
Style/Semicolon:

lib/puppet/pops/evaluator/access_operator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def access_String(o, scope, keys)
6767
k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
6868
# if k1 is outside, adjust to first position, and adjust length
6969
if k1 < 0
70-
k2 = k2 + k1
70+
k2 += k1
7171
k1 = 0
7272
end
7373
o[k1, k2]
@@ -116,7 +116,7 @@ def access_Array(o, scope, keys)
116116
k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
117117
# if k1 is outside, adjust to first position, and adjust length
118118
if k1 < 0
119-
k2 = k2 + k1
119+
k2 += k1
120120
k1 = 0
121121
end
122122
# Help ruby always return empty array when asking for a sub array

lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def collect
2525
resolved << ref
2626
end
2727

28-
@resources = @resources - resolved
28+
@resources -= resolved
2929

3030
@scope.compiler.delete_collection(self) if @resources.empty?
3131

lib/puppet/pops/evaluator/epp_evaluator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def self.epp(scope, file, env_name, template_args = nil)
3131

3232
unless Puppet::FileSystem.exist?(file)
3333
unless file =~ /\.epp$/
34-
file = file + ".epp"
34+
file += ".epp"
3535
end
3636
end
3737

lib/puppet/pops/parser/epp_parser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def initvars
1414
def parse_file(file)
1515
unless FileTest.exist?(file)
1616
unless file =~ /\.epp$/
17-
file = file + ".epp"
17+
file += ".epp"
1818
end
1919
end
2020
@lexer.file = file

lib/puppet/pops/parser/parser_support.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def error(semantic, message)
7777
def parse_file(file)
7878
unless Puppet::FileSystem.exist?(file)
7979
unless file =~ /\.pp$/
80-
file = file + ".pp"
80+
file += ".pp"
8181
end
8282
end
8383
@lexer.file = file

lib/puppet/pops/time/timestamp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def self.parse(str, format = :default, timezone = nil)
107107
fraction = parsed[:sec_fraction]
108108

109109
# Convert msec rational found in _strptime hash to usec
110-
fraction = fraction * 1_000_000 unless fraction.nil?
110+
fraction *= 1_000_000 unless fraction.nil?
111111

112112
# Create the Time instance and adjust for timezone
113113
parsed_time = ::Time.utc(parsed[:year], parsed[:mon], parsed[:mday], parsed[:hour], parsed[:min], parsed[:sec], fraction)

lib/puppet/pops/types/recursion_guard.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def recursive_that?(instance)
4646
def with_this(instance)
4747
if (@state & SELF_RECURSION_IN_THIS) == 0
4848
tc = this_count
49-
@state = @state | SELF_RECURSION_IN_THIS if this_put(instance)
49+
@state |= SELF_RECURSION_IN_THIS if this_put(instance)
5050
if tc < this_count
5151
# recursive state detected
5252
result = yield(@state)
@@ -66,7 +66,7 @@ def with_this(instance)
6666
def with_that(instance)
6767
if (@state & SELF_RECURSION_IN_THAT) == 0
6868
tc = that_count
69-
@state = @state | SELF_RECURSION_IN_THAT if that_put(instance)
69+
@state |= SELF_RECURSION_IN_THAT if that_put(instance)
7070
if tc < that_count
7171
# recursive state detected
7272
result = yield(@state)
@@ -85,7 +85,7 @@ def with_that(instance)
8585
# @return [Integer] the resulting state
8686
def add_this(instance)
8787
if (@state & SELF_RECURSION_IN_THIS) == 0
88-
@state = @state | SELF_RECURSION_IN_THIS if this_put(instance)
88+
@state |= SELF_RECURSION_IN_THIS if this_put(instance)
8989
end
9090
@state
9191
end
@@ -95,7 +95,7 @@ def add_this(instance)
9595
# @return [Integer] the resulting state
9696
def add_that(instance)
9797
if (@state & SELF_RECURSION_IN_THAT) == 0
98-
@state = @state | SELF_RECURSION_IN_THAT if that_put(instance)
98+
@state |= SELF_RECURSION_IN_THAT if that_put(instance)
9999
end
100100
@state
101101
end

lib/puppet/property/ordered_list.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def add_should_with_current(should, current)
1717
# tricky trick
1818
# Preserve all the current items in the list
1919
# but move them to the back of the line
20-
should = should + (current - should)
20+
should += (current - should)
2121
end
2222
should
2323
end

lib/puppet/util/autoload.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def reload_changed(env)
111111
# returns nil if no file is found
112112
# @api private
113113
def get_file(name, env)
114-
name = name + '.rb' unless name =~ /\.rb$/
114+
name += '.rb' unless name =~ /\.rb$/
115115
path = search_directories(env).find { |dir| Puppet::FileSystem.exist?(File.join(dir, name)) }
116116
path and File.join(path, name)
117117
end

0 commit comments

Comments
 (0)