Merge pull request #1954 from pry/rubocop-fixes

Various Rubocop fixes
This commit is contained in:
Kyrylo Silin 2019-03-01 01:38:33 +02:00 committed by GitHub
commit e4bfc51d54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 100 additions and 230 deletions

View File

@ -203,14 +203,6 @@ Style/AsciiComments:
Style/CaseEquality:
Enabled: false
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: is_a?, kind_of?
Style/ClassCheck:
Exclude:
- 'lib/pry/pry_class.rb'
# Offense count: 1
Style/ClassVars:
Exclude:
@ -221,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
@ -251,53 +230,6 @@ Style/DoubleNegation:
- 'lib/pry/slop/option.rb'
- 'lib/pry/wrapped_module.rb'
# Offense count: 6
# Cop supports --auto-correct.
Style/EmptyCaseCondition:
Exclude:
- 'lib/pry/command.rb'
- 'lib/pry/commands/cat.rb'
- 'lib/pry/commands/code_collector.rb'
- 'lib/pry/commands/edit.rb'
- 'lib/pry/commands/hist.rb'
- 'lib/pry/commands/watch_expression.rb'
# Offense count: 6
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: empty, nil, both
Style/EmptyElse:
Exclude:
- 'lib/pry/code_object.rb'
- 'lib/pry/config/behavior.rb'
- 'lib/pry/pry_instance.rb'
- 'lib/pry/terminal.rb'
- 'lib/pry/wrapped_module.rb'
# Offense count: 2
# Cop supports --auto-correct.
Style/EmptyLiteral:
Exclude:
- 'lib/pry/pry_instance.rb'
- 'spec/method_spec.rb'
# Offense count: 42
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: compact, expanded
Style/EmptyMethod:
Exclude:
- 'lib/pry/pager.rb'
- 'spec/code_object_spec.rb'
- 'spec/commands/show_doc_spec.rb'
- 'spec/commands/show_source_spec.rb'
- 'spec/completion_spec.rb'
- 'spec/fixtures/candidate_helper1.rb'
- 'spec/fixtures/candidate_helper2.rb'
- 'spec/fixtures/show_source_doc_examples.rb'
- 'spec/method_spec.rb'
- 'spec/wrapped_module_spec.rb'
# Offense count: 2
# Cop supports --auto-correct.
Style/Encoding:

View File

@ -122,8 +122,6 @@ class Pry
Pry::Method(obj)
elsif !obj.is_a?(Module)
Pry::WrappedModule(obj.class)
else
nil
end
end
rescue Pry::RescuableException

View File

@ -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)
@ -495,12 +497,11 @@ WARN
# @param [Array] args The arguments to pass
# @return [Array] A (possibly shorter) array of the arguments to pass
def correct_arg_arity(arity, args)
case
when arity < 0
if arity < 0
args
when arity == 0
elsif arity == 0
[]
when arity > 0
elsif arity > 0
args.values_at(*(0..(arity - 1)).to_a)
end
end

View File

@ -33,10 +33,9 @@ class Pry
end
def process
output = case
when opts.present?(:ex)
output = if opts.present?(:ex)
ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format
when opts.present?(:in)
elsif opts.present?(:in)
InputExpressionFormatter.new(_pry_.input_ring, opts).format
else
FileFormatter.new(args.first, _pry_, opts).format

View File

@ -56,12 +56,11 @@ class Pry
begin
raise CommandError, "Only one of --out, --in, --doc and CODE_OBJECT may be specified." if bad_option_combination?
content = case
when opts.present?(:o)
content = if opts.present?(:o)
pry_output_content
when opts.present?(:i)
elsif opts.present?(:i)
pry_input_content
when opts.present?(:d)
elsif opts.present?(:d)
code_object_doc
else
code_object_source_or_file

View File

@ -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])

View File

@ -183,12 +183,11 @@ class Pry
end
def initial_temp_file_content
case
when opts.present?(:temp)
if opts.present?(:temp)
""
when opts.present?(:in)
elsif opts.present?(:in)
input_expression
when eval_string.strip != ""
elsif eval_string.strip != ""
eval_string
else
_pry_.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || ""

View File

@ -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

View File

@ -45,12 +45,11 @@ class Pry
end
@history =
case
when opts.present?(:head)
if opts.present?(:head)
@history.take_lines(1, opts[:head] || 10)
when opts.present?(:tail)
elsif opts.present?(:tail)
@history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10)
when opts.present?(:show)
elsif opts.present?(:show)
@history.between(opts[:show])
else
@history

View File

@ -36,10 +36,9 @@ class Pry
end
def process
case
when opts.present?(:delete)
if opts.present?(:delete)
delete opts[:delete]
when opts.present?(:list) || args.empty?
elsif opts.present?(:list) || args.empty?
list
else
add_hook

View File

@ -324,8 +324,6 @@ class Pry
elsif @default.respond_to?(name)
value = @default.public_send(name, *args, &block)
self[key] = __dup(value)
else
nil
end
end
@ -347,8 +345,6 @@ class Pry
obj.to_h
elsif obj.respond_to?(:to_hash)
obj.to_hash
else
nil
end
end

View File

@ -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

View File

@ -81,8 +81,7 @@ class Pry
@out.write str
end
def close
end
def close; end
private

View File

@ -237,7 +237,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
def self.view_clip(obj, options = {})
max = options.fetch :max_length, 60
id = options.fetch :id, false
if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max
if obj.is_a?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max
obj.name.to_s
elsif Pry.main == obj
# special-case to support jruby.

View File

@ -373,8 +373,6 @@ class Pry
exception_handler.call(output, result, self)
elsif should_print?
print.call(output, result, self)
else
# nothin'
end
rescue RescuableException => e
# Being uber-paranoid here, given that this exception arose because we couldn't
@ -593,7 +591,7 @@ class Pry
# the array that the prompt stack is stored in
def prompt_stack
@prompt_stack ||= Array.new
@prompt_stack ||= []
end
private :prompt_stack

View File

@ -10,8 +10,6 @@ class Pry
rows, cols = actual_screen_size
if rows.to_i != 0 && cols.to_i != 0
[rows.to_i, cols.to_i]
else
nil
end
end

View File

@ -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

View File

@ -29,8 +29,6 @@ class Pry
def self.from_str(mod_name, target = TOPLEVEL_BINDING)
if safe_to_evaluate?(mod_name, target)
Pry::WrappedModule.new(target.eval(mod_name))
else
nil
end
rescue RescuableException
nil
@ -268,11 +266,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 +367,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

View File

@ -219,15 +219,12 @@ describe Pry::CodeObject do
before do
class ClassyWassy
class Puff
def tiggy
end
def tiggy; end
end
def Puff
end
def Puff; end
def piggy
end
def piggy; end
end
Object.class_eval do

View File

@ -198,26 +198,22 @@ describe "show-doc" do
before do
# god this is boring1
class ShowSourceTestClass
def alpha
end
def alpha; end
end
# god this is boring2
module ShowSourceTestModule
def alpha
end
def alpha; end
end
# god this is boring3
ShowSourceTestClassWeirdSyntax = Class.new do
def beta
end
def beta; end
end
# god this is boring4
ShowSourceTestModuleWeirdSyntax = Module.new do
def beta
end
def beta; end
end
end
@ -273,15 +269,13 @@ describe "show-doc" do
temporary_constants(:AlphaClass, :BetaClass) do
# top-level beta
class BetaClass
def alpha
end
def alpha; end
end
class AlphaClass
# nested beta
class BetaClass
def beta
end
def beta; end
end
end
@ -294,8 +288,7 @@ describe "show-doc" do
class AlphaClass
# nested beta
class BetaClass
def beta
end
def beta; end
end
end
@ -309,8 +302,7 @@ describe "show-doc" do
it 'should show the docs for all monkeypatches defined in different files' do
# local monkeypatch
class TestClassForShowSource
def epsilon
end
def epsilon; end
end
result = pry_eval("show-doc TestClassForShowSource -a")
@ -321,8 +313,7 @@ describe "show-doc" do
describe "messages relating to -a" do
it "displays the original definition by default (not a doc of a monkeypatch)" do
class TestClassForCandidatesOrder
def beta
end
def beta; end
end
result = pry_eval("show-doc TestClassForCandidatesOrder")
@ -334,8 +325,7 @@ describe "show-doc" do
'(when -a not used and more than one candidate exists for class)' do
# Still reading boring tests, eh?
class TestClassForShowSource
def delta
end
def delta; end
end
result = pry_eval('show-doc TestClassForShowSource')

View File

@ -346,34 +346,28 @@ describe "show-source" do
describe "on modules" do
before do
class ShowSourceTestSuperClass
def alpha
end
def alpha; end
end
class ShowSourceTestClass < ShowSourceTestSuperClass
def alpha
end
def alpha; end
end
module ShowSourceTestSuperModule
def alpha
end
def alpha; end
end
module ShowSourceTestModule
include ShowSourceTestSuperModule
def alpha
end
def alpha; end
end
ShowSourceTestClassWeirdSyntax = Class.new do
def beta
end
def beta; end
end
ShowSourceTestModuleWeirdSyntax = Module.new do
def beta
end
def beta; end
end
end
@ -455,14 +449,12 @@ describe "show-source" do
it 'should lookup module name with respect to current context' do
temporary_constants(:AlphaClass, :BetaClass) do
class BetaClass
def alpha
end
def alpha; end
end
class AlphaClass
class BetaClass
def beta
end
def beta; end
end
end
@ -474,8 +466,7 @@ describe "show-source" do
temporary_constants(:AlphaClass) do
class AlphaClass
class BetaClass
def beta
end
def beta; end
end
end
@ -489,8 +480,7 @@ describe "show-source" do
describe "show-source -a" do
it 'should show the source for all monkeypatches defined in different files' do
class TestClassForShowSource
def beta
end
def beta; end
end
result = pry_eval('show-source TestClassForShowSource -a')
@ -500,8 +490,7 @@ describe "show-source" do
it 'should show the source for a class_eval-based monkeypatch' do
TestClassForShowSourceClassEval.class_eval do
def class_eval_method
end
def class_eval_method; end
end
result = pry_eval('show-source TestClassForShowSourceClassEval -a')
@ -521,8 +510,7 @@ describe "show-source" do
it 'should show the source for an instance_eval-based monkeypatch' do
TestClassForShowSourceInstanceEval.instance_eval do
def instance_eval_method
end
def instance_eval_method; end
end
result = pry_eval('show-source TestClassForShowSourceInstanceEval -a')
@ -532,8 +520,7 @@ describe "show-source" do
describe "messages relating to -a" do
it 'indicates all available monkeypatches can be shown with -a when (when -a not used and more than one candidate exists for class)' do
class TestClassForShowSource
def gamma
end
def gamma; end
end
result = pry_eval('show-source TestClassForShowSource')

View File

@ -227,11 +227,9 @@ describe Pry::InputCompleter do
# skip unless Pry::Helpers::Platform.jruby?
m = Module.new do
def self.hash(a, b)
end
def self.hash(a, b); end
def aaaa
end
def aaaa; end
end
completer_test(m, nil, false).call("[].size.aaaa")

View File

@ -1,11 +1,8 @@
# rank 0
class CandidateTest
def test1
end
def test1; end
def test2
end
def test2; end
def test3
end
def test3; end
end

View File

@ -1,8 +1,6 @@
# rank 1
class CandidateTest
def test4
end
def test4; end
def test5
end
def test5; end
end

View File

@ -1,22 +1,18 @@
# used by show_source_spec.rb and show_doc_spec.rb
class TestClassForShowSource
# doc
def alpha
end
def alpha; end
end
class TestClassForShowSourceClassEval
def alpha
end
def alpha; end
end
class TestClassForShowSourceInstanceEval
def alpha
end
def alpha; end
end
# The first definition (find the second one in show_doc_spec.rb).
class TestClassForCandidatesOrder
def alpha
end
def alpha; end
end

View File

@ -508,14 +508,12 @@ describe Pry::Method do
describe 'method aliases' do
before do
@class = Class.new do
def eat
end
def eat; end
alias_method :fress, :eat
alias_method :omnomnom, :fress
def eruct
end
def eruct; end
end
end
@ -554,7 +552,7 @@ describe Pry::Method do
end
it 'should be able to find aliases for methods implemented in C' do
meth = Pry::Method(Hash.new.method(:key?))
meth = Pry::Method({}.method(:key?))
aliases = Set.new(meth.aliases)
expect(aliases).to eq Set.new(["include?", "member?", "has_key?"])

View File

@ -14,8 +14,7 @@ describe Pry::WrappedModule do
# rank 2
class CandidateTest
def test6
end
def test6; end
end
class PitifullyBlank
@ -27,8 +26,7 @@ describe Pry::WrappedModule do
class DoublyNested
# nested docs
class TriplyNested
def nested_method
end
def nested_method; end
end
end
end
@ -103,7 +101,7 @@ describe Pry::WrappedModule do
it 'should return source for deeply nested class' do
expect(Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source).to match(/nested_method/)
expect(Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count).to eq 4
expect(Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count).to eq(3)
end
end