From 944ada1cd432ade0af90bc0a5a5df3ae36b722bb Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Sat, 20 Oct 2018 00:21:07 +0800 Subject: [PATCH] rubocop: fix offences of the Style/MultilineTernaryOperator cop --- .rubocop_todo.yml | 10 ---------- lib/pry/commands/gem_stats.rb | 12 +++++++----- lib/pry/commands/show_doc.rb | 10 ++++------ lib/pry/commands/whereami.rb | 5 +++-- lib/pry/history_array.rb | 22 +++++++++------------- lib/pry/pry_instance.rb | 3 +-- 6 files changed, 24 insertions(+), 38 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 26fea174..69c7672c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1187,16 +1187,6 @@ Style/MultilineBlockChain: - 'lib/pry/commands/ls/local_vars.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 Style/MultipleComparison: Exclude: diff --git a/lib/pry/commands/gem_stats.rb b/lib/pry/commands/gem_stats.rb index c652ba0a..14e7c9f4 100644 --- a/lib/pry/commands/gem_stats.rb +++ b/lib/pry/commands/gem_stats.rb @@ -71,11 +71,13 @@ FAILWHALE end def format_dependencies(rdeps) - rdeps.empty? ? - bold("None") : - with_line_numbers(rdeps.map {|h| - "%{name} (%{requirements})" % {name: h["name"], requirements: h["requirements"]} - }.join($/), 1, :bold) + return bold('None') if rdeps.empty? + + with_line_numbers( + rdeps.map { |h| "#{h['name']} (#{h['requirements']})" }.join("\n"), + 1, + :bold + ) end Pry::Commands.add_command(self) end diff --git a/lib/pry/commands/show_doc.rb b/lib/pry/commands/show_doc.rb index 2fa74feb..978a3a3e 100644 --- a/lib/pry/commands/show_doc.rb +++ b/lib/pry/commands/show_doc.rb @@ -69,12 +69,10 @@ class Pry # number of lines in the comment and the start line of the code_object # @return [Fixnum] start line of docs def start_line_for(code_object) - if code_object.command? || opts.present?(:'base-one') - 1 - else - code_object.source_line.nil? ? 1 : - (code_object.source_line - code_object.doc.lines.count) - end + return 1 if code_object.command? || opts.present?(:'base-one') + return 1 unless code_object.source_line + + code_object.source_line - code_object.doc.lines.count end end diff --git a/lib/pry/commands/whereami.rb b/lib/pry/commands/whereami.rb index 126721a3..ab6176a5 100644 --- a/lib/pry/commands/whereami.rb +++ b/lib/pry/commands/whereami.rb @@ -154,8 +154,9 @@ class Pry # or it returns the class of `target_self` if `target_self` is not a class. # @return [Pry::WrappedModule] def target_class - target_self.is_a?(Module) ? Pry::WrappedModule(target_self) : - Pry::WrappedModule(target_self.class) + return Pry::WrappedModule(target_self) if target_self.is_a?(Module) + + Pry::WrappedModule(target_self.class) end def class_code diff --git a/lib/pry/history_array.rb b/lib/pry/history_array.rb index 4d93f76a..ad476011 100644 --- a/lib/pry/history_array.rb +++ b/lib/pry/history_array.rb @@ -51,21 +51,17 @@ class Pry # @return [Array, nil] The selected items. Nil if index is greater than # the size of the array. def [](index_or_range, size = nil) - if 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 + unless index_or_range.is_a?(Integer) 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 + + 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 # @return [Integer] Amount of objects in the array diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 7f70b4c8..16b4ec99 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -531,8 +531,7 @@ class Pry # @return [String] The prompt. def select_prompt object = current_binding.eval('self') - open_token = @indent.open_delimiters.any? ? @indent.open_delimiters.last : - @indent.stack.last + open_token = @indent.open_delimiters.last || @indent.stack.last c = Pry::Config.assign({ object: object,