1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

Merge pull request #1800 from pry/rubocop-layout-empty-line-between-defs

rubocop: fix offences of the Layout/EmptyLineBetweenDefs cop
This commit is contained in:
Kyrylo Silin 2018-10-14 14:54:38 +08:00 committed by GitHub
commit 32c9126d4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 84 additions and 24 deletions

View file

@ -179,12 +179,6 @@ Layout/EmptyLineAfterMagicComment:
- 'lib/pry/terminal.rb' - 'lib/pry/terminal.rb'
- 'pry.gemspec' - 'pry.gemspec'
# Offense count: 44
# Cop supports --auto-correct.
# Configuration parameters: AllowAdjacentOneLineDefs, NumberOfEmptyLines.
Layout/EmptyLineBetweenDefs:
Enabled: false
# Offense count: 24 # Offense count: 24
# Cop supports --auto-correct. # Cop supports --auto-correct.
Layout/EmptyLines: Layout/EmptyLines:

View file

@ -23,6 +23,7 @@ class Pry
private 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 # If `end_line` is equal to `nil`, then calculate it from the first

View file

@ -98,12 +98,19 @@ class Pry
# Make those properties accessible to instances # 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
def source_location; self.class.source_location; end def source_location; self.class.source_location; end
class << self class << self

View file

@ -305,7 +305,6 @@ class Pry
helper_module.class_eval(&block) helper_module.class_eval(&block)
end end
# @return [Array] # @return [Array]
# The list of commands provided by the command set. # The list of commands provided by the command set.
def list_commands def list_commands

View file

@ -37,7 +37,6 @@ class Pry
super || @instance_methods_switch || @ppp_switch || @no_user_opts super || @instance_methods_switch || @ppp_switch || @no_user_opts
end end
# Get a lambda that can be used with `take_while` to prevent over-eager # Get a lambda that can be used with `take_while` to prevent over-eager
# traversal of the Object's ancestry graph. # traversal of the Object's ancestry graph.
def below_ceiling def below_ceiling

View file

@ -53,7 +53,6 @@ class Pry
end end
end end
def content_after_options def content_after_options
if opts.present?(:open) if opts.present?(:open)
restrict_to_lines(content, (0..-2)) restrict_to_lines(content, (0..-2))

View file

@ -31,6 +31,7 @@ class Pry
@pager = pager @pager = pager
super opts super opts
end end
def page def page
paging_text = StringIO.new paging_text = StringIO.new
yield paging_text yield paging_text

View file

@ -73,6 +73,7 @@ class Pry
end 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 private

View file

@ -40,6 +40,7 @@ class Pry
cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4") cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
require cli_options_file require cli_options_file
end end
# Activate the plugin (require the gem - enables/loads the # Activate the plugin (require the gem - enables/loads the
# plugin immediately at point of call, even if plugin is # plugin immediately at point of call, even if plugin is
# disabled) # disabled)

View file

@ -654,7 +654,9 @@ class Pry
raise exception raise exception
end end
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. # Convenience accessor for the `quiet` config key.

View file

@ -162,6 +162,7 @@ describe "edit" do
def last_exception=(exception) def last_exception=(exception)
@pry.last_exception = exception @pry.last_exception = exception
end end
def last_exception; @pry.last_exception; end def last_exception; @pry.last_exception; end
end end
end end

View file

@ -5,12 +5,15 @@ describe "find-method" do
def hello def hello
"timothy" "timothy"
end end
def goodbye def goodbye
"jenny" "jenny"
end end
def tea_tim? def tea_tim?
"timothy" "timothy"
end end
def tea_time? def tea_time?
"polly" "polly"
end end

View file

@ -17,10 +17,12 @@ describe 'gist' do
module ::Gist module ::Gist
class << self class << self
def login!; Pad.gist_calls[:login!] = true end def login!; Pad.gist_calls[:login!] = true end
def gist(*args) def gist(*args)
Pad.gist_calls[:gist_args] = args Pad.gist_calls[:gist_args] = args
{'html_url' => 'http://gist.blahblah'} {'html_url' => 'http://gist.blahblah'}
end end
def copy(content); Pad.gist_calls[:copy_args] = content end def copy(content); Pad.gist_calls[:copy_args] = content end
end end
end end

View file

@ -40,12 +40,14 @@ describe "play" do
it 'should play a file' do it 'should play a file' do
@t.process_command 'play spec/fixtures/whereami_helper.rb' @t.process_command 'play spec/fixtures/whereami_helper.rb'
expect(@t.eval_string).to eq unindent(<<-STR) expect(@t.eval_string).to eq unindent(<<-STR)
# rubocop:disable Layout/EmptyLineBetweenDefs
class Cor class Cor
def a; end def a; end
def b; end def b; end
def c; end def c; end
def d; end def d; end
end end
# rubocop:enable Layout/EmptyLineBetweenDefs
STR STR
end end
@ -53,12 +55,14 @@ describe "play" do
it 'should output file contents with print option' do it 'should output file contents with print option' do
@t.process_command 'play --print spec/fixtures/whereami_helper.rb' @t.process_command 'play --print spec/fixtures/whereami_helper.rb'
expect(@t.last_output).to eq unindent(<<-STR) expect(@t.last_output).to eq unindent(<<-STR)
1: class Cor 1: # rubocop:disable Layout/EmptyLineBetweenDefs
2: def a; end 2: class Cor
3: def b; end 3: def a; end
4: def c; end 4: def b; end
5: def d; end 5: def c; end
6: end 6: def d; end
7: end
8: # rubocop:enable Layout/EmptyLineBetweenDefs
STR STR
end end
end end

View file

@ -58,6 +58,7 @@ describe "save-file" do
def @o.baby def @o.baby
:baby :baby
end end
def @o.bang def @o.bang
:bang :bang
end end

View file

@ -355,6 +355,7 @@ describe "show-doc" do
# hello there froggy # hello there froggy
module M module M
def d; end def d; end
def e; end def e; end
end end
end end
@ -384,6 +385,7 @@ describe "show-doc" do
# goodbye # goodbye
module M module M
def d; end def d; end
def e; end def e; end
end end
end end

View file

@ -559,6 +559,7 @@ describe "show-source" do
module TestHost module TestHost
class M class M
def alpha; end def alpha; end
def beta; end def beta; end
end end
@ -621,6 +622,7 @@ describe "show-source" do
module Muesli module Muesli
def d; end def d; end
def e; end def e; end
end end
end end

View file

@ -1,6 +1,8 @@
# rubocop:disable Layout/EmptyLineBetweenDefs
class Cor class Cor
def a; end def a; end
def b; end def b; end
def c; end def c; end
def d; end def d; end
end end
# rubocop:enable Layout/EmptyLineBetweenDefs

View file

@ -21,31 +21,51 @@ describe Pry::Method do
end end
it 'should look up instance methods first even if methods available and no options provided' do it 'should look up instance methods first even if methods available and no options provided' do
klass = Class.new { def hello; end; def self.hello; end } klass = Class.new do
def hello; end
def self.hello; end
end
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass)) meth = Pry::Method.from_str(:hello, Pry.binding_for(klass))
expect(meth).to eq klass.instance_method(:hello) expect(meth).to eq klass.instance_method(:hello)
end end
it 'should look up instance methods if "instance-methods" option provided' do it 'should look up instance methods if "instance-methods" option provided' do
klass = Class.new { def hello; end; def self.hello; end } klass = Class.new do
def hello; end
def self.hello; end
end
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {"instance-methods" => true}) meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {"instance-methods" => true})
expect(meth).to eq klass.instance_method(:hello) expect(meth).to eq klass.instance_method(:hello)
end end
it 'should look up methods if :methods option provided' do it 'should look up methods if :methods option provided' do
klass = Class.new { def hello; end; def self.hello; end } klass = Class.new do
def hello; end
def self.hello; end
end
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {methods: true}) meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {methods: true})
expect(meth).to eq klass.method(:hello) expect(meth).to eq klass.method(:hello)
end end
it 'should look up instance methods using the Class#method syntax' do it 'should look up instance methods using the Class#method syntax' do
klass = Class.new { def hello; end; def self.hello; end } klass = Class.new do
def hello; end
def self.hello; end
end
meth = Pry::Method.from_str("klass#hello", Pry.binding_for(binding)) meth = Pry::Method.from_str("klass#hello", Pry.binding_for(binding))
expect(meth).to eq klass.instance_method(:hello) expect(meth).to eq klass.instance_method(:hello)
end end
it 'should look up methods using the object.method syntax' do it 'should look up methods using the object.method syntax' do
klass = Class.new { def hello; end; def self.hello; end } klass = Class.new do
def hello; end
def self.hello; end
end
meth = Pry::Method.from_str("klass.hello", Pry.binding_for(binding)) meth = Pry::Method.from_str("klass.hello", Pry.binding_for(binding))
expect(meth).to eq klass.method(:hello) expect(meth).to eq klass.method(:hello)
end end
@ -119,7 +139,10 @@ describe Pry::Method do
end end
it 'should find the super method correctly' do it 'should find the super method correctly' do
a = Class.new{ def gag33; binding; end; def self.line; __LINE__; end } # rubocop:disable Layout/EmptyLineBetweenDefs
a = Class.new { def gag33; binding; end; def self.line; __LINE__; end }
# rubocop:enable Layout/EmptyLineBetweenDefs
b = Class.new(a){ def gag33; super; end } b = Class.new(a){ def gag33; super; end }
g = b.new.gag33 g = b.new.gag33
@ -132,7 +155,10 @@ describe Pry::Method do
it 'should find the right method if a super method exists' do it 'should find the right method if a super method exists' do
a = Class.new{ def gag; binding; end; } a = Class.new{ def gag; binding; end; }
b = Class.new(a){ def gag; super; binding; end; def self.line; __LINE__; end }
# rubocop:disable Layout/EmptyLineBetweenDefs
b = Class.new(a) { def gag; super; binding; end; def self.line; __LINE__; end }
# rubocop:enable Layout/EmptyLineBetweenDefs
m = Pry::Method.from_binding(b.new.gag) m = Pry::Method.from_binding(b.new.gag)
@ -142,7 +168,11 @@ describe Pry::Method do
end end
it "should find the right method from a BasicObject" do it "should find the right method from a BasicObject" do
a = Class.new(BasicObject) { def gag; ::Kernel.binding; end; def self.line; __LINE__; end } # rubocop:disable Layout/EmptyLineBetweenDefs
a = Class.new(BasicObject) do
def gag; ::Kernel.binding; end; def self.line; __LINE__; end
end
# rubocop:enable Layout/EmptyLineBetweenDefs
m = Pry::Method.from_binding(a.new.gag) m = Pry::Method.from_binding(a.new.gag)
expect(m.owner).to eq a expect(m.owner).to eq a
@ -311,7 +341,11 @@ describe Pry::Method do
end end
it "should work in the face of an overridden send" do it "should work in the face of an overridden send" do
@obj = Class.new{ def meth; 1; end; def send; raise EOFError; end }.new @obj = Class.new {
def meth; 1; end
def send; raise EOFError; end
}.new
should_find_method('meth') should_find_method('meth')
end end
end end
@ -507,8 +541,11 @@ describe Pry::Method do
before do before do
@class = Class.new { @class = Class.new {
def self.standard_arg(arg) end def self.standard_arg(arg) end
def self.block_arg(&block) end def self.block_arg(&block) end
def self.rest(*splat) end def self.rest(*splat) end
def self.optional(option=nil) end def self.optional(option=nil) end
} }
end end

View file

@ -316,6 +316,7 @@ describe "test Pry defaults" do
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(c, DEFAULT_OPTIONS)).to match(/#<Class/)
@ -328,6 +329,7 @@ describe "test Pry defaults" do
c, m = Class.new, Module.new c, m = Class.new, 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(c, DEFAULT_OPTIONS)).to eq c.name