Skip to content

Commit eaca32a

Browse files
committed
(PUP-11993) Style/NilComparison
This commit enables the Style/NilComparison cop and fixes 14 autocorrectable offenses.
1 parent d460145 commit eaca32a

File tree

10 files changed

+12
-27
lines changed

10 files changed

+12
-27
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -629,21 +629,6 @@ Style/MultipleComparison:
629629
Style/MutableConstant:
630630
Enabled: false
631631

632-
# This cop supports safe auto-correction (--auto-correct).
633-
# Configuration parameters: EnforcedStyle.
634-
# SupportedStyles: predicate, comparison
635-
Style/NilComparison:
636-
Exclude:
637-
- 'lib/puppet/pops/types/type_factory.rb'
638-
- 'lib/puppet/pops/types/types.rb'
639-
- 'lib/puppet/provider/package/dnfmodule.rb'
640-
- 'lib/puppet/provider/package/nim.rb'
641-
- 'lib/puppet/provider/package/windows/exe_package.rb'
642-
- 'lib/puppet/provider/user/directoryservice.rb'
643-
- 'lib/puppet/type/file.rb'
644-
- 'lib/puppet/util/pidlock.rb'
645-
- 'lib/puppet/util/suidmanager.rb'
646-
647632
# This cop supports safe auto-correction (--auto-correct).
648633
# Configuration parameters: IncludeSemanticChanges.
649634
Style/NonNilCheck:

lib/puppet/pops/types/type_factory.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def self.type_alias(name = nil, expression = nil)
627627
# @param type_string [String] the string form of the type
628628
# @return [PTypeReferenceType] the type reference
629629
def self.type_reference(type_string = nil)
630-
type_string == nil ? PTypeReferenceType::DEFAULT : PTypeReferenceType.new(type_string)
630+
type_string.nil? ? PTypeReferenceType::DEFAULT : PTypeReferenceType.new(type_string)
631631
end
632632

633633
# Returns true if the given type t is of valid range parameter type (integer

lib/puppet/pops/types/types.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ def callable_with?(args, block = nil)
24382438
return false unless @param_types.instance?(args)
24392439

24402440
if @block_type.nil?
2441-
block == nil
2441+
block.nil?
24422442
else
24432443
@block_type.instance?(block)
24442444
end

lib/puppet/provider/package/dnfmodule.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def install
9595
# module has no default profile and no profile was requested, so just enable the stream
9696
# DNF versions prior to 4.2.8 do not need this workaround
9797
# see https://bugzilla.redhat.com/show_bug.cgi?id=1669527
98-
if @resource[:flavor] == nil && e.message =~ /^(?:missing|broken) groups or modules: #{Regexp.quote(args)}$/
98+
if @resource[:flavor].nil? && e.message =~ /^(?:missing|broken) groups or modules: #{Regexp.quote(args)}$/
9999
enable(args)
100100
else
101101
raise

lib/puppet/provider/package/nim.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def install(useversion = true)
9696
package_type, version = determine_latest_version(output, pkg)
9797
end
9898

99-
if (package_type == nil)
99+
if (package_type.nil?)
100100

101101
errmsg = if version_specified
102102
_("Unable to find package '%{package}' with version '%{version}' on lpp_source '%{source}'") %

lib/puppet/provider/package/windows/exe_package.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ def self.valid?(name, values)
4444
values['UninstallString'].length > 0 &&
4545
values['WindowsInstaller'] != 1 && # DWORD
4646
name !~ /^KB[0-9]{6}/ &&
47-
values['ParentKeyName'] == nil &&
48-
values['Security Update'] == nil &&
49-
values['Update Rollup'] == nil &&
50-
values['Hotfix'] == nil)
47+
values['ParentKeyName'].nil? &&
48+
values['Security Update'].nil? &&
49+
values['Update Rollup'].nil? &&
50+
values['Hotfix'].nil?)
5151
end
5252

5353
def initialize(name, version, uninstall_string)

lib/puppet/provider/user/directoryservice.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def self.get_salted_sha512_pbkdf2(field, embedded_binary_plist, user_name = "")
216216
case field
217217
when 'salt', 'entropy'
218218
value = embedded_binary_plist['SALTED-SHA512-PBKDF2'][field]
219-
if value == nil
219+
if value.nil?
220220
raise Puppet::Error, "Invalid #{field} given for user #{user_name}"
221221
end
222222

lib/puppet/type/file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ def retrieve
827827
[:use, :use_when_creating].include?(self[:source_permissions])
828828
# TRANSLATORS "source_permissions => ignore" should not be translated
829829
err_msg = _("Copying owner/mode/group from the source file on Windows is not supported; use source_permissions => ignore.")
830-
if self[:owner] == nil || self[:group] == nil || self[:mode] == nil
830+
if self[:owner].nil? || self[:group].nil? || self[:mode].nil?
831831
# Fail on Windows if source permissions are being used and the file resource
832832
# does not have mode owner, group, and mode all set (which would take precedence).
833833
self.fail err_msg

lib/puppet/util/pidlock.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def ps_argument_for_current_kernel
5959

6060
def clear_if_stale
6161
pid = lock_pid
62-
return @lockfile.unlock if pid == nil
62+
return @lockfile.unlock if pid.nil?
6363
return if Process.pid == pid
6464

6565
errors = [Errno::ESRCH]

lib/puppet/util/suidmanager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def convert_xid(type, id)
147147
raise ArgumentError, _("Invalid id type %{type}") % { type: type } unless map.include?(type)
148148

149149
ret = Puppet::Util.send(type, id)
150-
if ret == nil
150+
if ret.nil?
151151
raise Puppet::Error, _("Invalid %{klass}: %{id}") % { klass: map[type], id: id }
152152
end
153153

0 commit comments

Comments
 (0)