Skip to content

Commit

Permalink
[Fix #11914] Fix an incorrect examples for `Style/ClassEqualityCompar…
Browse files Browse the repository at this point in the history
…ison`

Fixes #11914.

This PR fixes an incorrect examples for `Style/ClassEqualityComparison`.

The original `IgnoredMethods` (later renamed `AllowedMethods`) was introduced
by #8833. OTOH, #10809 seems to have mis-documented #8833.
  • Loading branch information
koic authored and bbatsov committed Jun 4, 2023
1 parent 728457d commit ab4b73c
Showing 1 changed file with 17 additions and 39 deletions.
56 changes: 17 additions & 39 deletions lib/rubocop/cop/style/class_equality_comparison.rb
Expand Up @@ -5,7 +5,7 @@ module Cop
module Style
# Enforces the use of `Object#instance_of?` instead of class comparison
# for equality.
# `==`, `equal?`, and `eql?` methods are allowed by default.
# `==`, `equal?`, and `eql?` custom method definitions are allowed by default.
# These are customizable with `AllowedMethods` option.
#
# @example
Expand All @@ -18,53 +18,31 @@ module Style
# # good
# var.instance_of?(Date)
#
# @example AllowedMethods: [] (default)
# @example AllowedMethods: ['==', 'equal?', 'eql?'] (default)
# # good
# var.instance_of?(Date)
#
# # bad
# var.class == Date
# var.class.equal?(Date)
# var.class.eql?(Date)
# var.class.name == 'Date'
# var.class.to_s == 'Date'
# var.class.inspect == 'Date'
# def ==(other)
# self.class == other.class && name == other.name
# end
#
# @example AllowedMethods: [`==`]
# # good
# var.instance_of?(Date)
# var.class == Date
# var.class.name == 'Date'
# var.class.to_s == 'Date'
# var.class.inspect == 'Date'
# def equal?(other)
# self.class.equal?(other.class) && name.equal?(other.name)
# end
#
# # bad
# var.class.equal?(Date)
# var.class.eql?(Date)
# def eql?(other)
# self.class.eql?(other.class) && name.eql?(other.name)
# end
#
# @example AllowedPatterns: [] (default)
# # good
# var.instance_of?(Date)
#
# # bad
# var.class == Date
# var.class.equal?(Date)
# var.class.eql?(Date)
# var.class.name == 'Date'
# var.class.to_s == 'Date'
# var.class.inspect == 'Date'
# def eq(other)
# self.class.eq(other.class) && name.eq(other.name)
# end
#
# @example AllowedPatterns: ['eq']
# # good
# var.instance_of?(Date)
# var.class.equal?(Date)
# var.class.eql?(Date)
#
# # bad
# var.class == Date
# var.class.name == 'Date'
# var.class.to_s == 'Date'
# var.class.inspect == 'Date'
# def eq(other)
# self.class.eq(other.class) && name.eq(other.name)
# end
#
class ClassEqualityComparison < Base
include RangeHelp
Expand Down

0 comments on commit ab4b73c

Please sign in to comment.