rubocop: fix offences of the Layout/EmptyLineBetweenDefs cop

This commit is contained in:
Kyrylo Silin 2018-10-14 14:23:34 +08:00
parent e7f01818d3
commit 383f97e341
20 changed files with 84 additions and 24 deletions

View File

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

View File

@ -23,6 +23,7 @@ class Pry
private
def start_line; @start_line; end
def end_line; @end_line; end
# 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
def name; self.class.name; end
def match; self.class.match; end
def description; self.class.description; end
def block; self.class.block; end
def command_options; self.class.options; end
def command_name; self.class.command_name; end
def source; self.class.source; end
def source_location; self.class.source_location; end
class << self

View File

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

View File

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

View File

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

View File

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

View File

@ -73,6 +73,7 @@ class Pry
end
def ==(other); items == other.to_a end
def to_a; items.to_a end
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")
require cli_options_file
end
# Activate the plugin (require the gem - enables/loads the
# plugin immediately at point of call, even if plugin is
# disabled)

View File

@ -654,7 +654,9 @@ class Pry
raise exception
end
end
def raise_up(*args); raise_up_common(false, *args); end
def raise_up!(*args); raise_up_common(true, *args); end
# Convenience accessor for the `quiet` config key.

View File

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

View File

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

View File

@ -17,10 +17,12 @@ describe 'gist' do
module ::Gist
class << self
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
end
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -21,31 +21,51 @@ describe Pry::Method do
end
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))
expect(meth).to eq klass.instance_method(:hello)
end
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})
expect(meth).to eq klass.instance_method(:hello)
end
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})
expect(meth).to eq klass.method(:hello)
end
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))
expect(meth).to eq klass.instance_method(:hello)
end
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))
expect(meth).to eq klass.method(:hello)
end
@ -119,7 +139,10 @@ describe Pry::Method do
end
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 }
g = b.new.gag33
@ -132,7 +155,10 @@ describe Pry::Method do
it 'should find the right method if a super method exists' do
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)
@ -142,7 +168,11 @@ describe Pry::Method do
end
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)
expect(m.owner).to eq a
@ -311,7 +341,11 @@ describe Pry::Method do
end
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')
end
end
@ -507,8 +541,11 @@ describe Pry::Method do
before do
@class = Class.new {
def self.standard_arg(arg) end
def self.block_arg(&block) end
def self.rest(*splat) end
def self.optional(option=nil) end
}
end

View File

@ -316,6 +316,7 @@ describe "test Pry defaults" do
def c.name; "a" * (MAX_LENGTH + 1); end
def m.name; "a" * (MAX_LENGTH + 1); end
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
def c.name; "a" * MAX_LENGTH; end
def m.name; "a" * MAX_LENGTH; end
expect(Pry.view_clip(c, DEFAULT_OPTIONS)).to eq c.name