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

This commit is contained in:
Kyrylo Silin 2019-03-02 15:35:35 +02:00
parent 13b10dad38
commit 080d2b0b3a
20 changed files with 222 additions and 68 deletions

View file

@ -33,3 +33,12 @@ Style/ExpandPathArguments:
Exclude:
- 'lib/pry/commands.rb'
- 'pry.gemspec'
Style/Semicolon:
Exclude:
- 'spec/method_spec.rb'
Style/SingleLineMethods:
Exclude:
- 'spec/method_spec.rb'
- 'spec/fixtures/example_nesting.rb'

View file

@ -86,7 +86,7 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 731
Max: 760
# Offense count: 1
# Configuration parameters: CountBlocks.
@ -314,12 +314,6 @@ Style/PerlBackrefs:
- 'lib/pry/method.rb'
- 'lib/pry/rubygem.rb'
# Offense count: 116
# Cop supports --auto-correct.
# Configuration parameters: AllowIfMethodIsEmpty.
Style/SingleLineMethods:
Enabled: false
# Offense count: 8
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.

View file

@ -20,9 +20,13 @@ class Pry
private
def start_line; @start_line; end
def start_line
@start_line
end
def end_line; @end_line; end
def end_line
@end_line
end
# If `end_line` is equal to `nil`, then calculate it from the first
# parameter, `start_line`. Otherwise, leave it as it is.

View file

@ -13,7 +13,9 @@ class Pry
VOID_VALUE = Object.new
# give it a nice inspect
def VOID_VALUE.inspect() "void" end
def VOID_VALUE.inspect
"void"
end
# Properties of the command itself (as passed as arguments to
# {CommandSet#command} or {CommandSet#create_command}).
@ -92,19 +94,33 @@ class Pry
end
# Make those properties accessible to instances
def name; self.class.name; end
def name
self.class.name
end
def match; self.class.match; end
def match
self.class.match
end
def description; self.class.description; end
def description
self.class.description
end
def block; self.class.block; end
def block
self.class.block
end
def command_options; self.class.options; end
def command_options
self.class.options
end
def command_name; self.class.command_name; end
def command_name
self.class.command_name
end
def source; self.class.source; end
def source
self.class.source
end
class << self
def name
@ -274,7 +290,9 @@ class Pry
end
# @return [Object] The value of `self` inside the `target` binding.
def target_self; target.eval('self'); end
def target_self
target.eval('self')
end
# @return [Hash] Pry commands can store arbitrary state
# here. This state persists between subsequent command invocations.
@ -713,6 +731,8 @@ WARN
# gist_method
# end
# end
def process; raise CommandError, "command '#{command_name}' not implemented" end
def process
raise CommandError, "command '#{command_name}' not implemented"
end
end
end

View file

@ -76,9 +76,13 @@ class Pry
@rows_without_colors.transpose
end
def ==(other); items == other.to_a end
def ==(other)
items == other.to_a
end
def to_a; items.to_a end
def to_a
items.to_a
end
private

View file

@ -40,9 +40,13 @@ class Pry
private
def enabled?; !!@enabled; end
def enabled?
!!@enabled
end
def output; @output; end
def output
@output
end
# Return an instance of the "best" available pager class --
# `SystemPager` if possible, `SimplePager` if `SystemPager` isn't

View file

@ -671,9 +671,13 @@ class Pry
end
end
def raise_up(*args); raise_up_common(false, *args); end
def raise_up(*args)
raise_up_common(false, *args)
end
def raise_up!(*args); raise_up_common(true, *args); end
def raise_up!(*args)
raise_up_common(true, *args)
end
# Convenience accessor for the `quiet` config key.
# @return [Boolean]

View file

@ -586,7 +586,9 @@ describe Pry::CommandSet do
it 'should return Result.new(true, VOID) if the command is not keep_retval' do
@set.create_command('mrs-cake') do
def process; 42; end
def process
42
end
end
result = @set.process_line('mrs-cake')
@ -597,7 +599,9 @@ describe Pry::CommandSet do
it 'should return Result.new(true, retval) if the command is keep_retval' do
@set.create_command('magrat', 'the maiden', keep_retval: true) do
def process; 42; end
def process
42
end
end
result = @set.process_line('magrat')
@ -649,7 +653,11 @@ describe Pry::CommandSet do
end
it "should delegate to commands" do
@set.create_command('susan') { def complete(_search); ['--foo']; end }
@set.create_command('susan') do
def complete(_search)
['--foo']
end
end
expect(@set.complete('susan ')).to eq ['--foo']
end
end

View file

@ -5,7 +5,9 @@ describe "edit" do
@old_editor = Pry.config.editor
@file = @line = @contents = nil
Pry.config.editor = lambda do |file, line|
@file = file; @line = line; @contents = File.read(@file)
@file = file
@line = line
@contents = File.read(@file)
nil
end
end
@ -141,7 +143,9 @@ describe "edit" do
before do
@reloading = nil
Pry.config.editor = lambda do |file, line, reloading|
@file = file; @line = line; @reloading = reloading
@file = file
@line = line
@reloading = reloading
nil
end
end
@ -162,7 +166,9 @@ describe "edit" do
@pry.last_exception = exception
end
def last_exception; @pry.last_exception; end
def last_exception
@pry.last_exception
end
end
end
@ -414,6 +420,7 @@ describe "edit" do
tester
end
# rubocop:disable Style/SingleLineMethods
it 'uses patch editing on methods that were previously patched' do
# initial definition
tester = pry_tester binding
@ -435,6 +442,7 @@ describe "edit" do
# original file is unchanged
expect(File.readlines(filename)[line - 1].strip).to eq 'def m; 1; end'
end
# rubocop:enable Style/SingleLineMethods
it 'can repeatedly edit methods that were defined in the console' do
# initial definition
@ -515,7 +523,8 @@ describe "edit" do
before do
@file = @line = @contents = nil
Pry.config.editor = lambda do |file, line|
@file = file; @line = line
@file = file
@line = line
nil
end
end
@ -733,7 +742,9 @@ describe "edit" do
before do
@file = @line = @reloading = nil
Pry.config.editor = lambda do |file, line, reloading|
@file = file; @line = line; @reloading = reloading
@file = file
@line = line
@reloading = reloading
nil
end
end

View file

@ -13,14 +13,18 @@ describe 'gist' do
# In absence of normal mocking, just monkeysmash these with no undoing after.
module ::Gist # rubocop:disable Style/ClassAndModuleChildren
class << self
def login!; Pad.gist_calls[:login!] = true end
def login!
Pad.gist_calls[:login!] = true
end
def gist(*args)
Pad.gist_calls[:gist_args] = args
{ 'html_url' => 'http://gist.blahblah' }
end
def copy(content); Pad.gist_calls[:copy_args] = content end
def copy(content)
Pad.gist_calls[:copy_args] = content
end
end
end

View file

@ -23,7 +23,9 @@ describe "show-doc" do
it 'should work even if #call is defined on Symbol' do
class Symbol
def call; 5; end
def call
5
end
end
expect(pry_eval(binding, "show-doc @o.sample_method")).to match(/sample doc/)
end
@ -474,7 +476,9 @@ describe "show-doc" do
# doink-doc
class Jingle
def a; :doink; end
def a
:doink
end
end
class Jangle < Jingle; end
@ -521,7 +525,9 @@ describe "show-doc" do
module Jesus
# alpha-doc
module Alpha
def alpha; :alpha; end
def alpha
:alpha
end
end
module Zeta; end

View file

@ -66,7 +66,11 @@ describe "show-source" do
end
it "should not show the source when a non-extant method is requested" do
_c = Class.new { def method; 98; end }
_c = Class.new do
def method
98
end
end
expect(mock_pry(binding, "show-source _c#wrongmethod")).to match(/Couldn't locate/)
end
@ -82,44 +86,70 @@ describe "show-source" do
98
end
def self.instance_method; 789; end
def self.instance_method
789
end
end
expect(pry_eval(binding, "show-source _c#method")).to match(/98/)
end
it "should find instance methods with self#moo" do
_c = Class.new { def moo; "ve over!"; end }
_c = Class.new do
def moo
"ve over!"
end
end
expect(pry_eval(binding, "cd _c", "show-source self#moo")).to match(/ve over/)
end
it "should not find instance methods with self.moo" do
_c = Class.new { def moo; "ve over!"; end }
_c = Class.new do
def moo
"ve over!"
end
end
expect { pry_eval(binding, 'cd _c', 'show-source self.moo') }.to raise_error(Pry::CommandError, /Couldn't locate/)
end
it "should find normal methods with self.moo" do
_c = Class.new { def self.moo; "ve over!"; end }
_c = Class.new do
def self.moo
"ve over!"
end
end
expect(pry_eval(binding, 'cd _c', 'show-source self.moo')).to match(/ve over/)
end
it "should not find normal methods with self#moo" do
_c = Class.new { def self.moo; "ve over!"; end }
_c = Class.new do
def self.moo
"ve over!"
end
end
expect { pry_eval(binding, 'cd _c', 'show-source self#moo') }.to raise_error(Pry::CommandError, /Couldn't locate/)
end
it "should find normal methods (i.e non-instance methods) by default" do
_c = Class.new { def self.moo; "ve over!"; end }
_c = Class.new do
def self.moo
"ve over!"
end
end
expect(pry_eval(binding, "cd _c", "show-source moo")).to match(/ve over/)
end
it "should find instance methods if no normal methods available" do
_c = Class.new { def moo; "ve over!"; end }
_c = Class.new do
def moo
"ve over!"
end
end
expect(pry_eval(binding, "cd _c", "show-source moo")).to match(/ve over/)
end
@ -280,7 +310,9 @@ describe "show-source" do
end
it "should output source for method objects" do
def @o.hi; puts 'hi world'; end
def @o.hi
puts 'hi world'
end
_meth = @o.method(:hi)
expect(pry_eval(binding, "show-source _meth")).to match(/puts 'hi world'/)
end
@ -700,7 +732,9 @@ describe "show-source" do
describe "create_command commands" do
it 'should show source for a command' do
@set.create_command "foo", "babble" do
def process() :body_of_foo end
def process
:body_of_foo
end
end
expect(pry_eval('show-source foo')).to match(/:body_of_foo/)
end
@ -720,7 +754,9 @@ describe "show-source" do
# rubocop:disable Style/ClassAndModuleChildren
class ::TemporaryCommand < Pry::ClassCommand
match 'temp-command'
def process() :body_of_temp end
def process
:body_of_temp
end
end
# rubocop:enable Style/ClassAndModuleChildren
@ -763,12 +799,16 @@ describe "show-source" do
before do
module Jesus
module Pig
def lillybing; :lillybing; end
def lillybing
:lillybing
end
end
class Brian; end
class Jingle
def a; :doink; end
def a
:doink
end
end
class Jangle < Jingle; include Pig; end
@ -820,7 +860,9 @@ describe "show-source" do
before do
module Jesus
module Alpha
def alpha; :alpha; end
def alpha
:alpha
end
end
module Zeta; end

View file

@ -21,7 +21,9 @@ describe "whereami" do
pry_eval(binding, 'whereami').should =~ /Cor[#]blimey!/
end
def method; "moo"; end
def method
"moo"
end
end
Cor.new.blimey!
Object.remove_const(:Cor)

View file

@ -17,7 +17,9 @@ describe Pry::InputCompleter do
# pry(main)> AMQP::Protocol::Test::ContentOk.name
# => :content_ok
module SymbolyName
def self.name; :symboly_name; end
def self.name
:symboly_name
end
end
@before_completer = Pry.config.completer

View file

@ -37,7 +37,13 @@ RSpec.describe Pry::Config do
describe "bug #1277" do
specify "a local key has precendence over an inherited method of the same name" do
local = described_class.from_hash(output: 'foobar')
local.extend(Module.new { def output(); 'broken'; end })
local.extend(
Module.new do
def output
'broken'
end
end
)
expect(local.output).to eq('foobar')
end
end
@ -185,13 +191,21 @@ RSpec.describe Pry::Config do
end
it "merges an object who returns a Hash through #to_hash" do
obj = Class.new { def to_hash() { epoch: 1 } end }.new
obj = Class.new do
def to_hash
{ epoch: 1 }
end
end.new
@config.merge!(obj)
expect(@config.epoch).to eq(1)
end
it "merges an object who returns a Hash through #to_h" do
obj = Class.new { def to_h() { epoch: 2 } end }.new
obj = Class.new do
def to_h
{ epoch: 2 }
end
end.new
@config.merge!(obj)
expect(@config.epoch).to eq(2)
end

View file

@ -252,7 +252,9 @@ describe Pry::Hooks do
obj.instance_variable_set(:@test_var, nil)
class << obj
attr_accessor :test_var
def call() @test_var = true; end
def call
@test_var = true
end
end
end

View file

@ -1,9 +1,11 @@
describe Pry::Method::Patcher do
# rubocop:disable Style/SingleLineMethods
before do
@x = Object.new
def @x.test; :before; end
@method = Pry::Method(@x.method(:test))
end
# rubocop:enable Style/SingleLineMethods
it "should change the behaviour of the method" do
expect(@x.test).to eq :before

View file

@ -242,7 +242,9 @@ describe "test Pry defaults" do
describe "given an object with an #inspect string" do
it "returns the #<> format of the object (never use inspect)" do
o = Object.new
def o.inspect; "a" * MAX_LENGTH; end
def o.inspect
"a" * MAX_LENGTH
end
expect(Pry.view_clip(o, DEFAULT_OPTIONS)).to match(/#<Object/)
end
@ -268,7 +270,11 @@ describe "test Pry defaults" do
end
it "returns the #inspect of the custom prompt safe objects" do
Barbie = Class.new { def inspect; "life is plastic, it's fantastic" end }
Barbie = Class.new do
def inspect
"life is plastic, it's fantastic"
end
end
Pry.config.prompt_safe_contexts << Barbie
output = Pry.view_clip(Barbie.new, DEFAULT_OPTIONS)
expect(output).to eq "life is plastic, it's fantastic"
@ -278,7 +284,9 @@ describe "test Pry defaults" do
describe "given an object with an #inspect string as long as the maximum specified" do
it "returns the #<> format of the object (never use inspect)" do
o = Object.new
def o.inspect; "a" * DEFAULT_OPTIONS; end
def o.inspect
"a" * DEFAULT_OPTIONS
end
expect(Pry.view_clip(o, DEFAULT_OPTIONS)).to match(/#<Object/)
end
@ -288,7 +296,9 @@ describe "test Pry defaults" do
describe "when the object is a regular one" do
it "returns a string of the #<class name:object idish> format" do
o = Object.new
def o.inspect; "a" * (DEFAULT_OPTIONS + 1); end
def o.inspect
"a" * (DEFAULT_OPTIONS + 1)
end
expect(Pry.view_clip(o, DEFAULT_OPTIONS)).to match(/#<Object/)
end
@ -310,9 +320,13 @@ describe "test Pry defaults" do
c = Class.new
m = Module.new
def c.name; "a" * (MAX_LENGTH + 1); end
def c.name
"a" * (MAX_LENGTH + 1)
end
def m.name; "a" * (MAX_LENGTH + 1); end
def m.name
"a" * (MAX_LENGTH + 1)
end
expect(Pry.view_clip(c, DEFAULT_OPTIONS)).to match(/#<Class/)
expect(Pry.view_clip(m, DEFAULT_OPTIONS)).to match(/#<Module/)
@ -324,9 +338,13 @@ describe "test Pry defaults" do
c = Class.new
m = Module.new
def c.name; "a" * MAX_LENGTH; end
def c.name
"a" * MAX_LENGTH
end
def m.name; "a" * MAX_LENGTH; end
def m.name
"a" * MAX_LENGTH
end
expect(Pry.view_clip(c, DEFAULT_OPTIONS)).to eq c.name
expect(Pry.view_clip(m, DEFAULT_OPTIONS)).to eq m.name

View file

@ -20,7 +20,9 @@ describe Pry do
Pry.config.print = proc do
ex = Exception.new("catch-22")
class << ex
def inspect; raise ex; end
def inspect
raise ex
end
end
raise ex
end

View file

@ -125,7 +125,9 @@ describe Pry::REPL do
it "should raise no exception when indented with a tab" do
ReplTester.start(correct_indent: true, auto_indent: true) do
output = @pry.config.output
def output.tty?; true; end
def output.tty?
true
end
input <<EOS
loop do
break #note the tab here