diff --git a/.rubocop.yml b/.rubocop.yml index ad0fbb03..a0b255d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -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' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 10904b5f..82fde807 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/lib/pry/code/code_range.rb b/lib/pry/code/code_range.rb index 72042179..135be5de 100644 --- a/lib/pry/code/code_range.rb +++ b/lib/pry/code/code_range.rb @@ -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. diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 3c5e26d0..12142bd2 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -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 diff --git a/lib/pry/helpers/table.rb b/lib/pry/helpers/table.rb index fa6b1c78..f015f46b 100644 --- a/lib/pry/helpers/table.rb +++ b/lib/pry/helpers/table.rb @@ -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 diff --git a/lib/pry/pager.rb b/lib/pry/pager.rb index 9ef5ea69..7fb49fcf 100644 --- a/lib/pry/pager.rb +++ b/lib/pry/pager.rb @@ -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 diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index c774bf3d..ab00c116 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -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] diff --git a/spec/command_set_spec.rb b/spec/command_set_spec.rb index e89bff47..e31285bc 100644 --- a/spec/command_set_spec.rb +++ b/spec/command_set_spec.rb @@ -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 diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb index 531a55c8..a5a01d5c 100644 --- a/spec/commands/edit_spec.rb +++ b/spec/commands/edit_spec.rb @@ -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 diff --git a/spec/commands/gist_spec.rb b/spec/commands/gist_spec.rb index 5f6a0015..3630dd57 100644 --- a/spec/commands/gist_spec.rb +++ b/spec/commands/gist_spec.rb @@ -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 diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb index 4153f3a6..76ab44c3 100644 --- a/spec/commands/show_doc_spec.rb +++ b/spec/commands/show_doc_spec.rb @@ -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 diff --git a/spec/commands/show_source_spec.rb b/spec/commands/show_source_spec.rb index d16510e3..b68104d1 100644 --- a/spec/commands/show_source_spec.rb +++ b/spec/commands/show_source_spec.rb @@ -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 diff --git a/spec/commands/whereami_spec.rb b/spec/commands/whereami_spec.rb index b115c5e2..2b56ece8 100644 --- a/spec/commands/whereami_spec.rb +++ b/spec/commands/whereami_spec.rb @@ -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) diff --git a/spec/completion_spec.rb b/spec/completion_spec.rb index ff24530f..5481f2a2 100644 --- a/spec/completion_spec.rb +++ b/spec/completion_spec.rb @@ -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 diff --git a/spec/config_spec.rb b/spec/config_spec.rb index 5f763154..bf75da96 100644 --- a/spec/config_spec.rb +++ b/spec/config_spec.rb @@ -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 diff --git a/spec/hooks_spec.rb b/spec/hooks_spec.rb index f3375761..22bdeb43 100644 --- a/spec/hooks_spec.rb +++ b/spec/hooks_spec.rb @@ -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 diff --git a/spec/method/patcher_spec.rb b/spec/method/patcher_spec.rb index 718b6e15..2408b03f 100644 --- a/spec/method/patcher_spec.rb +++ b/spec/method/patcher_spec.rb @@ -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 diff --git a/spec/pry_defaults_spec.rb b/spec/pry_defaults_spec.rb index ce9f1cef..93164f58 100644 --- a/spec/pry_defaults_spec.rb +++ b/spec/pry_defaults_spec.rb @@ -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(/# 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(/# 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(/#