Skip to content

Commit

Permalink
(PUP-11993) Style/SelfAssignment
Browse files Browse the repository at this point in the history
This commit enables the Style/SelfAssignment cop and fixes 13
autocorrectable fixes.
  • Loading branch information
AriaXLi committed Mar 6, 2024
1 parent 62b1cd6 commit 131c4ab
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 26 deletions.
13 changes: 0 additions & 13 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -664,19 +664,6 @@ Style/RescueStandardError:
Style/SafeNavigation:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Style/SelfAssignment:
Exclude:
- 'lib/puppet/pops/evaluator/access_operator.rb'
- 'lib/puppet/pops/evaluator/collectors/fixed_set_collector.rb'
- 'lib/puppet/pops/evaluator/epp_evaluator.rb'
- 'lib/puppet/pops/parser/epp_parser.rb'
- 'lib/puppet/pops/parser/parser_support.rb'
- 'lib/puppet/pops/time/timestamp.rb'
- 'lib/puppet/pops/types/recursion_guard.rb'
- 'lib/puppet/property/ordered_list.rb'
- 'lib/puppet/util/autoload.rb'

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: AllowAsExpressionSeparator.
Style/Semicolon:
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/pops/evaluator/access_operator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def access_String(o, scope, keys)
k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
# if k1 is outside, adjust to first position, and adjust length
if k1 < 0
k2 = k2 + k1
k2 += k1
k1 = 0
end
o[k1, k2]
Expand Down Expand Up @@ -116,7 +116,7 @@ def access_Array(o, scope, keys)
k2 = k2 < 0 ? o.length - k1 + k2 + 1 : k2 # abs length (negative k2 is length from pos to end count)
# if k1 is outside, adjust to first position, and adjust length
if k1 < 0
k2 = k2 + k1
k2 += k1
k1 = 0
end
# Help ruby always return empty array when asking for a sub array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def collect
resolved << ref
end

@resources = @resources - resolved
@resources -= resolved

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

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/evaluator/epp_evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def self.epp(scope, file, env_name, template_args = nil)

unless Puppet::FileSystem.exist?(file)
unless file =~ /\.epp$/
file = file + ".epp"
file += ".epp"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/parser/epp_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initvars
def parse_file(file)
unless FileTest.exist?(file)
unless file =~ /\.epp$/
file = file + ".epp"
file += ".epp"
end
end
@lexer.file = file
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/parser/parser_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def error(semantic, message)
def parse_file(file)
unless Puppet::FileSystem.exist?(file)
unless file =~ /\.pp$/
file = file + ".pp"
file += ".pp"
end
end
@lexer.file = file
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/time/timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def self.parse(str, format = :default, timezone = nil)
fraction = parsed[:sec_fraction]

# Convert msec rational found in _strptime hash to usec
fraction = fraction * 1_000_000 unless fraction.nil?
fraction *= 1_000_000 unless fraction.nil?

# Create the Time instance and adjust for timezone
parsed_time = ::Time.utc(parsed[:year], parsed[:mon], parsed[:mday], parsed[:hour], parsed[:min], parsed[:sec], fraction)
Expand Down
8 changes: 4 additions & 4 deletions lib/puppet/pops/types/recursion_guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def recursive_that?(instance)
def with_this(instance)
if (@state & SELF_RECURSION_IN_THIS) == 0
tc = this_count
@state = @state | SELF_RECURSION_IN_THIS if this_put(instance)
@state |= SELF_RECURSION_IN_THIS if this_put(instance)
if tc < this_count
# recursive state detected
result = yield(@state)
Expand All @@ -66,7 +66,7 @@ def with_this(instance)
def with_that(instance)
if (@state & SELF_RECURSION_IN_THAT) == 0
tc = that_count
@state = @state | SELF_RECURSION_IN_THAT if that_put(instance)
@state |= SELF_RECURSION_IN_THAT if that_put(instance)
if tc < that_count
# recursive state detected
result = yield(@state)
Expand All @@ -85,7 +85,7 @@ def with_that(instance)
# @return [Integer] the resulting state
def add_this(instance)
if (@state & SELF_RECURSION_IN_THIS) == 0
@state = @state | SELF_RECURSION_IN_THIS if this_put(instance)
@state |= SELF_RECURSION_IN_THIS if this_put(instance)
end
@state
end
Expand All @@ -95,7 +95,7 @@ def add_this(instance)
# @return [Integer] the resulting state
def add_that(instance)
if (@state & SELF_RECURSION_IN_THAT) == 0
@state = @state | SELF_RECURSION_IN_THAT if that_put(instance)
@state |= SELF_RECURSION_IN_THAT if that_put(instance)
end
@state
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/property/ordered_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def add_should_with_current(should, current)
# tricky trick
# Preserve all the current items in the list
# but move them to the back of the line
should = should + (current - should)
should += (current - should)
end
should
end
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/autoload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def reload_changed(env)
# returns nil if no file is found
# @api private
def get_file(name, env)
name = name + '.rb' unless name =~ /\.rb$/
name += '.rb' unless name =~ /\.rb$/
path = search_directories(env).find { |dir| Puppet::FileSystem.exist?(File.join(dir, name)) }
path and File.join(path, name)
end
Expand Down

0 comments on commit 131c4ab

Please sign in to comment.