Skip to content

Commit 27609dd

Browse files
(PUP-11767) add Style/ClassCheck and ClassEqualityComparison checks
1 parent a20a869 commit 27609dd

20 files changed

+35
-29
lines changed

.rubocop.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,9 @@ Style/CaseEquality:
208208

209209
Style/CaseLikeIf:
210210
Enabled: true
211+
212+
Style/ClassCheck:
213+
Enabled: true
214+
215+
Style/ClassEqualityComparison:
216+
Enabled: true

lib/puppet/module_tool.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def self.username_and_modname_from(full_module_name)
4848
# @return [Pathname, nil] the root path of the module directory or nil if
4949
# we cannot find one
5050
def self.find_module_root(path)
51-
path = Pathname.new(path) if path.class == String
51+
path = Pathname.new(path) if path.instance_of?(String)
5252

5353
path.expand_path.ascend do |p|
5454
return p if is_module_root?(p)
@@ -63,7 +63,7 @@ def self.find_module_root(path)
6363
# @param path [Pathname, String] path to analyse
6464
# @return [Boolean] true if the path is a module root, false otherwise
6565
def self.is_module_root?(path)
66-
path = Pathname.new(path) if path.class == String
66+
path = Pathname.new(path) if path.instance_of?(String)
6767

6868
FileTest.file?(path + 'metadata.json')
6969
end

lib/puppet/parser/compiler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def evaluate_classes(classes, scope, lazy_evaluate = true)
240240
class_parameters = nil
241241
# if we are a param class, save the classes hash
242242
# and transform classes to be the keys
243-
if classes.class == Hash
243+
if classes.instance_of?(Hash)
244244
class_parameters = classes
245245
classes = classes.keys
246246
end
@@ -543,7 +543,7 @@ def initvars
543543
@resources = []
544544

545545
# Make sure any external node classes are in our class list
546-
if @node.classes.class == Hash
546+
if @node.classes.instance_of?(Hash)
547547
@catalog.add_class(*@node.classes.keys)
548548
else
549549
@catalog.add_class(*@node.classes)

lib/puppet/pops/evaluator/access_operator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def access_PNotUndefType(o, scope, keys)
378378
when String
379379
type = Types::TypeFactory.string(type)
380380
when Types::PAnyType
381-
type = nil if type.class == Types::PAnyType
381+
type = nil if type.instance_of?(Types::PAnyType)
382382
else
383383
fail(Issues::BAD_NOT_UNDEF_SLICE_TYPE, @semantic.keys[0], { :base_type => 'NotUndef-Type', :actual => type.class })
384384
end

lib/puppet/pops/evaluator/deferred_resolver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def mark_sensitive_parameters(r, k)
117117
private :mark_sensitive_parameters
118118

119119
def resolve(x)
120-
if x.class == @deferred_class
120+
if x.instance_of?(@deferred_class)
121121
resolve_future(x)
122122
elsif x.is_a?(Array)
123123
x.map { |v| resolve(v) }

lib/puppet/pops/types/p_binary_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def from_hash(hash)
225225
protected
226226

227227
def _assignable?(o, guard)
228-
o.class == self.class
228+
o.instance_of?(self.class)
229229
end
230230
end
231231
end

lib/puppet/pops/types/p_object_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def assert_override(parent_members)
170170
# @raises [Puppet::ParseError] if the assertion fails
171171
# @api private
172172
def assert_can_be_overridden(member)
173-
unless self.class == member.class
173+
unless self.instance_of?(member.class)
174174
raise Puppet::ParseError, _("%{member} attempts to override %{label}") % { member: member.label, label: label }
175175
end
176176
if @final && !(constant? && member.constant?)

lib/puppet/pops/types/p_sem_ver_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def to_array(component)
119119
protected
120120

121121
def _assignable?(o, guard)
122-
return false unless o.class == self.class
122+
return false unless o.instance_of?(self.class)
123123
return true if @ranges.empty?
124124
return false if o.ranges.empty?
125125

lib/puppet/pops/types/p_sensitive_type.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def from_sensitive(value)
7272
private
7373

7474
def _assignable?(o, guard)
75-
self.class == o.class && @type.assignable?(o.type, guard)
75+
self.instance_of?(o.class) && @type.assignable?(o.type, guard)
7676
end
7777

7878
DEFAULT = PSensitiveType.new

lib/puppet/pops/types/p_timespan_type.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(from, to = nil)
1717
# @return [Boolean] `true` if this range intersects with the other range
1818
# @api public
1919
def intersect?(o)
20-
self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from)
20+
self.instance_of?(o.class) && !(@to < o.numeric_from || o.numeric_to < @from)
2121
end
2222

2323
# Returns the lower bound of the numeric range or `nil` if no lower bound is set.
@@ -94,7 +94,7 @@ def merge(o)
9494
end
9595

9696
def _assignable?(o, guard)
97-
self.class == o.class && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to
97+
self.instance_of?(o.class) && numeric_from <= o.numeric_from && numeric_to >= o.numeric_to
9898
end
9999
end
100100

0 commit comments

Comments
 (0)