diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-03-02 14:12:25 +0200 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2019-03-02 14:12:25 +0200 |
commit | ac24bad339e19f576592d98178ce0ae0a1659605 (patch) | |
tree | de8aff9f967d89a67f3ac0daeab269056696b07a | |
parent | 4450fa75f0e9f613b5eee01687f3642a962a8525 (diff) | |
download | pry-ac24bad339e19f576592d98178ce0ae0a1659605.tar.gz |
rubocop: fix offences of the Style/RescueModifier cop
-rw-r--r-- | .rubocop_todo.yml | 12 | ||||
-rw-r--r-- | Rakefile | 6 | ||||
-rw-r--r-- | lib/pry/code_object.rb | 7 | ||||
-rw-r--r-- | lib/pry/color_printer.rb | 6 | ||||
-rw-r--r-- | lib/pry/commands/ls/constants.rb | 18 | ||||
-rw-r--r-- | lib/pry/input_completer.rb | 6 | ||||
-rw-r--r-- | lib/pry/method.rb | 20 | ||||
-rw-r--r-- | lib/pry/method/patcher.rb | 6 |
8 files changed, 55 insertions, 26 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dbf642dd..7e88f9d4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -314,18 +314,6 @@ Style/PerlBackrefs: - 'lib/pry/method.rb' - 'lib/pry/rubygem.rb' -# Offense count: 12 -# Cop supports --auto-correct. -Style/RescueModifier: - Exclude: - - 'Rakefile' - - 'lib/pry/code_object.rb' - - 'lib/pry/color_printer.rb' - - 'lib/pry/commands/ls/constants.rb' - - 'lib/pry/input_completer.rb' - - 'lib/pry/method.rb' - - 'lib/pry/method/patcher.rb' - # Offense count: 11 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. @@ -85,7 +85,11 @@ task rm_pkgs: :rmgems desc "reinstall gem" task reinstall: :gems do - sh "gem uninstall pry" rescue nil + begin + sh "gem uninstall pry" + rescue StandardError + nil + end sh "gem install #{File.dirname(__FILE__)}/pkg/pry-#{Pry::VERSION}.gem" end diff --git a/lib/pry/code_object.rb b/lib/pry/code_object.rb index c6714793..20138382 100644 --- a/lib/pry/code_object.rb +++ b/lib/pry/code_object.rb @@ -87,10 +87,11 @@ class Pry @super_level = options[:super] end + # TODO: just make it so find_command_by_match_or_listing doesn't raise? def command_lookup - # TODO: just make it so find_command_by_match_or_listing doesn't - # raise? - _pry_.commands.find_command_by_match_or_listing(str) rescue nil + _pry_.commands.find_command_by_match_or_listing(str) + rescue StandardError + nil end # when no paramter is given (i.e CodeObject.lookup(nil)), then we diff --git a/lib/pry/color_printer.rb b/lib/pry/color_printer.rb index 7b26e287..f209478d 100644 --- a/lib/pry/color_printer.rb +++ b/lib/pry/color_printer.rb @@ -49,7 +49,11 @@ class Pry singleton = class << obj; self; end ancestors = Pry::Method.safe_send(singleton, :ancestors) klass = ancestors.reject { |k| k == singleton }.first - obj_id = obj.__id__.to_s(16) rescue 0 + obj_id = begin + obj.__id__.to_s(16) + rescue + 0 + end str = "#<#{klass}:0x#{obj_id}>" end diff --git a/lib/pry/commands/ls/constants.rb b/lib/pry/commands/ls/constants.rb index e30b3edc..b6266ec5 100644 --- a/lib/pry/commands/ls/constants.rb +++ b/lib/pry/commands/ls/constants.rb @@ -44,10 +44,22 @@ class Pry next end - if (const = (!mod.autoload?(name) && (mod.const_get(name) || true) rescue nil)) - if (const < Exception rescue false) + if (const = (begin + !mod.autoload?(name) && (mod.const_get(name) || true) + rescue StandardError + nil + end)) + if begin + const < Exception + rescue StandardError + false + end color(:exception_constant, name) - elsif (Module === mod.const_get(name) rescue false) + elsif begin + Module === mod.const_get(name) + rescue StandardError + false + end color(:class_constant, name) else color(:constant, name) diff --git a/lib/pry/input_completer.rb b/lib/pry/input_completer.rb index 39a2e087..4840142b 100644 --- a/lib/pry/input_completer.rb +++ b/lib/pry/input_completer.rb @@ -172,7 +172,11 @@ class Pry candidates = Set.new to_ignore = ignored_modules ObjectSpace.each_object(Module) do |m| - next if (to_ignore.include?(m) rescue true) + next if begin + to_ignore.include?(m) + rescue StandardError + true + end # jruby doesn't always provide #instance_methods() on each # object. diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 34c66c99..ecd0c36b 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -121,7 +121,9 @@ class Pry # @param [Binding] target The binding where the method is looked up. # @return [Pry::Method, nil] def from_class(klass, name, target = TOPLEVEL_BINDING) - new(lookup_method_via_binding(klass, name, :instance_method, target)) rescue nil + new(lookup_method_via_binding(klass, name, :instance_method, target)) + rescue StandardError + nil end alias from_module from_class @@ -134,7 +136,9 @@ class Pry # @param [Binding] target The binding where the method is looked up. # @return [Pry::Method, nil] def from_obj(obj, name, target = TOPLEVEL_BINDING) - new(lookup_method_via_binding(obj, name, :method, target)) rescue nil + new(lookup_method_via_binding(obj, name, :method, target)) + rescue StandardError + nil end # Get all of the instance methods of a `Class` or `Module` @@ -171,7 +175,11 @@ class Pry if Class === obj singleton_class_resolution_order(obj) + instance_resolution_order(Class) else - klass = singleton_class_of(obj) rescue obj.class + klass = begin + singleton_class_of(obj) + rescue StandardError + obj.class + end instance_resolution_order(klass) end end @@ -498,7 +506,11 @@ class Pry (next_owner = ancestors[i]) || (return nil) end - safe_send(next_owner, :instance_method, name) rescue nil + begin + safe_send(next_owner, :instance_method, name) + rescue StandardError + nil + end end # @param [String] first_ln The first line of a method definition. diff --git a/lib/pry/method/patcher.rb b/lib/pry/method/patcher.rb index c09e29dd..ac1ca87b 100644 --- a/lib/pry/method/patcher.rb +++ b/lib/pry/method/patcher.rb @@ -52,7 +52,11 @@ class Pry alias_method method.original_name, temp_name end ensure - method.send(:remove_method, temp_name) rescue nil + begin + method.send(:remove_method, temp_name) + rescue StandardError + nil + end end # Update the definition line so that it can be eval'd directly on the Method's |