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/ConditionalAssignment cop

This commit is contained in:
Kyrylo Silin 2019-03-01 01:24:54 +02:00
parent 017fc06722
commit bd778a3c04
7 changed files with 38 additions and 53 deletions

View file

@ -213,19 +213,6 @@ Style/CommentedKeyword:
Exclude: Exclude:
- 'spec/fixtures/example_nesting.rb' - '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 # Offense count: 154
Style/Documentation: Style/Documentation:
Enabled: false Enabled: false

View file

@ -349,11 +349,12 @@ class Pry
# process and pass a block if one is found # process and pass a block if one is found
pass_block(arg_string) if command_options[:takes_block] pass_block(arg_string) if command_options[:takes_block]
if arg_string args =
args = command_options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ") if arg_string
else command_options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ")
args = [] else
end []
end
[val[0..pos].rstrip, arg_string, captures, args] [val[0..pos].rstrip, arg_string, captures, args]
end end
@ -390,11 +391,12 @@ class Pry
block_init_string = arg_string.slice!(block_index..-1)[1..-1] block_init_string = arg_string.slice!(block_index..-1)[1..-1]
prime_string = "proc #{block_init_string}\n" prime_string = "proc #{block_init_string}\n"
if !Pry::Code.complete_expression?(prime_string) block_string =
block_string = _pry_.r(target, prime_string) if !Pry::Code.complete_expression?(prime_string)
else _pry_.r(target, prime_string)
block_string = prime_string else
end prime_string
end
begin begin
self.command_block = target.eval(block_string) self.command_block = target.eval(block_string)

View file

@ -95,11 +95,12 @@ class Pry
\____/ \________________________| \____/ \________________________|
EOS EOS
if Helpers::Platform.windows_ansi? move_up =
move_up = proc { |n| "\e[#{n}F" } if Helpers::Platform.windows_ansi?
else proc { |n| "\e[#{n}F" }
move_up = proc { |n| "\e[#{n}A\e[0G" } else
end proc { |n| "\e[#{n}A\e[0G" }
end
output.puts "\n" * 6 output.puts "\n" * 6
output.puts picture.lines.map(&:chomp).reverse.join(move_up[1]) output.puts picture.lines.map(&:chomp).reverse.join(move_up[1])

View file

@ -72,11 +72,7 @@ class Pry
def comment_expression_result_for_gist(result) def comment_expression_result_for_gist(result)
content = "" content = ""
result.lines.each_with_index do |line, index| result.lines.each_with_index do |line, index|
if index == 0 content << index == 0 ? "# => #{line}" : "# #{line}"
content << "# => #{line}"
else
content << "# #{line}"
end
end end
content content

View file

@ -291,11 +291,7 @@ class Pry
when @close_heredocs[@heredoc_queue.first] when @close_heredocs[@heredoc_queue.first]
@heredoc_queue.shift @heredoc_queue.shift
else else
if @string_start @string_start = @string_start ? nil : token
@string_start = nil
else
@string_start = token
end
end end
end end

View file

@ -23,11 +23,12 @@ class Pry
end end
@history.push str if @history @history.push str if @history
if @pry.process_command(str) result =
result = last_command_result_or_output if @pry.process_command(str)
else last_command_result_or_output
result = @pry.evaluate_ruby(str) else
end @pry.evaluate_ruby(str)
end
end end
result result

View file

@ -268,11 +268,12 @@ class Pry
def super(times = 1) def super(times = 1)
return self if times.zero? return self if times.zero?
if wrapped.is_a?(Class) sup =
sup = ancestors.select { |v| v.is_a?(Class) }[times] if wrapped.is_a?(Class)
else ancestors.select { |v| v.is_a?(Class) }[times]
sup = ancestors[times] else
end ancestors[times]
end
Pry::WrappedModule(sup) if sup Pry::WrappedModule(sup) if sup
end end
@ -368,11 +369,12 @@ class Pry
def lines_for_file(file) def lines_for_file(file)
@lines_for_file ||= {} @lines_for_file ||= {}
if file == Pry.eval_path @lines_for_file[file] ||=
@lines_for_file[file] ||= Pry.line_buffer.drop(1) if file == Pry.eval_path
else Pry.line_buffer.drop(1)
@lines_for_file[file] ||= File.readlines(file) else
end File.readlines(file)
end
end end
end end
end end