diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-03-24 14:30:00 +0200 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2019-03-24 14:30:00 +0200 |
commit | b85073f80833b4377ea92bfcfb93cb03a2773559 (patch) | |
tree | d6b27a3eab4e76b8cd4fb0c82327f9fc1e9b85ee /lib | |
parent | b938bddf0a0825ee3f61768bd95dc2d80c2714b7 (diff) | |
download | pry-b85073f80833b4377ea92bfcfb93cb03a2773559.tar.gz |
rubocop: fix offences of the Style/CaseEquality cop
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pry/color_printer.rb | 2 | ||||
-rw-r--r-- | lib/pry/command.rb | 2 | ||||
-rw-r--r-- | lib/pry/command_set.rb | 4 | ||||
-rw-r--r-- | lib/pry/commands/find_method.rb | 2 | ||||
-rw-r--r-- | lib/pry/commands/ls.rb | 2 | ||||
-rw-r--r-- | lib/pry/commands/ls/constants.rb | 2 | ||||
-rw-r--r-- | lib/pry/commands/ls/instance_vars.rb | 2 | ||||
-rw-r--r-- | lib/pry/commands/ls/interrogatable.rb | 2 | ||||
-rw-r--r-- | lib/pry/commands/show_source.rb | 2 | ||||
-rw-r--r-- | lib/pry/config.rb | 2 | ||||
-rw-r--r-- | lib/pry/config/behavior.rb | 12 | ||||
-rw-r--r-- | lib/pry/core_extensions.rb | 2 | ||||
-rw-r--r-- | lib/pry/exceptions.rb | 2 | ||||
-rw-r--r-- | lib/pry/helpers/base_helpers.rb | 2 | ||||
-rw-r--r-- | lib/pry/indent.rb | 2 | ||||
-rw-r--r-- | lib/pry/method.rb | 6 | ||||
-rw-r--r-- | lib/pry/pry_class.rb | 5 | ||||
-rw-r--r-- | lib/pry/pry_instance.rb | 6 | ||||
-rw-r--r-- | lib/pry/repl.rb | 2 | ||||
-rw-r--r-- | lib/pry/testable/evalable.rb | 2 | ||||
-rw-r--r-- | lib/pry/wrapped_module.rb | 6 |
21 files changed, 37 insertions, 32 deletions
diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb index 09c8f34c..4286adc2 100644 --- a/lib/pry/color_printer.rb +++ b/lib/pry/color_printer.rb @@ -34,7 +34,7 @@ class Pry end def pp(obj) - if String === obj + if obj.is_a?(String) # Avoid calling Ruby 2.4+ String#pretty_print that prints multiline # Strings prettier text(obj.inspect) diff --git a/lib/pry/command.rb b/lib/pry/command.rb index d10e252b..ff42efa6 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -86,7 +86,7 @@ class Pry argument_required: false, interpolate: true, shellwords: true, - listing: (String === match ? match : match.inspect), + listing: (match.is_a?(String) ? match : match.inspect), use_prefix: true, takes_block: false } diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index 441f624f..3d5164a5 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -325,7 +325,7 @@ class Pry return end - unless Class === command && command < Pry::Command + unless command.is_a?(Class) && command < Pry::Command raise TypeError, "command is not a subclass of Pry::Command" end @@ -397,7 +397,7 @@ class Pry command.new(context).complete(search) else keys = @commands.keys.select do |key| - String === key && key.start_with?(search) + key.is_a?(String) && key.start_with?(search) end keys.map { |key| key + " " } end diff --git a/lib/pry/commands/find_method.rb b/lib/pry/commands/find_method.rb index 6c760ca7..db5e6418 100644 --- a/lib/pry/commands/find_method.rb +++ b/lib/pry/commands/find_method.rb @@ -116,7 +116,7 @@ class Pry # @yieldparam klass Each class/module in the namespace. # def recurse_namespace(klass, done = {}, &block) - return if !(Module === klass) || done[klass] + return if !klass.is_a?(Module) || done[klass] done[klass] = true diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb index fb2549cd..5f15c8fa 100644 --- a/lib/pry/commands/ls.rb +++ b/lib/pry/commands/ls.rb @@ -103,7 +103,9 @@ class Pry def error_list any_args = args.any? + # rubocop:disable Style/CaseEquality non_mod_interrogatee = !(Module === @interrogatee) + # rubocop:enable Style/CaseEquality [ ['-l does not make sense with a specified Object', :locals, any_args], ['-g does not make sense with a specified Object', :globals, any_args], diff --git a/lib/pry/commands/ls/constants.rb b/lib/pry/commands/ls/constants.rb index 27c3f493..a07ff896 100644 --- a/lib/pry/commands/ls/constants.rb +++ b/lib/pry/commands/ls/constants.rb @@ -54,7 +54,7 @@ class Pry end color(:exception_constant, name) elsif begin - Module === mod.const_get(name) + mod.const_get(name).is_a?(Module) rescue StandardError false end diff --git a/lib/pry/commands/ls/instance_vars.rb b/lib/pry/commands/ls/instance_vars.rb index ebae02fd..b5496ff2 100644 --- a/lib/pry/commands/ls/instance_vars.rb +++ b/lib/pry/commands/ls/instance_vars.rb @@ -16,7 +16,7 @@ class Pry end def output_self - ivars = if Object === @interrogatee + ivars = if Object === @interrogatee # rubocop:disable Style/CaseEquality Pry::Method.safe_send(@interrogatee, :instance_variables) else [] # TODO: BasicObject support diff --git a/lib/pry/commands/ls/interrogatable.rb b/lib/pry/commands/ls/interrogatable.rb index 399d11f3..67a43373 100644 --- a/lib/pry/commands/ls/interrogatable.rb +++ b/lib/pry/commands/ls/interrogatable.rb @@ -5,7 +5,7 @@ class Pry private def interrogating_a_module? - Module === @interrogatee + Module === @interrogatee # rubocop:disable Style/CaseEquality end def interrogatee_mod diff --git a/lib/pry/commands/show_source.rb b/lib/pry/commands/show_source.rb index 9103c14f..9390fb10 100644 --- a/lib/pry/commands/show_source.rb +++ b/lib/pry/commands/show_source.rb @@ -36,7 +36,7 @@ class Pry def process if opts.present?(:e) obj = target.eval(args.first) - self.args = Array.new(1) { Module === obj ? obj.name : obj.class.name } + self.args = Array.new(1) { obj.is_a?(Module) ? obj.name : obj.class.name } end super diff --git a/lib/pry/config.rb b/lib/pry/config.rb index 6c497314..fd6d92b9 100644 --- a/lib/pry/config.rb +++ b/lib/pry/config.rb @@ -28,7 +28,7 @@ class Pry # Will only show the first line of the backtrace exception_handler: proc do |output, exception, _| - if UserError === exception && SyntaxError === exception + if exception.is_a?(UserError) && exception.is_a?(SyntaxError) output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}" else output.puts "#{exception.class}: #{exception.message}" diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb index 8bf1ef7b..5aeee32f 100644 --- a/lib/pry/config/behavior.rb +++ b/lib/pry/config/behavior.rb @@ -98,10 +98,10 @@ class Pry def from_hash(attributes, default = nil) new(default).tap do |config| attributes.each do |key, value| - config[key] = if Hash === value + config[key] = if value.is_a?(Hash) from_hash(value) - elsif Array === value - value.map { |v| Hash === v ? from_hash(v) : v } + elsif value.is_a?(Array) + value.map { |v| v.is_a?(Hash) ? from_hash(v) : v } else value end @@ -149,7 +149,7 @@ class Pry def [](key) key = key.to_s obj = key?(key) ? @lookup[key] : (@default && @default[key]) - Pry::Config::Lazy === obj ? obj.call : obj + obj.is_a?(Pry::Config::Lazy) ? obj.call : obj end # @@ -344,7 +344,7 @@ class Pry end def __try_convert_to_hash(obj) - if Hash === obj + if obj.is_a?(Hash) obj elsif obj.respond_to?(:to_h) obj.to_h @@ -354,7 +354,7 @@ class Pry end def __dup(value) - if NODUP.any? { |klass| klass === value } + if NODUP.any? { |klass| value.is_a?(klass) } value else value.dup diff --git a/lib/pry/core_extensions.rb b/lib/pry/core_extensions.rb index ffe1d221..6800b0e5 100644 --- a/lib/pry/core_extensions.rb +++ b/lib/pry/core_extensions.rb @@ -39,7 +39,7 @@ class Object # my_method() # @see Pry.start def pry(object = nil, hash = {}) - if object.nil? || Hash === object + if object.nil? || Hash === object # rubocop:disable Style/CaseEquality Pry.start(self, object || {}) else Pry.start(object, hash) diff --git a/lib/pry/exceptions.rb b/lib/pry/exceptions.rb index 603dd132..bec48c28 100644 --- a/lib/pry/exceptions.rb +++ b/lib/pry/exceptions.rb @@ -25,7 +25,7 @@ class Pry # Catches SecurityErrors if $SAFE is set module TooSafeException def self.===(exception) - $SAFE > 0 && SecurityError === exception + $SAFE > 0 && exception.is_a?(SecurityError) end end diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index b8c6bff6..897362d4 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -20,7 +20,7 @@ class Pry # This is required to introspect methods on objects like Net::HTTP::Get that # have overridden the `method` method. def safe_send(obj, method, *args, &block) - (Module === obj ? Module : Object).instance_method(method) + (obj.is_a?(Module) ? Module : Object).instance_method(method) .bind(obj).call(*args, &block) end diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index 1ea50fff..f8a263de 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -146,7 +146,7 @@ class Pry if in_string? tokens = tokenize("#{open_delimiters_line}\n#{line}") tokens = tokens.drop_while do |token, _type| - !(String === token && token.include?("\n")) + !(token.is_a?(String) && token.include?("\n")) end previously_in_string = true else diff --git a/lib/pry/method.rb b/lib/pry/method.rb index e10fbe4f..7be9697a 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -78,7 +78,7 @@ class Pry else method = begin - if Object === b.eval('self') + if Object === b.eval('self') # rubocop:disable Style/CaseEquality new(Kernel.instance_method(:method).bind(b.eval("self")).call(meth_name)) else str = 'class << self; self; end' \ @@ -183,7 +183,7 @@ class Pry # @param [Object] obj # @return [Array[Class, Module]] def resolution_order(obj) - if Class === obj + if Class === obj # rubocop:disable Style/CaseEquality singleton_class_resolution_order(obj) + instance_resolution_order(Class) else klass = begin @@ -405,7 +405,7 @@ class Pry # @return [Pry::Method, nil] The wrapped method that is called when you # use "super" in the body of this method. def super(times = 1) - if UnboundMethod === @method + if @method.is_a?(UnboundMethod) sup = super_using_ancestors(Pry::Method.instance_resolution_order(owner), times) else sup = super_using_ancestors(Pry::Method.resolution_order(receiver), times) diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 68440bf0..38c03f8d 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -247,8 +247,11 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc. # https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039 # we can drop in the future. obj.to_s + # rubocop:disable Style/CaseEquality elsif Pry.config.prompt_safe_contexts.any? { |v| v === obj } && obj.inspect.length <= max + # rubocop:enable Style/CaseEquality + obj.inspect elsif id format("#<#{obj.class}:0x%<id>x>", id: obj.object_id << 1) @@ -369,7 +372,7 @@ Readline version #{Readline::VERSION} detected - will not auto_resize! correctly # @param [Object] target The object to get a `Binding` object for. # @return [Binding] The `Binding` object. def self.binding_for(target) - return target if Binding === target + return target if Binding === target # rubocop:disable Style/CaseEquality return TOPLEVEL_BINDING if Pry.main == target target.__binding__ diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index e7f99f0e..39d4794b 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -164,7 +164,7 @@ class Pry # The value the local was set to. # def inject_local(name, value, b) - value = Proc === value ? value.call : value + value = value.is_a?(Proc) ? value.call : value if b.respond_to?(:local_variable_set) b.local_variable_set name, value else # < 2.1 @@ -664,7 +664,7 @@ class Pry raise ArgumentError, "wrong number of arguments" elsif !args.first.respond_to?(:exception) raise TypeError, "exception class/object expected" - elsif args.length === 1 + elsif args.size == 1 args.first.exception else args.first.exception(args[1]) @@ -672,7 +672,7 @@ class Pry raise TypeError, "exception object expected" unless exception.is_a? Exception - exception.set_backtrace(args.length === 3 ? args[2] : caller(1)) + exception.set_backtrace(args.size == 3 ? args[2] : caller(1)) if force || binding_stack.one? binding_stack.clear diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb index d8dcebbb..7c408407 100644 --- a/lib/pry/repl.rb +++ b/lib/pry/repl.rb @@ -96,7 +96,7 @@ class Pry val = read_line("#{current_prompt}#{indentation}") # Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C> - return val unless String === val + return val unless val.is_a?(String) if pry.config.auto_indent original_val = "#{indentation}#{val}" diff --git a/lib/pry/testable/evalable.rb b/lib/pry/testable/evalable.rb index 458465ff..08f68a35 100644 --- a/lib/pry/testable/evalable.rb +++ b/lib/pry/testable/evalable.rb @@ -10,7 +10,7 @@ class Pry def pry_eval(*eval_strs) b = - if String === eval_strs.first + if eval_strs.first.is_a?(String) Pry.toplevel_binding else Pry.binding_for(eval_strs.shift) diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 8b03d6d9..8261b3fb 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -52,7 +52,7 @@ class Pry # @raise [ArgumentError] if the argument is not a `Module` # @param [Module] mod def initialize(mod) - unless ::Module === mod + unless mod.is_a?(Module) raise ArgumentError, "Tried to initialize a WrappedModule with a " \ "non-module #{mod.inspect}" end @@ -82,7 +82,7 @@ class Pry # @return String def method_prefix if singleton_class? - if Module === singleton_instance + if Module === singleton_instance # rubocop:disable Style/CaseEquality "#{WrappedModule.new(singleton_instance).nonblank_name}." else "self." @@ -355,7 +355,7 @@ class Pry return if safe_send(parent, :autoload?, name) child = safe_send(parent, :const_get, name) - return unless Module === child + return unless child.is_a?(Module) return unless safe_send(child, :name) == "#{safe_send(parent, :name)}::#{name}" child |