1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

rubocop: fix offences of the Style/RedundantBegin cop

This commit is contained in:
Kyrylo Silin 2019-02-24 18:32:19 +02:00
parent 898e9d963e
commit 8b41db334c
5 changed files with 19 additions and 37 deletions

View file

@ -1146,15 +1146,6 @@ Style/RaiseArgs:
Exclude: Exclude:
- 'lib/pry/method.rb' - '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 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
Style/RedundantException: Style/RedundantException:

View file

@ -38,12 +38,10 @@ class Pry
end end
def process_cd(dest) def process_cd(dest)
begin state.old_pwd = Dir.pwd
state.old_pwd = Dir.pwd Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest))
Dir.chdir(File.expand_path(path_from_cd_path(dest) || dest)) rescue Errno::ENOENT
rescue Errno::ENOENT raise CommandError, "No such directory: #{dest}"
raise CommandError, "No such directory: #{dest}"
end
end end
def cd_path_env def cd_path_env

View file

@ -37,7 +37,6 @@ class Pry
# all the flags we want as well as the file and line number we # all the flags we want as well as the file and line number we
# want to open at. # want to open at.
def build_editor_invocation_string(file, line, blocking) def build_editor_invocation_string(file, line, blocking)
if _pry_.config.editor.respond_to?(:call) if _pry_.config.editor.respond_to?(:call)
args = [file, line, blocking][0...(_pry_.config.editor.arity)] args = [file, line, blocking][0...(_pry_.config.editor.arity)]
_pry_.config.editor.call(*args) _pry_.config.editor.call(*args)
@ -58,13 +57,11 @@ class Pry
# We need JRuby specific code here cos just shelling out using # We need JRuby specific code here cos just shelling out using
# system() appears to be pretty broken :/ # system() appears to be pretty broken :/
def open_editor_on_jruby(editor_invocation) def open_editor_on_jruby(editor_invocation)
begin require 'spoon'
require 'spoon' pid = Spoon.spawnp(*Shellwords.split(editor_invocation))
pid = Spoon.spawnp(*Shellwords.split(editor_invocation)) Process.waitpid(pid)
Process.waitpid(pid) rescue FFI::NotFoundError
rescue FFI::NotFoundError system(editor_invocation)
system(editor_invocation)
end
end end
# Some editors that run outside the terminal allow you to control whether or # Some editors that run outside the terminal allow you to control whether or

View file

@ -211,11 +211,9 @@ class Pry
end end
def singleton_class_of(obj) def singleton_class_of(obj)
begin class << obj; self; end
class << obj; self; end rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ...
rescue TypeError # can't define singleton. Fixnum, Symbol, Float, ... obj.class
obj.class
end
end end
end end

View file

@ -128,19 +128,17 @@ class Pry
end end
def self.load_win32console def self.load_win32console
begin require 'win32console'
require 'win32console' # The mswin and mingw versions of pry require win32console, so this should
# The mswin and mingw versions of pry require win32console, so this should # only fail on jruby (where win32console doesn't work).
# only fail on jruby (where win32console doesn't work). # Instead we'll recommend ansicon, which does.
# Instead we'll recommend ansicon, which does. rescue LoadError
rescue LoadError warn <<-WARNING if Pry.config.windows_console_warning
warn <<-WARNING if Pry.config.windows_console_warning
For a better Pry experience on Windows, please use ansicon: For a better Pry experience on Windows, please use ansicon:
https://github.com/adoxa/ansicon https://github.com/adoxa/ansicon
If you use an alternative to ansicon and don't want to see this warning again, 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. you can add "Pry.config.windows_console_warning = false" to your pryrc.
WARNING WARNING
end
end end
# Do basic setup for initial session including: loading pryrc, plugins, # Do basic setup for initial session including: loading pryrc, plugins,