mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
rubocop: fix ofences of the Style/BlockDelimiters cop
This commit is contained in:
parent
f1fc421d73
commit
f829360909
17 changed files with 86 additions and 92 deletions
|
@ -732,16 +732,6 @@ Style/AsciiComments:
|
|||
- 'lib/pry/pry_instance.rb'
|
||||
- 'lib/pry/terminal.rb'
|
||||
|
||||
# Offense count: 51
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods.
|
||||
# SupportedStyles: line_count_based, semantic, braces_for_chaining
|
||||
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
||||
# FunctionalMethods: let, let!, subject, watch
|
||||
# IgnoredMethods: lambda, proc, it
|
||||
Style/BlockDelimiters:
|
||||
Enabled: false
|
||||
|
||||
# Offense count: 14
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle.
|
||||
|
|
|
@ -88,8 +88,9 @@ class Pry
|
|||
if lines.is_a? String
|
||||
lines = lines.lines
|
||||
end
|
||||
@lines = lines.each_with_index.map { |line, lineno|
|
||||
LOC.new(line, lineno + start_line.to_i) }
|
||||
@lines = lines.each_with_index.map do |line, lineno|
|
||||
LOC.new(line, lineno + start_line.to_i)
|
||||
end
|
||||
@code_type = code_type
|
||||
|
||||
@with_marker = @with_indentation = @with_line_numbers = nil
|
||||
|
|
|
@ -50,11 +50,11 @@ class Pry
|
|||
|
||||
def load_path_completions
|
||||
$LOAD_PATH.flat_map do |path|
|
||||
Dir[path + '/**/*'].map { |f|
|
||||
Dir[path + '/**/*'].map do |f|
|
||||
next if File.directory?(f)
|
||||
|
||||
f.sub!(path + '/', '')
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ module Pry::Command::Ls::JRubyHacks
|
|||
# When removing jruby aliases, we want to keep the alias that is
|
||||
# "least rubbish" according to this metric.
|
||||
def rubbishness(name)
|
||||
name.each_char.map { |x|
|
||||
name.each_char.map do |x|
|
||||
case x
|
||||
when /[A-Z]/
|
||||
1
|
||||
|
@ -43,7 +43,7 @@ module Pry::Command::Ls::JRubyHacks
|
|||
else
|
||||
0
|
||||
end
|
||||
}.inject(&:+) + (name.size / 100.0)
|
||||
end.inject(&:+) + (name.size / 100.0)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,22 +8,22 @@ class Pry
|
|||
end
|
||||
|
||||
def output_self
|
||||
name_value_pairs = @target.eval('local_variables').reject { |e|
|
||||
name_value_pairs = @target.eval('local_variables').reject do |e|
|
||||
@sticky_locals.keys.include?(e.to_sym)
|
||||
}.map { |name|
|
||||
end.map do |name|
|
||||
[name, (@target.eval(name.to_s))]
|
||||
}
|
||||
end
|
||||
format(name_value_pairs).join('')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def format(name_value_pairs)
|
||||
name_value_pairs.sort_by { |_name, value|
|
||||
name_value_pairs.sort_by do |_name, value|
|
||||
value.to_s.size
|
||||
}.reverse.map { |name, value|
|
||||
end.reverse.map do |name, value|
|
||||
colorized_assignment_style(name, format_value(value))
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def colorized_assignment_style(lhs, rhs, desired_width = 7)
|
||||
|
|
|
@ -170,7 +170,7 @@ class Pry::InputCompleter
|
|||
require 'set'
|
||||
candidates = Set.new
|
||||
to_ignore = ignored_modules
|
||||
ObjectSpace.each_object(Module) { |m|
|
||||
ObjectSpace.each_object(Module) do |m|
|
||||
next if (to_ignore.include?(m) rescue true)
|
||||
|
||||
# jruby doesn't always provide #instance_methods() on each
|
||||
|
@ -178,7 +178,7 @@ class Pry::InputCompleter
|
|||
if m.respond_to?(:instance_methods)
|
||||
candidates.merge m.instance_methods(false).collect(&:to_s)
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
select_message(path, receiver, message, candidates.sort)
|
||||
when /^\.([^.]*)$/
|
||||
|
@ -206,7 +206,7 @@ class Pry::InputCompleter
|
|||
end
|
||||
|
||||
def select_message(path, receiver, message, candidates)
|
||||
candidates.grep(/^#{message}/).collect { |e|
|
||||
candidates.grep(/^#{message}/).collect do |e|
|
||||
case e
|
||||
when /^[a-zA-Z_]/
|
||||
path.call(receiver + "." << e)
|
||||
|
@ -214,7 +214,7 @@ class Pry::InputCompleter
|
|||
when *Operators
|
||||
#receiver + " " << e
|
||||
end
|
||||
}.compact
|
||||
end.compact
|
||||
end
|
||||
|
||||
# build_path seperates the input into two parts: path and input.
|
||||
|
|
|
@ -410,9 +410,9 @@ class Pry::Slop
|
|||
heads = options.reject(&:tail?)
|
||||
tails = (options - heads)
|
||||
opts = (heads + tails).select(&:help).map(&:to_s)
|
||||
optstr = opts.each_with_index.map { |o, i|
|
||||
optstr = opts.each_with_index.map do |o, i|
|
||||
(str = @separators[i + 1]) ? [o, str].join("\n") : o
|
||||
}.join("\n")
|
||||
end.join("\n")
|
||||
|
||||
if @commands.any?
|
||||
optstr << "\n" if !optstr.empty?
|
||||
|
|
|
@ -48,10 +48,10 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
it 'should pass arguments of the command to the block' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
@set.command('foo', &probe)
|
||||
@set.run_command(@ctx, 'foo', 1, 2, 3)
|
||||
}.to yield_with_args(1, 2, 3)
|
||||
end.to yield_with_args(1, 2, 3)
|
||||
end
|
||||
|
||||
it 'should use the first argument as context' do
|
||||
|
@ -333,12 +333,12 @@ describe Pry::CommandSet do
|
|||
end
|
||||
|
||||
it 'should provide a :listing for a command that defaults to its name' do
|
||||
@set.command 'foo', "" do;end
|
||||
@set.command('foo', '') {}
|
||||
expect(@set['foo'].options[:listing]).to eq 'foo'
|
||||
end
|
||||
|
||||
it 'should provide a :listing for a command that differs from its name' do
|
||||
@set.command 'foo', "", listing: 'bar' do;end
|
||||
@set.command('foo', '', listing: 'bar') {}
|
||||
expect(@set['foo'].options[:listing]).to eq 'bar'
|
||||
end
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ describe "Pry::Command" do
|
|||
end
|
||||
end
|
||||
|
||||
let(:hooks) {
|
||||
let(:hooks) do
|
||||
h = Pry::Hooks.new
|
||||
h.add_hook('before_jamaica', 'name1') do |i|
|
||||
output.puts 3 - i.to_i
|
||||
|
@ -69,7 +69,7 @@ describe "Pry::Command" do
|
|||
h.add_hook('after_jamaica', 'name4') do |i|
|
||||
output.puts 3 + i.to_i
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
it "should call hooks in the right order" do
|
||||
out = pry_tester(hooks: hooks, commands: @set).process_command('jamaica 2')
|
||||
|
@ -129,7 +129,7 @@ describe "Pry::Command" do
|
|||
end
|
||||
|
||||
describe 'context' do
|
||||
let(:context) {
|
||||
let(:context) do
|
||||
{
|
||||
target: binding,
|
||||
output: StringIO.new,
|
||||
|
@ -137,7 +137,7 @@ describe "Pry::Command" do
|
|||
command_set: @set,
|
||||
pry_instance: Pry.new
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
describe '#setup' do
|
||||
it 'should capture lots of stuff from the hash passed to new before setup' do
|
||||
|
@ -310,52 +310,52 @@ describe "Pry::Command" do
|
|||
|
||||
describe 'tokenize' do
|
||||
it 'should interpolate string with #{} in them' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
cmd = @set.command('random-dent', &probe)
|
||||
|
||||
_foo = 5
|
||||
cmd.new(target: binding).process_line 'random-dent #{1 + 2} #{3 + _foo}'
|
||||
}.to yield_with_args('3', '8')
|
||||
end.to yield_with_args('3', '8')
|
||||
end
|
||||
|
||||
it 'should not fail if interpolation is not needed and target is not set' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
cmd = @set.command('the-book', &probe)
|
||||
|
||||
cmd.new.process_line 'the-book --help'
|
||||
}.to yield_with_args('--help')
|
||||
end.to yield_with_args('--help')
|
||||
end
|
||||
|
||||
it 'should not interpolate commands with :interpolate => false' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
cmd = @set.command('thor', 'norse god', interpolate: false, &probe)
|
||||
|
||||
cmd.new.process_line 'thor %(#{foo})'
|
||||
}.to yield_with_args('%(#{foo})')
|
||||
end.to yield_with_args('%(#{foo})')
|
||||
end
|
||||
|
||||
it 'should use shell-words to split strings' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
cmd = @set.command('eccentrica', &probe)
|
||||
|
||||
cmd.new.process_line %(eccentrica "gallumbits" 'erot''icon' 6)
|
||||
}.to yield_with_args('gallumbits', 'eroticon', '6')
|
||||
end.to yield_with_args('gallumbits', 'eroticon', '6')
|
||||
end
|
||||
|
||||
it 'should split on spaces if shellwords is not used' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
cmd = @set.command('bugblatter-beast', 'would eat its grandmother', shellwords: false, &probe)
|
||||
|
||||
cmd.new.process_line %(bugblatter-beast "of traal")
|
||||
}.to yield_with_args('"of', 'traal"')
|
||||
end.to yield_with_args('"of', 'traal"')
|
||||
end
|
||||
|
||||
it 'should add captures to arguments for regex commands' do
|
||||
expect { |probe|
|
||||
expect do |probe|
|
||||
cmd = @set.command(/perfectly (normal)( beast)?/i, &probe)
|
||||
|
||||
cmd.new.process_line %(Perfectly Normal Beast (honest!))
|
||||
}.to yield_with_args('Normal', ' Beast', '(honest!)')
|
||||
end.to yield_with_args('Normal', ' Beast', '(honest!)')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -392,11 +392,11 @@ describe "Pry::Command" do
|
|||
end
|
||||
|
||||
it "should set the commands' arg_string and captures" do
|
||||
inside = inner_scope { |probe|
|
||||
inside = inner_scope do |probe|
|
||||
cmd = @set.command(/benj(ie|ei)/, &probe)
|
||||
|
||||
cmd.new.process_line %(benjie mouse)
|
||||
}
|
||||
end
|
||||
|
||||
expect(inside.arg_string).to eq("mouse")
|
||||
expect(inside.captures).to eq(['ie'])
|
||||
|
|
|
@ -366,9 +366,9 @@ describe "edit" do
|
|||
it "should write the evaluated command to history" do
|
||||
quote = 'history repeats itself, first as tradegy...'
|
||||
Pry.config.editor = lambda { |file, _line|
|
||||
File.open(file, 'w') { |f|
|
||||
File.open(file, 'w') do |f|
|
||||
f << quote
|
||||
}
|
||||
end
|
||||
nil
|
||||
}
|
||||
@t.process_command 'edit'
|
||||
|
|
|
@ -17,20 +17,20 @@ describe "help" do
|
|||
end
|
||||
|
||||
it 'should display help for a regex command with a "listing"' do
|
||||
@set.command(/bar(.*)/, "Test listing", listing: "foo") do; end
|
||||
@set.command(/bar(.*)/, "Test listing", listing: "foo") { ; }
|
||||
expect(pry_eval('help foo')).to match(/Test listing/)
|
||||
end
|
||||
|
||||
it 'should display help for a command with a spaces in its name' do
|
||||
@set.command "cmd with spaces", "desc of a cmd with spaces" do; end
|
||||
@set.command('cmd with spaces', 'desc of a cmd with spaces') {}
|
||||
expect(pry_eval('help "cmd with spaces"')).to match(/desc of a cmd with spaces/)
|
||||
end
|
||||
|
||||
it 'should display help for all commands with a description' do
|
||||
@set.command(/bar(.*)/, "Test listing", listing: "foo") do; end
|
||||
@set.command "b", "description for b", listing: "foo" do; end
|
||||
@set.command "c" do;end
|
||||
@set.command "d", "" do;end
|
||||
@set.command(/bar(.*)/, "Test listing", listing: "foo") { ; }
|
||||
@set.command('b', 'description for b', listing: 'foo') {}
|
||||
@set.command('c') {}
|
||||
@set.command('d', '') {}
|
||||
|
||||
output = pry_eval('help')
|
||||
expect(output).to match(/Test listing/)
|
||||
|
@ -39,10 +39,10 @@ describe "help" do
|
|||
end
|
||||
|
||||
it "should sort the output of the 'help' command" do
|
||||
@set.command 'faa', "Fooerizes" do; end
|
||||
@set.command 'gaa', "Gooerizes" do; end
|
||||
@set.command 'maa', "Mooerizes" do; end
|
||||
@set.command 'baa', "Booerizes" do; end
|
||||
@set.command('faa', 'Fooerizes') {}
|
||||
@set.command('gaa', 'Gooerizes') {}
|
||||
@set.command('maa', 'Mooerizes') {}
|
||||
@set.command('baa', 'Booerizes') {}
|
||||
|
||||
doc = pry_eval('help')
|
||||
|
||||
|
|
|
@ -61,9 +61,9 @@ describe Pry::Command::ShellCommand do
|
|||
describe "with CDPATH" do
|
||||
let(:cdpath) { File.expand_path(File.join('spec', 'fixtures', 'cdpathdir')) }
|
||||
let(:nonexisting_path) { File.expand_path('nonexisting_path') }
|
||||
let(:long_cdpath) {
|
||||
let(:long_cdpath) do
|
||||
[nonexisting_path, cdpath].join(File::PATH_SEPARATOR)
|
||||
}
|
||||
end
|
||||
|
||||
describe "when it is defined" do
|
||||
before do
|
||||
|
|
|
@ -127,14 +127,14 @@ describe "show-doc" do
|
|||
|
||||
describe "rdoc highlighting" do
|
||||
it "should syntax highlight code in rdoc" do
|
||||
_c = Class.new {
|
||||
_c = Class.new do
|
||||
# This can initialize your class:
|
||||
#
|
||||
# a = _c.new :foo
|
||||
#
|
||||
# @param foo
|
||||
def initialize(foo); end
|
||||
}
|
||||
end
|
||||
t = pry_tester(binding)
|
||||
expect(t.eval("show-doc _c#initialize")).to match(/_c.new :foo/)
|
||||
# I don't want the test to rely on which colour codes are there, just to
|
||||
|
@ -144,12 +144,12 @@ describe "show-doc" do
|
|||
end
|
||||
|
||||
it "should syntax highlight `code` in rdoc" do
|
||||
_c = Class.new {
|
||||
_c = Class.new do
|
||||
# After initializing your class with `_c.new(:foo)`, go have fun!
|
||||
#
|
||||
# @param foo
|
||||
def initialize(foo); end
|
||||
}
|
||||
end
|
||||
|
||||
t = pry_tester(binding)
|
||||
expect(t.eval("show-doc _c#initialize")).to match(/_c.new\(:foo\)/)
|
||||
|
@ -160,14 +160,14 @@ describe "show-doc" do
|
|||
end
|
||||
|
||||
it "should not syntax highlight `` inside code" do
|
||||
_c = Class.new {
|
||||
_c = Class.new do
|
||||
# Convert aligned output (from many shell commands) into nested arrays:
|
||||
#
|
||||
# a = decolumnize `ls -l $HOME`
|
||||
#
|
||||
# @param output
|
||||
def decolumnize(output); end
|
||||
}
|
||||
end
|
||||
|
||||
begin
|
||||
t = pry_tester(binding)
|
||||
|
@ -422,12 +422,15 @@ describe "show-doc" do
|
|||
end
|
||||
|
||||
it 'should display help for a regex command with a "listing"' do
|
||||
@set.command(/bar(.*)/, "Test listing", listing: "foo") do; end
|
||||
@set.command(/bar(.*)/, "Test listing", listing: "foo") { ; }
|
||||
expect(pry_eval('show-doc foo')).to match(/Test listing/)
|
||||
end
|
||||
|
||||
it 'should display help for a command with a spaces in its name' do
|
||||
@set.command "command with spaces", "description of a command with spaces" do; end
|
||||
@set.command(
|
||||
'command with spaces',
|
||||
'description of a command with spaces'
|
||||
) {}
|
||||
expect(pry_eval('show-doc command with spaces')).to match(/description of a command with spaces/)
|
||||
end
|
||||
|
||||
|
|
|
@ -57,11 +57,11 @@ describe "show-source" do
|
|||
end
|
||||
|
||||
it "should find methods even if the object overrides method method" do
|
||||
_c = Class.new {
|
||||
_c = Class.new do
|
||||
def method;
|
||||
98
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
expect(pry_eval(binding, "show-source _c.new.method")).to match(/98/)
|
||||
end
|
||||
|
@ -78,13 +78,13 @@ describe "show-source" do
|
|||
end
|
||||
|
||||
it "should find instance_methods if the class overrides instance_method" do
|
||||
_c = Class.new {
|
||||
_c = Class.new do
|
||||
def method;
|
||||
98
|
||||
end
|
||||
|
||||
def self.instance_method; 789; end
|
||||
}
|
||||
end
|
||||
|
||||
expect(pry_eval(binding, "show-source _c#method")).to match(/98/)
|
||||
end
|
||||
|
@ -688,25 +688,25 @@ describe "show-source" do
|
|||
|
||||
describe "block commands" do
|
||||
it 'should show source for an ordinary command' do
|
||||
@set.command "foo", :body_of_foo do; end
|
||||
@set.command('foo', :body_of_foo) {}
|
||||
|
||||
expect(pry_eval('show-source foo')).to match(/:body_of_foo/)
|
||||
end
|
||||
|
||||
it "should output source of commands using special characters" do
|
||||
@set.command "!%$", "I gots the yellow fever" do; end
|
||||
@set.command('!%$', 'I gots the yellow fever') {}
|
||||
|
||||
expect(pry_eval('show-source !%$')).to match(/yellow fever/)
|
||||
end
|
||||
|
||||
it 'should show source for a command with spaces in its name' do
|
||||
@set.command "foo bar", :body_of_foo_bar do; end
|
||||
@set.command('foo bar', :body_of_foo_bar) {}
|
||||
|
||||
expect(pry_eval('show-source foo bar')).to match(/:body_of_foo_bar/)
|
||||
end
|
||||
|
||||
it 'should show source for a command by listing name' do
|
||||
@set.command(/foo(.*)/, :body_of_foo_bar_regex, listing: "bar") do; end
|
||||
@set.command(/foo(.*)/, :body_of_foo_bar_regex, listing: "bar") { ; }
|
||||
|
||||
expect(pry_eval('show-source bar')).to match(/:body_of_foo_bar_regex/)
|
||||
end
|
||||
|
|
|
@ -66,12 +66,12 @@ describe Pry do
|
|||
expect(Pry.history.to_a.size).to eq 3
|
||||
Pry.history.clear
|
||||
|
||||
File.open(@hist_file_path, 'r') { |fh|
|
||||
File.open(@hist_file_path, 'r') do |fh|
|
||||
file = fh.to_a
|
||||
|
||||
expect(file.length).to eq 3
|
||||
expect(file.any? { |a| a =~ /athos/ }).to eq true
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -322,9 +322,9 @@ describe Pry::Method do
|
|||
end
|
||||
|
||||
it "should find methods defined in modules included into the object's class" do
|
||||
@obj = Class.new {
|
||||
@obj = Class.new do
|
||||
include(Module.new { def meth; 1; end })
|
||||
}.new
|
||||
end.new
|
||||
should_find_method('meth')
|
||||
end
|
||||
|
||||
|
@ -351,11 +351,11 @@ describe Pry::Method do
|
|||
end
|
||||
|
||||
it "should work in the face of an overridden send" do
|
||||
@obj = Class.new {
|
||||
@obj = Class.new do
|
||||
def meth; 1; end
|
||||
|
||||
def send; raise EOFError; end
|
||||
}.new
|
||||
end.new
|
||||
should_find_method('meth')
|
||||
end
|
||||
end
|
||||
|
@ -499,7 +499,7 @@ describe Pry::Method do
|
|||
|
||||
describe 'method aliases' do
|
||||
before do
|
||||
@class = Class.new {
|
||||
@class = Class.new do
|
||||
def eat
|
||||
end
|
||||
|
||||
|
@ -508,7 +508,7 @@ describe Pry::Method do
|
|||
|
||||
def eruct
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'should be able to find method aliases' do
|
||||
|
@ -554,7 +554,7 @@ describe Pry::Method do
|
|||
|
||||
describe '.signature' do
|
||||
before do
|
||||
@class = Class.new {
|
||||
@class = Class.new do
|
||||
def self.standard_arg(arg) end
|
||||
|
||||
def self.block_arg(&block) end
|
||||
|
@ -562,7 +562,7 @@ describe Pry::Method do
|
|||
def self.rest(*splat) end
|
||||
|
||||
def self.optional(option = nil) end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
it 'should print the name of regular args' do
|
||||
|
|
|
@ -72,9 +72,9 @@ describe Pry do
|
|||
|
||||
# YUCK! horrible hack to get round the fact that output is not configured
|
||||
# at the point this message is printed.
|
||||
(class << Pry; self; end).send(:define_method, :puts) { |str|
|
||||
(class << Pry; self; end).send(:define_method, :puts) do |str|
|
||||
putsed = str
|
||||
}
|
||||
end
|
||||
|
||||
@doing_it = lambda {
|
||||
Pry.start(self, input: StringIO.new("Object::TEST_AFTER_RAISE=1\nexit-all\n"), output: StringIO.new)
|
||||
|
|
Loading…
Reference in a new issue