From bd778a3c04f3201bfe781e2b2e12363b234add0f Mon Sep 17 00:00:00 2001 From: Kyrylo Silin Date: Fri, 1 Mar 2019 01:24:54 +0200 Subject: [PATCH] rubocop: fix offences of the Style/ConditionalAssignment cop --- .rubocop_todo.yml | 13 ------------- lib/pry/command.rb | 22 ++++++++++++---------- lib/pry/commands/easter_eggs.rb | 11 ++++++----- lib/pry/commands/gist.rb | 6 +----- lib/pry/indent.rb | 6 +----- lib/pry/testable/pry_tester.rb | 11 ++++++----- lib/pry/wrapped_module.rb | 22 ++++++++++++---------- 7 files changed, 38 insertions(+), 53 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 97079f1e..3e130021 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -213,19 +213,6 @@ Style/CommentedKeyword: Exclude: - 'spec/fixtures/example_nesting.rb' -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'lib/pry/command.rb' - - 'lib/pry/commands/easter_eggs.rb' - - 'lib/pry/commands/gist.rb' - - 'lib/pry/indent.rb' - - 'lib/pry/testable/pry_tester.rb' - - 'lib/pry/wrapped_module.rb' - # Offense count: 154 Style/Documentation: Enabled: false diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 68dee7ab..bcb4855e 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -349,11 +349,12 @@ class Pry # process and pass a block if one is found pass_block(arg_string) if command_options[:takes_block] - if arg_string - args = command_options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ") - else - args = [] - end + args = + if arg_string + command_options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ") + else + [] + end [val[0..pos].rstrip, arg_string, captures, args] end @@ -390,11 +391,12 @@ class Pry block_init_string = arg_string.slice!(block_index..-1)[1..-1] prime_string = "proc #{block_init_string}\n" - if !Pry::Code.complete_expression?(prime_string) - block_string = _pry_.r(target, prime_string) - else - block_string = prime_string - end + block_string = + if !Pry::Code.complete_expression?(prime_string) + _pry_.r(target, prime_string) + else + prime_string + end begin self.command_block = target.eval(block_string) diff --git a/lib/pry/commands/easter_eggs.rb b/lib/pry/commands/easter_eggs.rb index 755f78e2..c3cf3145 100644 --- a/lib/pry/commands/easter_eggs.rb +++ b/lib/pry/commands/easter_eggs.rb @@ -95,11 +95,12 @@ class Pry \____/ \________________________| EOS - if Helpers::Platform.windows_ansi? - move_up = proc { |n| "\e[#{n}F" } - else - move_up = proc { |n| "\e[#{n}A\e[0G" } - end + move_up = + if Helpers::Platform.windows_ansi? + proc { |n| "\e[#{n}F" } + else + proc { |n| "\e[#{n}A\e[0G" } + end output.puts "\n" * 6 output.puts picture.lines.map(&:chomp).reverse.join(move_up[1]) diff --git a/lib/pry/commands/gist.rb b/lib/pry/commands/gist.rb index 7ce590cf..d9574992 100644 --- a/lib/pry/commands/gist.rb +++ b/lib/pry/commands/gist.rb @@ -72,11 +72,7 @@ class Pry def comment_expression_result_for_gist(result) content = "" result.lines.each_with_index do |line, index| - if index == 0 - content << "# => #{line}" - else - content << "# #{line}" - end + content << index == 0 ? "# => #{line}" : "# #{line}" end content diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index 14500582..a3f1b9ef 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -291,11 +291,7 @@ class Pry when @close_heredocs[@heredoc_queue.first] @heredoc_queue.shift else - if @string_start - @string_start = nil - else - @string_start = token - end + @string_start = @string_start ? nil : token end end diff --git a/lib/pry/testable/pry_tester.rb b/lib/pry/testable/pry_tester.rb index e6c3a61e..6572c2e8 100644 --- a/lib/pry/testable/pry_tester.rb +++ b/lib/pry/testable/pry_tester.rb @@ -23,11 +23,12 @@ class Pry end @history.push str if @history - if @pry.process_command(str) - result = last_command_result_or_output - else - result = @pry.evaluate_ruby(str) - end + result = + if @pry.process_command(str) + last_command_result_or_output + else + @pry.evaluate_ruby(str) + end end result diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 563b9087..1a1fea7e 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -268,11 +268,12 @@ class Pry def super(times = 1) return self if times.zero? - if wrapped.is_a?(Class) - sup = ancestors.select { |v| v.is_a?(Class) }[times] - else - sup = ancestors[times] - end + sup = + if wrapped.is_a?(Class) + ancestors.select { |v| v.is_a?(Class) }[times] + else + ancestors[times] + end Pry::WrappedModule(sup) if sup end @@ -368,11 +369,12 @@ class Pry def lines_for_file(file) @lines_for_file ||= {} - if file == Pry.eval_path - @lines_for_file[file] ||= Pry.line_buffer.drop(1) - else - @lines_for_file[file] ||= File.readlines(file) - end + @lines_for_file[file] ||= + if file == Pry.eval_path + Pry.line_buffer.drop(1) + else + File.readlines(file) + end end end end