Skip to content

Commit

Permalink
rubocop: fix offences of the Layout/EmptyLineBetweenDefs cop
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrylo committed Oct 14, 2018
1 parent e7f0181 commit 383f97e
Show file tree
Hide file tree
Showing 20 changed files with 84 additions and 24 deletions.
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions lib/pry/code/code_range.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def indices_range(lines)
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
Expand Down
7 changes: 7 additions & 0 deletions lib/pry/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,19 @@ def default_options(match)

# 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
Expand Down
1 change: 0 additions & 1 deletion lib/pry/command_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ def helpers(&block)
helper_module.class_eval(&block)
end


# @return [Array]
# The list of commands provided by the command set.
def list_commands
Expand Down
1 change: 0 additions & 1 deletion lib/pry/commands/ls/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def correct_opts?
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
Expand Down
1 change: 0 additions & 1 deletion lib/pry/commands/play.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def show_input
end
end


def content_after_options
if opts.present?(:open)
restrict_to_lines(content, (0..-2))
Expand Down
1 change: 1 addition & 0 deletions lib/pry/commands/ri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def initialize(pager, opts)
@pager = pager
super opts
end

def page
paging_text = StringIO.new
yield paging_text
Expand Down
1 change: 1 addition & 0 deletions lib/pry/helpers/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def columns
end

def ==(other); items == other.to_a end

def to_a; items.to_a end

private
Expand Down
1 change: 1 addition & 0 deletions lib/pry/plugins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def load_cli_options
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)
Expand Down
2 changes: 2 additions & 0 deletions lib/pry/pry_instance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,9 @@ def raise_up_common(force, *args)
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.
Expand Down
1 change: 1 addition & 0 deletions spec/commands/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
def last_exception=(exception)
@pry.last_exception = exception
end

def last_exception; @pry.last_exception; end
end
end
Expand Down
3 changes: 3 additions & 0 deletions spec/commands/find_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
def hello
"timothy"
end

def goodbye
"jenny"
end

def tea_tim?
"timothy"
end

def tea_time?
"polly"
end
Expand Down
2 changes: 2 additions & 0 deletions spec/commands/gist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
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
Expand Down
16 changes: 10 additions & 6 deletions spec/commands/play_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,29 @@
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


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
Expand Down
1 change: 1 addition & 0 deletions spec/commands/save_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
def @o.baby
:baby
end

def @o.bang
:bang
end
Expand Down
2 changes: 2 additions & 0 deletions spec/commands/show_doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ module TestHost
# hello there froggy
module M
def d; end

def e; end
end
end
Expand Down Expand Up @@ -384,6 +385,7 @@ module M
# goodbye
module M
def d; end

def e; end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/commands/show_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def o;end
module TestHost
class M
def alpha; end

def beta; end
end

Expand Down Expand Up @@ -621,6 +622,7 @@ module Muesli

module Muesli
def d; end

def e; end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/fixtures/whereami_helper.rb
Original file line number Diff line number Diff line change
@@ -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
55 changes: 46 additions & 9 deletions spec/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,51 @@
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
Expand Down Expand Up @@ -119,7 +139,10 @@ class << self; undef bar; end
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
Expand All @@ -132,7 +155,10 @@ class << self; undef bar; end

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)

Expand All @@ -142,7 +168,11 @@ class << self; undef bar; end
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
Expand Down Expand Up @@ -311,7 +341,11 @@ class << @obj; def meth; 1; end; end
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
Expand Down Expand Up @@ -507,8 +541,11 @@ class Object
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
Expand Down
2 changes: 2 additions & 0 deletions spec/pry_defaults_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ def o.inspect; "a" * (DEFAULT_OPTIONS + 1); end


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/)
Expand All @@ -328,6 +329,7 @@ def m.name; "a" * (MAX_LENGTH + 1); end
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
Expand Down

0 comments on commit 383f97e

Please sign in to comment.