mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Merge pull request #1887 from pry/rubocop-style-and-or
rubocop: fix offences of the Style/AndOr cop
This commit is contained in:
commit
f1fc421d73
21 changed files with 39 additions and 46 deletions
|
@ -725,13 +725,6 @@ Style/Alias:
|
|||
- 'lib/pry/wrapped_module/candidate.rb'
|
||||
- 'spec/method_spec.rb'
|
||||
|
||||
# Offense count: 44
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
# SupportedStyles: always, conditionals
|
||||
Style/AndOr:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 2
|
||||
# Configuration parameters: AllowedChars.
|
||||
Style/AsciiComments:
|
||||
|
|
|
@ -58,16 +58,16 @@ class Pry
|
|||
# readable for some reason.
|
||||
# @return [String] absolute path for the given `filename`.
|
||||
def abs_path
|
||||
code_path.detect { |path| readable?(path) } or
|
||||
raise MethodSource::SourceNotFoundError,
|
||||
"Cannot open #{ @filename.inspect } for reading."
|
||||
code_path.detect { |path| readable?(path) } ||
|
||||
raise(MethodSource::SourceNotFoundError,
|
||||
"Cannot open #{ @filename.inspect } for reading.")
|
||||
end
|
||||
|
||||
# @param [String] path
|
||||
# @return [Boolean] if the path, with or without the default ext,
|
||||
# is a readable file then `true`, otherwise `false`.
|
||||
def readable?(path)
|
||||
File.readable?(path) && !File.directory?(path) or
|
||||
File.readable?(path) && !File.directory?(path) ||
|
||||
File.readable?(path << DEFAULT_EXT)
|
||||
end
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ class Pry
|
|||
def find_command_by_match_or_listing(match_or_listing)
|
||||
cmd = (@commands[match_or_listing] ||
|
||||
Pry::Helpers::BaseHelpers.find_command(match_or_listing, @commands))
|
||||
cmd or raise ArgumentError, "Cannot find a command: '#{match_or_listing}'!"
|
||||
cmd || raise(ArgumentError, "Cannot find a command: '#{match_or_listing}'!")
|
||||
end
|
||||
|
||||
# Aliases a command
|
||||
|
@ -175,7 +175,7 @@ class Pry
|
|||
# @example Pass explicit description (overriding default).
|
||||
# Pry.config.commands.alias_command "lM", "ls -M", :desc => "cutiepie"
|
||||
def alias_command(match, action, options = {})
|
||||
cmd = find_command(action) or fail "Command: `#{action}` not found"
|
||||
(cmd = find_command(action)) || fail("Command: `#{action}` not found")
|
||||
original_options = cmd.options.dup
|
||||
|
||||
options = original_options.merge!({
|
||||
|
@ -371,7 +371,7 @@ class Pry
|
|||
|
||||
# @private (used for testing)
|
||||
def run_command(context, match, *args)
|
||||
command = @commands[match] or raise NoCommandError.new(match, self)
|
||||
(command = @commands[match]) || raise(NoCommandError.new(match, self))
|
||||
command.new(context).call_safely(*args)
|
||||
end
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class Pry
|
|||
end
|
||||
|
||||
def code_object_doc
|
||||
(code_object && code_object.doc) or could_not_locate(obj_name)
|
||||
(code_object && code_object.doc) || could_not_locate(obj_name)
|
||||
end
|
||||
|
||||
def code_object_source_or_file
|
||||
|
|
|
@ -34,8 +34,8 @@ class Pry
|
|||
|
||||
def format(mod, constants)
|
||||
constants.sort_by(&:downcase).map do |name|
|
||||
if Object.respond_to?(:deprecate_constant) and
|
||||
DEPRECATED_CONSTANTS.include?(name) and
|
||||
if Object.respond_to?(:deprecate_constant) &&
|
||||
DEPRECATED_CONSTANTS.include?(name) &&
|
||||
!show_deprecated_constants?
|
||||
next
|
||||
end
|
||||
|
|
|
@ -48,7 +48,7 @@ class Pry
|
|||
end
|
||||
|
||||
def show_input
|
||||
if opts.present?(:print) or !Pry::Code.complete_expression?(eval_string)
|
||||
if opts.present?(:print) || !Pry::Code.complete_expression?(eval_string)
|
||||
run "show-input"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,9 +52,9 @@ class Pry
|
|||
|
||||
def code
|
||||
@code ||= if opts.present?(:m)
|
||||
method_code or raise CommandError, "Cannot find method code."
|
||||
method_code || raise(CommandError, "Cannot find method code.")
|
||||
elsif opts.present?(:c)
|
||||
class_code or raise CommandError, "Cannot find class code."
|
||||
class_code || raise(CommandError, "Cannot find class code.")
|
||||
elsif opts.present?(:f)
|
||||
Pry::Code.from_file(@file)
|
||||
elsif args.any?
|
||||
|
|
|
@ -76,7 +76,7 @@ class Pry
|
|||
#
|
||||
def [](key)
|
||||
key = key.to_s
|
||||
key?(key) ? @lookup[key] : (@default and @default[key])
|
||||
key?(key) ? @lookup[key] : (@default && @default[key])
|
||||
end
|
||||
|
||||
#
|
||||
|
@ -177,7 +177,7 @@ class Pry
|
|||
|
||||
def last_default
|
||||
last = @default
|
||||
last = last.default while last and last.default
|
||||
last = last.default while last && last.default
|
||||
last
|
||||
end
|
||||
|
||||
|
@ -216,7 +216,7 @@ class Pry
|
|||
|
||||
def respond_to_missing?(key, include_all = false)
|
||||
key = key.to_s.chomp(ASSIGNMENT)
|
||||
key?(key) or @default.respond_to?(key) or super(key, include_all)
|
||||
key?(key) || @default.respond_to?(key) || super(key, include_all)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -81,7 +81,7 @@ class Object
|
|||
# This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
|
||||
# 1) ./spec/pry_spec.rb:360:in `block in (root)'
|
||||
# 2) ./spec/pry_spec.rb:366:in `block in (root)'
|
||||
return class_eval { binding } if Pry::Helpers::Platform.jruby? and self.name == nil
|
||||
return class_eval { binding } if Pry::Helpers::Platform.jruby? && (self.name == nil)
|
||||
|
||||
# class_eval sets both self and the default definee to this class.
|
||||
return class_eval("binding")
|
||||
|
|
|
@ -52,7 +52,7 @@ class Pry
|
|||
# Note we dont want to use Pry.config.system here as that
|
||||
# may be invoked non-interactively (i.e via Open4), whereas we want to
|
||||
# ensure the editor is always interactive
|
||||
system(*Shellwords.split(editor_invocation)) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
|
||||
system(*Shellwords.split(editor_invocation)) || raise(CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}")
|
||||
end
|
||||
|
||||
# We need JRuby specific code here cos just shelling out using
|
||||
|
|
|
@ -143,7 +143,7 @@ class Pry
|
|||
end
|
||||
|
||||
def set_file_and_dir_locals(file_name, _pry_ = _pry_(), target = target())
|
||||
return if !target or !file_name
|
||||
return if !target || !file_name
|
||||
|
||||
_pry_.last_file = File.expand_path(file_name)
|
||||
_pry_.inject_local("_file_", _pry_.last_file, target)
|
||||
|
|
|
@ -23,7 +23,7 @@ class Pry
|
|||
|
||||
def self.tablify(things, line_length, config = Pry.config)
|
||||
table = Table.new(things, { column_count: things.size }, config)
|
||||
table.column_count -= 1 until 1 == table.column_count or
|
||||
table.column_count -= 1 until (1 == table.column_count) ||
|
||||
table.fits_on_line?(line_length)
|
||||
table
|
||||
end
|
||||
|
|
|
@ -157,7 +157,7 @@ class Pry::InputCompleter
|
|||
lv = eval("local_variables", bind).collect(&:to_s)
|
||||
cv = eval("self.class.constants", bind).collect(&:to_s)
|
||||
|
||||
if (gv | lv | cv).include?(receiver) or /^[A-Z]/ =~ receiver && /\./ !~ receiver
|
||||
if (gv | lv | cv).include?(receiver) || /^[A-Z]/ =~ receiver && /\./ !~ receiver
|
||||
# foo.func and foo is local var. OR
|
||||
# Foo::Bar.func
|
||||
begin
|
||||
|
|
|
@ -56,7 +56,7 @@ class Pry
|
|||
elsif options[:methods]
|
||||
from_obj(target.eval("self"), name, target)
|
||||
else
|
||||
from_str(name, target, instance: true) or
|
||||
from_str(name, target, instance: true) ||
|
||||
from_str(name, target, methods: true)
|
||||
end
|
||||
|
||||
|
@ -395,7 +395,7 @@ class Pry
|
|||
|
||||
# @return [Boolean] Was the method defined outside a source file?
|
||||
def dynamically_defined?
|
||||
!!(source_file and source_file =~ /(\(.*\))|<.*>/)
|
||||
!!(source_file && source_file =~ /(\(.*\))|<.*>/)
|
||||
end
|
||||
|
||||
# @return [Boolean] Whether the method is unbound.
|
||||
|
@ -452,14 +452,14 @@ class Pry
|
|||
# @param [Class] klass
|
||||
# @return [Boolean]
|
||||
def is_a?(klass)
|
||||
klass == Pry::Method or @method.is_a?(klass)
|
||||
(klass == Pry::Method) || @method.is_a?(klass)
|
||||
end
|
||||
alias kind_of? is_a?
|
||||
|
||||
# @param [String, Symbol] method_name
|
||||
# @return [Boolean]
|
||||
def respond_to?(method_name, include_all = false)
|
||||
super or @method.respond_to?(method_name, include_all)
|
||||
super || @method.respond_to?(method_name, include_all)
|
||||
end
|
||||
|
||||
# Delegate any unknown calls to the wrapped method.
|
||||
|
@ -477,7 +477,7 @@ class Pry
|
|||
# @raise [CommandError] when the method can't be found or `pry-doc` isn't installed.
|
||||
def pry_doc_info
|
||||
if Pry.config.has_pry_doc
|
||||
Pry::MethodInfo.info_for(@method) or raise CommandError, "Cannot locate this method: #{name}. (source_location returns nil)"
|
||||
Pry::MethodInfo.info_for(@method) || raise(CommandError, "Cannot locate this method: #{name}. (source_location returns nil)")
|
||||
else
|
||||
fail_msg = "Cannot locate this method: #{name}."
|
||||
if Helpers::Platform.mri?
|
||||
|
@ -496,7 +496,7 @@ class Pry
|
|||
while ancestors[i] && !(ancestors[i].method_defined?(name) || ancestors[i].private_method_defined?(name))
|
||||
i += 1
|
||||
end
|
||||
next_owner = ancestors[i] or return nil
|
||||
(next_owner = ancestors[i]) || (return nil)
|
||||
end
|
||||
|
||||
safe_send(next_owner, :instance_method, name) rescue nil
|
||||
|
@ -520,7 +520,7 @@ class Pry
|
|||
|
||||
def c_source
|
||||
info = pry_doc_info
|
||||
if info and info.source
|
||||
if info && info.source
|
||||
strip_comments_from_c_code(info.source)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,9 +24,9 @@ class Pry
|
|||
# @param [Binding] b
|
||||
# @return [Boolean]
|
||||
def normal_method?(method, b)
|
||||
if method and method.source_file and method.source_range
|
||||
if method && method.source_file && method.source_range
|
||||
binding_file, binding_line = b.eval('__FILE__'), b.eval('__LINE__')
|
||||
File.expand_path(method.source_file) == File.expand_path(binding_file) and
|
||||
(File.expand_path(method.source_file) == File.expand_path(binding_file)) &&
|
||||
method.source_range.include?(binding_line)
|
||||
end
|
||||
rescue
|
||||
|
|
|
@ -29,7 +29,7 @@ class Pry::Output
|
|||
alias write print
|
||||
|
||||
def tty?
|
||||
@boxed_io.respond_to?(:tty?) and @boxed_io.tty?
|
||||
@boxed_io.respond_to?(:tty?) && @boxed_io.tty?
|
||||
end
|
||||
|
||||
def method_missing(name, *args, &block)
|
||||
|
|
|
@ -131,7 +131,7 @@ class Pry
|
|||
|
||||
# Default to less, and make sure less is being passed the correct
|
||||
# options
|
||||
if pager.strip.empty? or pager =~ /^less\b/
|
||||
if pager.strip.empty? || pager =~ /^less\b/
|
||||
pager = "less -R -F -X"
|
||||
end
|
||||
|
||||
|
|
|
@ -293,8 +293,8 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
|
|||
end
|
||||
|
||||
def self.default_editor_for_platform
|
||||
return ENV['VISUAL'] if ENV['VISUAL'] and not ENV['VISUAL'].empty?
|
||||
return ENV['EDITOR'] if ENV['EDITOR'] and not ENV['EDITOR'].empty?
|
||||
return ENV['VISUAL'] if ENV['VISUAL'] && (not ENV['VISUAL'].empty?)
|
||||
return ENV['EDITOR'] if ENV['EDITOR'] && (not ENV['EDITOR'].empty?)
|
||||
return 'notepad' if Helpers::Platform.windows?
|
||||
|
||||
%w(editor nano vi).detect do |editor|
|
||||
|
|
|
@ -25,7 +25,7 @@ class Pry
|
|||
|
||||
first_spec = specs.sort_by { |spec| Gem::Version.new(spec.version) }.last
|
||||
|
||||
first_spec or raise CommandError, "Gem `#{name}` not found"
|
||||
first_spec || raise(CommandError, "Gem `#{name}` not found")
|
||||
end
|
||||
|
||||
# List gems matching a pattern.
|
||||
|
|
|
@ -30,12 +30,12 @@ class Pry::Terminal
|
|||
|
||||
def actual_screen_size
|
||||
# The best way, if possible (requires non-jruby ≥1.9 or io-console gem)
|
||||
screen_size_according_to_io_console or
|
||||
screen_size_according_to_io_console ||
|
||||
# Fall back to the old standby, though it might be stale:
|
||||
screen_size_according_to_env or
|
||||
screen_size_according_to_env ||
|
||||
# Fall further back, though this one is also out of date without something
|
||||
# calling Readline.set_screen_size
|
||||
screen_size_according_to_readline or
|
||||
screen_size_according_to_readline ||
|
||||
# Windows users can otherwise run ansicon and get a decent answer:
|
||||
screen_size_according_to_ansicon_env
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ class Pry::Testable::PryTester
|
|||
end
|
||||
|
||||
def process_command(command_str)
|
||||
@pry.process_command(command_str) or raise "Not a valid command"
|
||||
@pry.process_command(command_str) || raise("Not a valid command")
|
||||
last_command_result_or_output
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue