Skip to content

Commit

Permalink
(PUP-11993) Style/RedundantAssignment
Browse files Browse the repository at this point in the history
This commit enables the Style/RedundantAssignment cop and fixes
64 autocorrectable offenses.
  • Loading branch information
AriaXLi committed Feb 26, 2024
1 parent d7a5577 commit ef5fa24
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 60 deletions.
19 changes: 0 additions & 19 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -646,25 +646,6 @@ Style/OptionalBooleanParameter:
Style/PreferredHashMethods:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
Style/RedundantAssignment:
Exclude:
- 'lib/puppet/file_serving/mount/locales.rb'
- 'lib/puppet/file_serving/mount/pluginfacts.rb'
- 'lib/puppet/file_serving/mount/plugins.rb'
- 'lib/puppet/parameter.rb'
- 'lib/puppet/parser/ast/pops_bridge.rb'
- 'lib/puppet/pops/model/factory.rb'
- 'lib/puppet/pops/parser/parser_support.rb'
- 'lib/puppet/provider/nameservice/directoryservice.rb'
- 'lib/puppet/provider/nameservice/objectadd.rb'
- 'lib/puppet/provider/nameservice/pw.rb'
- 'lib/puppet/settings.rb'
- 'lib/puppet/type.rb'
- 'lib/puppet/type/file/ensure.rb'
- 'lib/puppet/util.rb'
- 'lib/puppet/util/execution.rb'

# This cop supports safe auto-correction (--auto-correct).
Style/RedundantBegin:
Enabled: false
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/file_serving/mount/locales.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def find(relative_path, request)
mod = request.environment.modules.find { |m| m.locale(relative_path) }
return nil unless mod

path = mod.locale(relative_path)

path
mod.locale(relative_path)
end

def search(relative_path, request)
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/file_serving/mount/pluginfacts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def find(relative_path, request)
mod = request.environment.modules.find { |m| m.pluginfact(relative_path) }
return nil unless mod

path = mod.pluginfact(relative_path)

path
mod.pluginfact(relative_path)
end

def search(relative_path, request)
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/file_serving/mount/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def find(relative_path, request)
mod = request.environment.modules.find { |m| m.plugin(relative_path) }
return nil unless mod

path = mod.plugin(relative_path)

path
mod.plugin(relative_path)
end

def search(relative_path, request)
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parameter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,7 @@ def name
#
def noop
@noop ||= false
tmp = @noop || self.resource.noop || Puppet[:noop] || false
tmp
@noop || self.resource.noop || Puppet[:noop] || false
end

# Returns an array of strings representing the containment hierarchy
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/ast/pops_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,14 @@ def create_type_map(definition)

# Obtains the scope or issues a warning if :global_scope is not bound
def obtain_scope
scope = Puppet.lookup(:global_scope) do
Puppet.lookup(:global_scope) do
# This occurs when testing and when applying a catalog (there is no scope available then), and
# when running tests that run a partial setup.
# This is bad if the logic is trying to compile, but a warning can not be issues since it is a normal
# use case that there is no scope when requesting the type in order to just get the parameters.
Puppet.debug { _("Instantiating Resource with type checked parameters - scope is missing, skipping type checking.") }
nil
end
scope
end

# Produces a hash with data for Definition and HostClass
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/pops/model/factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1052,8 +1052,7 @@ def self.transform_resource_wo_title(left, attribute_ops, lbrace_token, rbrace_t
end
a_hash = HASH(keyed_entries)
a_hash.record_position(left[KEY_LOCATOR], lbrace_token, rbrace_token)
result = block_or_expression(transform_calls([left, a_hash]))
result
block_or_expression(transform_calls([left, a_hash]))
end

def interpolate_Factory(c)
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/pops/parser/parser_support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ def create_empty_program
_, token = @lexer.emit_completed([:NOOP, '', 0], locator.string.bytesize)
loc(no_op, token)
# Program with a Noop
program = Factory.PROGRAM(no_op, [], locator)
program
Factory.PROGRAM(no_op, [], locator)
end

# Performs the parsing and returns the resulting model.
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/nameservice/directoryservice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def self.get_password(guid, username)
# string. The password_hash provided as a resource attribute is a
# hex value. We need to convert the Base64 encoded string to a
# hex value and provide it back to Puppet.
password_hash = converted_hash_plist['SALTED-SHA512'].unpack("H*")[0]
password_hash
converted_hash_plist['SALTED-SHA512'].unpack("H*")[0]

end
end
end
Expand Down
6 changes: 2 additions & 4 deletions lib/puppet/provider/nameservice/objectadd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ def flag(name)
end

def posixmethod(name)
name = name.intern if name.is_a? String
method = self.class.option(name, :method) || name

method
name = name.intern if name.is_a? String
self.class.option(name, :method) || name
end
end
end
3 changes: 1 addition & 2 deletions lib/puppet/provider/nameservice/pw.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ def deletecmd
end

def modifycmd(param, value)
cmd = [
[
command(:pw),
"#{@resource.class.name}mod",
@resource[:name],
flag(param),
munge(param, value)
]
cmd
end
end
end
4 changes: 1 addition & 3 deletions lib/puppet/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,7 @@ def newsetting(hash)
klass = StringSetting
end
hash[:settings] = self
setting = klass.new(hash)

setting
klass.new(hash)
end

# This has to be private, because it doesn't add the settings to @config
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,7 @@ def self.provide(name, options = {}, &block)

self.providify

provider = genclass(
genclass(
name,
:parent => parent,
:hash => provider_hash,
Expand All @@ -1827,8 +1827,6 @@ def self.provide(name, options = {}, &block)
:extend => feature_module,
:attributes => options
)

provider
end

# Ensures there is a `:provider` parameter defined.
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/type/file/ensure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ def sync
return :file_removed
end

event = super

event
super
end
end
end
7 changes: 2 additions & 5 deletions lib/puppet/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def uri_unescape(str)
module_function :uri_unescape

def safe_posix_fork(stdin = $stdin, stdout = $stdout, stderr = $stderr, &block)
child_pid = Kernel.fork do
Kernel.fork do
STDIN.reopen(stdin)
STDOUT.reopen(stdout)
STDERR.reopen(stderr)
Expand All @@ -491,7 +491,6 @@ def safe_posix_fork(stdin = $stdin, stdout = $stdout, stderr = $stderr, &block)

block.call if block
end
child_pid
end
module_function :safe_posix_fork

Expand All @@ -507,11 +506,9 @@ def symbolizehash(hash)

# Just benchmark, with no logging.
def thinmark
seconds = Benchmark.realtime {
Benchmark.realtime {
yield
}

seconds
end

module_function :thinmark
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/util/execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class << self
# @api private
#
def self.execute_posix(command, options, stdin, stdout, stderr)
child_pid = Puppet::Util.safe_posix_fork(stdin, stdout, stderr) do
Puppet::Util.safe_posix_fork(stdin, stdout, stderr) do
# We can't just call Array(command), and rely on it returning
# things like ['foo'], when passed ['foo'], because
# Array(command) will call command.to_a internally, which when
Expand Down Expand Up @@ -371,7 +371,6 @@ def self.execute_posix(command, options, stdin, stdout, stderr)
exit!(1)
end
end
child_pid
end
private_class_method :execute_posix

Expand Down

0 comments on commit ef5fa24

Please sign in to comment.