diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2018-10-14 14:23:34 +0800 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2018-10-14 14:40:48 +0800 |
commit | 383f97e3410e7a46ed1779e8aa770f9b3a5efc0b (patch) | |
tree | a34e49cb78c8e6b001742f2574b861749d8308bb | |
parent | e7f01818d36e92c883beb251badb045e5cdaefa7 (diff) | |
download | pry-383f97e3410e7a46ed1779e8aa770f9b3a5efc0b.tar.gz |
rubocop: fix offences of the Layout/EmptyLineBetweenDefs cop
-rw-r--r-- | .rubocop_todo.yml | 6 | ||||
-rw-r--r-- | lib/pry/code/code_range.rb | 1 | ||||
-rw-r--r-- | lib/pry/command.rb | 7 | ||||
-rw-r--r-- | lib/pry/command_set.rb | 1 | ||||
-rw-r--r-- | lib/pry/commands/ls/methods.rb | 1 | ||||
-rw-r--r-- | lib/pry/commands/play.rb | 1 | ||||
-rw-r--r-- | lib/pry/commands/ri.rb | 1 | ||||
-rw-r--r-- | lib/pry/helpers/table.rb | 1 | ||||
-rw-r--r-- | lib/pry/plugins.rb | 1 | ||||
-rw-r--r-- | lib/pry/pry_instance.rb | 2 | ||||
-rw-r--r-- | spec/commands/edit_spec.rb | 1 | ||||
-rw-r--r-- | spec/commands/find_method_spec.rb | 3 | ||||
-rw-r--r-- | spec/commands/gist_spec.rb | 2 | ||||
-rw-r--r-- | spec/commands/play_spec.rb | 16 | ||||
-rw-r--r-- | spec/commands/save_file_spec.rb | 1 | ||||
-rw-r--r-- | spec/commands/show_doc_spec.rb | 2 | ||||
-rw-r--r-- | spec/commands/show_source_spec.rb | 2 | ||||
-rw-r--r-- | spec/fixtures/whereami_helper.rb | 2 | ||||
-rw-r--r-- | spec/method_spec.rb | 55 | ||||
-rw-r--r-- | spec/pry_defaults_spec.rb | 2 |
20 files changed, 84 insertions, 24 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8f176104..46a55d1b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/lib/pry/code/code_range.rb b/lib/pry/code/code_range.rb index 043be02e..bdd3a6d3 100644 --- a/lib/pry/code/code_range.rb +++ b/lib/pry/code/code_range.rb @@ -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 diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 9f23b129..dbac62d2 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -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 diff --git a/lib/pry/command_set.rb b/lib/pry/command_set.rb index ba08df59..8a9a06f8 100644 --- a/lib/pry/command_set.rb +++ b/lib/pry/command_set.rb @@ -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 diff --git a/lib/pry/commands/ls/methods.rb b/lib/pry/commands/ls/methods.rb index c085f421..893df36e 100644 --- a/lib/pry/commands/ls/methods.rb +++ b/lib/pry/commands/ls/methods.rb @@ -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 diff --git a/lib/pry/commands/play.rb b/lib/pry/commands/play.rb index f2faf7f8..34842d1b 100644 --- a/lib/pry/commands/play.rb +++ b/lib/pry/commands/play.rb @@ -53,7 +53,6 @@ class Pry end end - def content_after_options if opts.present?(:open) restrict_to_lines(content, (0..-2)) diff --git a/lib/pry/commands/ri.rb b/lib/pry/commands/ri.rb index 0e7cb5d1..e4e61cf7 100644 --- a/lib/pry/commands/ri.rb +++ b/lib/pry/commands/ri.rb @@ -31,6 +31,7 @@ class Pry @pager = pager super opts end + def page paging_text = StringIO.new yield paging_text diff --git a/lib/pry/helpers/table.rb b/lib/pry/helpers/table.rb index 7bb7bbf0..164206ee 100644 --- a/lib/pry/helpers/table.rb +++ b/lib/pry/helpers/table.rb @@ -73,6 +73,7 @@ class Pry end def ==(other); items == other.to_a end + def to_a; items.to_a end private diff --git a/lib/pry/plugins.rb b/lib/pry/plugins.rb index 8e0e9776..17015b80 100644 --- a/lib/pry/plugins.rb +++ b/lib/pry/plugins.rb @@ -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) diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index ea3ecb5b..cc38c401 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -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. diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index d463fe07..a1b7296e 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -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 diff --git a/spec/commands/find_method_spec.rb b/spec/commands/find_method_spec.rb index 12c8fa34..22610a06 100644 --- a/spec/commands/find_method_spec.rb +++ b/spec/commands/find_method_spec.rb @@ -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 diff --git a/spec/commands/gist_spec.rb b/spec/commands/gist_spec.rb index 3e83eb32..09d1ffa9 100644 --- a/spec/commands/gist_spec.rb +++ b/spec/commands/gist_spec.rb @@ -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 diff --git a/spec/commands/play_spec.rb b/spec/commands/play_spec.rb index 780ab0f8..20df2f4c 100644 --- a/spec/commands/play_spec.rb +++ b/spec/commands/play_spec.rb @@ -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 diff --git a/spec/commands/save_file_spec.rb b/spec/commands/save_file_spec.rb index ab4f18b1..29373a6f 100644 --- a/spec/commands/save_file_spec.rb +++ b/spec/commands/save_file_spec.rb @@ -58,6 +58,7 @@ describe "save-file" do def @o.baby :baby end + def @o.bang :bang end diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb index 59a5ad4f..a2692d54 100644 --- a/spec/commands/show_doc_spec.rb +++ b/spec/commands/show_doc_spec.rb @@ -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 diff --git a/spec/commands/show_source_spec.rb b/spec/commands/show_source_spec.rb index 0254b9eb..9d646b79 100644 --- a/spec/commands/show_source_spec.rb +++ b/spec/commands/show_source_spec.rb @@ -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 diff --git a/spec/fixtures/whereami_helper.rb b/spec/fixtures/whereami_helper.rb index 661e9322..6aea145e 100644 --- a/spec/fixtures/whereami_helper.rb +++ b/spec/fixtures/whereami_helper.rb @@ -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 diff --git a/spec/method_spec.rb b/spec/method_spec.rb index b327661b..23482569 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -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 diff --git a/spec/pry_defaults_spec.rb b/spec/pry_defaults_spec.rb index feffd563..4fa36190 100644 --- a/spec/pry_defaults_spec.rb +++ b/spec/pry_defaults_spec.rb @@ -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 |