From 8b41db334c03d4b3afc457f3e7038155a0f45614 Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Sun, 24 Feb 2019 18:32:19 +0200 Subject: [PATCH] rubocop: fix offences of the Style/RedundantBegin cop --- .rubocop_todo.yml | 9 --------- lib/pry/commands/shell_command.rb | 10 ++++------ lib/pry/editor.rb | 13 +++++-------- lib/pry/method.rb | 8 +++----- lib/pry/pry_class.rb | 16 +++++++--------- 5 files changed, 19 insertions(+), 37 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2269ccf7..72c649d2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1146,15 +1146,6 @@ Style/RaiseArgs: Exclude: - 'lib/pry/method.rb' -# Offense count: 4 -# Cop supports --auto-correct. -Style/RedundantBegin: - Exclude: - - 'lib/pry/commands/shell_command.rb' - - 'lib/pry/editor.rb' - - 'lib/pry/method.rb' - - 'lib/pry/pry_class.rb' - # Offense count: 1 # Cop supports --auto-correct. Style/RedundantException: diff --git a/lib/pry/commands/shell_command.rb b/lib/pry/commands/shell_command.rb index 7b40f0b0..979a8db8 100644 --- a/lib/pry/commands/shell_command.rb +++ b/lib/pry/commands/shell_command.rb @@ -38,12 +38,10 @@ class Pry end def process_cd(dest) - begin - state.old_pwd = Dir.pwd - Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest)) - rescue Errno::ENOENT - raise CommandError, "No such directory: #{dest}" - end + state.old_pwd = Dir.pwd + Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest)) + rescue Errno::ENOENT + raise CommandError, "No such directory: #{dest}" end def cd_path_env diff --git a/lib/pry/editor.rb b/lib/pry/editor.rb index 18140712..ba09b679 100644 --- a/lib/pry/editor.rb +++ b/lib/pry/editor.rb @@ -37,7 +37,6 @@ class Pry # all the flags we want as well as the file and line number we # want to open at. def build_editor_invocation_string(file, line, blocking) - if _pry_.config.editor.respond_to?(:call) args = [file, line, blocking][0...(_pry_.config.editor.arity)] _pry_.config.editor.call(*args) @@ -58,13 +57,11 @@ class Pry # We need JRuby specific code here cos just shelling out using # system() appears to be pretty broken :/ def open_editor_on_jruby(editor_invocation) - begin - require 'spoon' - pid = Spoon.spawnp(*Shellwords.split(editor_invocation)) - Process.waitpid(pid) - rescue FFI::NotFoundError - system(editor_invocation) - end + require 'spoon' + pid = Spoon.spawnp(*Shellwords.split(editor_invocation)) + Process.waitpid(pid) + rescue FFI::NotFoundError + system(editor_invocation) end # Some editors that run outside the terminal allow you to control whether or diff --git a/lib/pry/method.rb b/lib/pry/method.rb index 585d62ba..2962011c 100644 --- a/lib/pry/method.rb +++ b/lib/pry/method.rb @@ -211,11 +211,9 @@ class Pry end def singleton_class_of(obj) - begin - class << obj; self; end - rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ... - obj.class - end + class << obj; self; end + rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ... + obj.class end end diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 7384020e..f71de8e6 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -128,19 +128,17 @@ class Pry end def self.load_win32console - begin - require 'win32console' - # The mswin and mingw versions of pry require win32console, so this should - # only fail on jruby (where win32console doesn't work). - # Instead we'll recommend ansicon, which does. - rescue LoadError - warn <<-WARNING if Pry.config.windows_console_warning + require 'win32console' + # The mswin and mingw versions of pry require win32console, so this should + # only fail on jruby (where win32console doesn't work). + # Instead we'll recommend ansicon, which does. + rescue LoadError + warn <<-WARNING if Pry.config.windows_console_warning For a better Pry experience on Windows, please use ansicon: https://github.com/adoxa/ansicon If you use an alternative to ansicon and don't want to see this warning again, you can add "Pry.config.windows_console_warning = false" to your pryrc. - WARNING - end + WARNING end # Do basic setup for initial session including: loading pryrc, plugins,