Merge pull request #1815 from pry/rubocop-style-multiline-ternary-operator

rubocop: fix offences of the Style/MultilineTernaryOperator cop
This commit is contained in:
Kyrylo Silin 2018-10-20 00:31:15 +08:00 committed by GitHub
commit 5f18796595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 38 deletions

View File

@ -1187,16 +1187,6 @@ Style/MultilineBlockChain:
- 'lib/pry/commands/ls/local_vars.rb' - 'lib/pry/commands/ls/local_vars.rb'
- 'spec/cli_spec.rb' - 'spec/cli_spec.rb'
# Offense count: 6
Style/MultilineTernaryOperator:
Exclude:
- 'lib/pry/commands/gem_stats.rb'
- 'lib/pry/commands/show_doc.rb'
- 'lib/pry/commands/whereami.rb'
- 'lib/pry/history_array.rb'
- 'lib/pry/pry_instance.rb'
- 'spec/syntax_checking_spec.rb'
# Offense count: 2 # Offense count: 2
Style/MultipleComparison: Style/MultipleComparison:
Exclude: Exclude:

View File

@ -71,11 +71,13 @@ FAILWHALE
end end
def format_dependencies(rdeps) def format_dependencies(rdeps)
rdeps.empty? ? return bold('None') if rdeps.empty?
bold("None") :
with_line_numbers(rdeps.map {|h| with_line_numbers(
"%{name} (%{requirements})" % {name: h["name"], requirements: h["requirements"]} rdeps.map { |h| "#{h['name']} (#{h['requirements']})" }.join("\n"),
}.join($/), 1, :bold) 1,
:bold
)
end end
Pry::Commands.add_command(self) Pry::Commands.add_command(self)
end end

View File

@ -69,12 +69,10 @@ class Pry
# number of lines in the comment and the start line of the code_object # number of lines in the comment and the start line of the code_object
# @return [Fixnum] start line of docs # @return [Fixnum] start line of docs
def start_line_for(code_object) def start_line_for(code_object)
if code_object.command? || opts.present?(:'base-one') return 1 if code_object.command? || opts.present?(:'base-one')
1 return 1 unless code_object.source_line
else
code_object.source_line.nil? ? 1 : code_object.source_line - code_object.doc.lines.count
(code_object.source_line - code_object.doc.lines.count)
end
end end
end end

View File

@ -154,8 +154,9 @@ class Pry
# or it returns the class of `target_self` if `target_self` is not a class. # or it returns the class of `target_self` if `target_self` is not a class.
# @return [Pry::WrappedModule] # @return [Pry::WrappedModule]
def target_class def target_class
target_self.is_a?(Module) ? Pry::WrappedModule(target_self) : return Pry::WrappedModule(target_self) if target_self.is_a?(Module)
Pry::WrappedModule(target_self.class)
Pry::WrappedModule(target_self.class)
end end
def class_code def class_code

View File

@ -51,21 +51,17 @@ class Pry
# @return [Array, nil] The selected items. Nil if index is greater than # @return [Array, nil] The selected items. Nil if index is greater than
# the size of the array. # the size of the array.
def [](index_or_range, size = nil) def [](index_or_range, size = nil)
if index_or_range.is_a? Integer unless index_or_range.is_a?(Integer)
index = convert_index(index_or_range)
if size
end_index = index + size
index > @count ? nil : (index...[end_index, @count].min).map do |n|
@hash[n]
end
else
@hash[index]
end
else
range = convert_range(index_or_range) range = convert_range(index_or_range)
range.begin > @count ? nil : range.map { |n| @hash[n] } return range.begin > @count ? nil : range.map { |n| @hash[n] }
end end
index = convert_index(index_or_range)
return @hash[index] unless size
return if index > @count
end_index = index + size
(index...[end_index, @count].min).map { |n| @hash[n] }
end end
# @return [Integer] Amount of objects in the array # @return [Integer] Amount of objects in the array

View File

@ -531,8 +531,7 @@ class Pry
# @return [String] The prompt. # @return [String] The prompt.
def select_prompt def select_prompt
object = current_binding.eval('self') object = current_binding.eval('self')
open_token = @indent.open_delimiters.any? ? @indent.open_delimiters.last : open_token = @indent.open_delimiters.last || @indent.stack.last
@indent.stack.last
c = Pry::Config.assign({ c = Pry::Config.assign({
object: object, object: object,