rubocop: fix offences of the Layout/ExtraSpacing cop

This commit is contained in:
Kyrylo Silin 2018-10-13 00:54:00 +08:00
parent 69c7b27f25
commit 4cc13f9a40
28 changed files with 56 additions and 61 deletions

View File

@ -272,12 +272,6 @@ Layout/EndAlignment:
- 'lib/pry/editor.rb'
- 'lib/pry/method.rb'
# Offense count: 53
# Cop supports --auto-correct.
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
Layout/ExtraSpacing:
Enabled: false
# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, IndentationWidth.

View File

@ -1,6 +1,6 @@
source 'https://rubygems.org'
gemspec
gem 'rake', '~> 10.0'
gem 'rake', '~> 10.0'
# For Guard
group :development do

View File

@ -550,8 +550,8 @@ class Pry
# Ensure that subclasses inherit the options, description and
# match from a ClassCommand super class.
def inherited(klass)
klass.match match
klass.description description
klass.match match
klass.description description
klass.command_options options
end

View File

@ -209,7 +209,7 @@ class Pry
# Pry.config.commands.alias_command "lM", "ls -M"
# @example Pass explicit description (overriding default).
# Pry.config.commands.alias_command "lM", "ls -M", :desc => "cutiepie"
def alias_command(match, action, options={})
def alias_command(match, action, options = {})
cmd = find_command(action) or fail "Command: `#{action}` not found"
original_options = cmd.options.dup

View File

@ -28,7 +28,7 @@ class Pry
opt.on :s, :start, "Starting line (defaults to the first line)", :optional_argument => true, :as => Integer
opt.on :e, :end, "Ending line (defaults to the last line)", :optional_argument => true, :as => Integer
opt.on :l, :'line-numbers', "Show line numbers"
opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", :argument => true, :as => Symbol
opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", :argument => true, :as => Symbol
end
def process

View File

@ -30,11 +30,12 @@ class Pry
def backtrace_level
@backtrace_level ||=
begin
bl = if opts[:ex].nil?
ex.bt_index
else
ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
end
bl =
if opts[:ex].nil?
ex.bt_index
else
ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
end
increment_backtrace_level
bl

View File

@ -74,7 +74,7 @@ class Pry
#
# @return [Pry::WrappedModule, Pry::Method, Pry::Command]
def code_object
Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
end
# Given a string and a range, return the `range` lines of that

View File

@ -50,7 +50,7 @@ class Pry
def options(opt)
opt.on :m, :methods, "Show public methods defined on the Object"
opt.on :m, :methods, "Show public methods defined on the Object"
opt.on :M, "instance-methods", "Show public methods defined in a Module or Class"
opt.on :p, :ppp, "Show public, protected (in yellow) and private (in green) methods"
opt.on :q, :quiet, "Show only methods defined on object.singleton_class and object.class"

View File

@ -46,14 +46,14 @@ class Pry
end
end
RDoc::RI.const_set :PryDriver, subclass # hook it up!
RDoc::RI.const_set :PryDriver, subclass # hook it up!
end
# Spin-up an RI insance.
ri = RDoc::RI::PryDriver.new _pry_.pager, :use_stdout => true, :interactive => false
begin
ri.display_names [spec] # Get the documentation (finally!)
ri.display_names [spec] # Get the documentation (finally!)
rescue RDoc::RI::Driver::NotFoundError => e
output.puts "error: '#{e.name}' not found"
end

View File

@ -14,7 +14,7 @@ class Pry
opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors", :as => :count
opt.on :l, "line-numbers", "Show line numbers"
opt.on :b, "base-one", "Show line numbers but start numbering at 1 (useful for `amend-line` and `play` commands)"
opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
opt.on :a, :all, "Show all definitions and monkeypatches of the module/class"
end
def process

View File

@ -13,8 +13,8 @@ class Pry
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{$1}\e[0m" }.
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { "\e[1m#{$1}\e[0m" }.
gsub(/<tt>(?:\s*\n)?(.*?)\s*<\/tt>/m) { CodeRay.scan($1, :ruby).term }.
gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{$1}\e[0m" }.
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan($1, :ruby).term }.
gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{$1}\e[0m" }.
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan($1, :ruby).term }.
gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan($1, :ruby).term}`" }
end

View File

@ -215,7 +215,7 @@ class Pry
# If the list of tokens contains a matching closing token the line should
# not be indented (and thus we should return true).
tokens.each do |token, kind|
is_singleline_if = (SINGLELINE_TOKENS.include?(token)) && end_of_statement?(last_token, last_kind)
is_singleline_if = (SINGLELINE_TOKENS.include?(token)) && end_of_statement?(last_token, last_kind)
is_optional_do = (token == "do" && seen_for_at.include?(add_after - 1))
last_token, last_kind = token, kind unless kind == :space

View File

@ -34,7 +34,7 @@ class Pry::InputCompleter
"yield" ]
Operators = [
"%", "&", "*", "**", "+", "-", "/",
"%", "&", "*", "**", "+", "-", "/",
"<", "<<", "<=", "<=>", "==", "===", "=~", ">", ">=", ">>",
"[]", "[]=", "^", "!", "!=", "!~"
]

View File

@ -28,7 +28,7 @@ class Pry
stack = @current_stack.dup
begin
next_segment = ""
next_segment = ""
loop do
# Scan for as long as we don't see a slash

View File

@ -286,7 +286,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
target = options[:context] || options[:target]
output = options[:show_output] ? options[:output] : StringIO.new
pry = Pry.new(:output => output, :target => target, :commands => options[:commands])
pry = Pry.new(:output => output, :target => target, :commands => options[:commands])
pry.eval command_string
nil
end

View File

@ -298,7 +298,7 @@ class Pry
# speed up source code extraction.
def method_candidates
@method_candidates ||= all_source_locations_by_popularity.map do |group|
methods_sorted_by_source_line = group.last.sort_by(&:source_line)
methods_sorted_by_source_line = group.last.sort_by(&:source_line)
[methods_sorted_by_source_line.first, methods_sorted_by_source_line.last]
end
end

View File

@ -76,7 +76,7 @@ class Pry
file, line = first_method_source_location
return nil if !file.is_a?(String)
@source_location = [file, first_line_of_module_definition(file, line)]
@source_location = [file, first_line_of_module_definition(file, line)]
rescue Pry::RescuableException
nil
end

View File

@ -198,7 +198,7 @@ describe Pry::Code do
specify 'pad multiline units created with edit command' do
multiline_unit = "def am_i_pretty?\n 'yes i am'\n end"
code = Pry::Code.new(multiline_unit).with_line_numbers
middle_line = code.split("\n")[1]
middle_line = code.split("\n")[1]
expect(middle_line).to match(/2: 'yes i am'/)
end

View File

@ -202,7 +202,7 @@ describe Pry::CommandSet do
expect(@set['bar'].options[:interpolate]).to eq @set['foo'].options[:interpolate]
# however some options should not be inherited
expect(@set['bar'].options[:listing]).not_to eq @set['foo'].options[:listing]
expect(@set['bar'].options[:listing]).not_to eq @set['foo'].options[:listing]
expect(@set['bar'].options[:listing]).to eq "bar"
end

View File

@ -787,7 +787,7 @@ describe "edit" do
end
t = pry_tester(BinkyWink.new.m1)
expect { t.process_command "edit -m -n" }.to raise_error(Pry::CommandError, /Cannot find a file for/)
expect { t.process_command "edit -m -n" }.to raise_error(Pry::CommandError, /Cannot find a file for/)
end
it 'errors when a filename arg is passed with --method' do

View File

@ -9,7 +9,7 @@ RSpec.describe "jump-to" do
end
it 'prints an error when trying to jump to the same binding index' do
expect(pry_eval obj, "cd 1", "cd 2", "jump-to 2").to match(/Already/)
expect(pry_eval obj, "cd 1", "cd 2", "jump-to 2").to match(/Already/)
end
it 'prints error when trying to jump to a non-existent binding index' do

View File

@ -4,7 +4,7 @@ require "pry/input_completer"
def completer_test(bind, pry=nil, assert_flag=true)
test = proc {|symbol|
expect(Pry::InputCompleter.new(pry || Readline, pry).call(symbol[0..-2], :target => Pry.binding_for(bind)).include?(symbol)).to eq(assert_flag)}
expect(Pry::InputCompleter.new(pry || Readline, pry).call(symbol[0..-2], :target => Pry.binding_for(bind)).include?(symbol)).to eq(assert_flag)}
return proc {|*symbols| symbols.each(&test) }
end
@ -115,7 +115,7 @@ describe Pry::InputCompleter do
completer_test(binding).call('o.foo')
# trailing slash
expect(Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/')).to eq(true)
expect(Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/')).to eq(true)
end
it 'should complete for arbitrary scopes' do
@ -188,7 +188,7 @@ describe Pry::InputCompleter do
completer_test(binding).call('o.foo')
# trailing slash
expect(Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/')).to eq(true)
expect(Pry::InputCompleter.new(Readline).call('Mod2/', :target => Pry.binding_for(Mod)).include?('Mod2/')).to eq(true)
end
it 'should complete for arbitrary scopes' do

View File

@ -3,7 +3,7 @@ require "shellwords"
RSpec.describe "Hanami integration" do
before :all do
@ruby = RbConfig.ruby.shellescape
@ruby = RbConfig.ruby.shellescape
@pry_dir = File.expand_path(File.join(__FILE__, '../../../lib')).shellescape
end

View File

@ -6,7 +6,7 @@ require "shellwords"
RSpec.describe "Readline" do
before :all do
@ruby = RbConfig.ruby.shellescape
@ruby = RbConfig.ruby.shellescape
@pry_dir = File.expand_path(File.join(__FILE__, '../../../lib')).shellescape
end

View File

@ -21,7 +21,7 @@ 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 { def hello; end; def self.hello; end }
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass))
expect(meth).to eq klass.instance_method(:hello)
end
@ -33,7 +33,7 @@ describe Pry::Method do
end
it 'should look up methods if :methods option provided' do
klass = Class.new { def hello; end; def self.hello; end }
klass = Class.new { def hello; end; def self.hello; end }
meth = Pry::Method.from_str(:hello, Pry.binding_for(klass), {:methods => true})
expect(meth).to eq klass.method(:hello)
end
@ -51,13 +51,13 @@ describe Pry::Method do
end
it 'should NOT look up instance methods using the Class#method syntax if no instance methods defined' do
_klass = Class.new { def self.hello; end }
_klass = Class.new { def self.hello; end }
meth = Pry::Method.from_str("_klass#hello", Pry.binding_for(binding))
expect(meth).to eq nil
end
it 'should NOT look up methods using the object.method syntax if no methods defined' do
_klass = Class.new { def hello; end }
_klass = Class.new { def hello; end }
meth = Pry::Method.from_str("_klass.hello", Pry.binding_for(binding))
expect(meth).to eq nil
end

View File

@ -76,11 +76,11 @@ describe "test Pry defaults" do
Object.new.pry
expect(@str_output.string).to match(/5/)
Pry.config.input = InputTester.new("6")
Pry.config.input = InputTester.new("6")
Object.new.pry
expect(@str_output.string).to match(/5\n.*6/)
Pry.config.input = InputTester.new("7")
Pry.config.input = InputTester.new("7")
@str_output = StringIO.new
Object.new.pry :output => @str_output
expect(@str_output.string).not_to match(/5\n.*6/)
@ -89,7 +89,7 @@ describe "test Pry defaults" do
it "should set the print default, and the default should be overridable" do
new_print = proc { |out, value| out.puts "=> LOL" }
Pry.config.print = new_print
Pry.config.print = new_print
expect(Pry.new.print).to eq Pry.config.print
Object.new.pry :input => InputTester.new("\"test\""), :output => @str_output
@ -147,16 +147,16 @@ describe "test Pry defaults" do
pry = Pry.new
expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt> "]
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt> "]
pry = Pry.new(:prompt => new_prompt)
expect(pry.prompt).to eq new_prompt
expect(get_prompts(pry)).to eq ["A", "A"]
expect(get_prompts(pry)).to eq ["A", "A"]
pry = Pry.new
expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt> "]
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt> "]
end
it 'should set the prompt default, and the default should be overridable (multi prompt)' do
@ -165,16 +165,16 @@ describe "test Pry defaults" do
pry = Pry.new
expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt* "]
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt* "]
pry = Pry.new(:prompt => new_prompt)
expect(pry.prompt).to eq new_prompt
expect(get_prompts(pry)).to eq ["A", "B"]
expect(get_prompts(pry)).to eq ["A", "B"]
pry = Pry.new
expect(pry.prompt).to eq Pry.prompt
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt* "]
expect(get_prompts(pry)).to eq ["test prompt> ", "test prompt* "]
end
describe 'storing and restoring the prompt' do
@ -239,7 +239,7 @@ describe "test Pry defaults" do
end
describe "view_clip used for displaying an object in a truncated format" do
DEFAULT_OPTIONS = {
DEFAULT_OPTIONS = {
max_length: 60
}
MAX_LENGTH = DEFAULT_OPTIONS[:max_length]
@ -379,7 +379,7 @@ describe "test Pry defaults" do
it 'should set the hooks default, and the default should be overridable' do
Pry.config.input = InputTester.new("exit-all")
Pry.config.hooks = Pry::Hooks.new.
add_hook(:before_session, :my_name) { |out,_,_| out.puts "HELLO" }.
add_hook(:before_session, :my_name) { |out,_,_| out.puts "HELLO" }.
add_hook(:after_session, :my_name) { |out,_,_| out.puts "BYE" }
Object.new.pry :output => @str_output

View File

@ -17,10 +17,10 @@ describe Pry::REPL do
output(/^RuntimeError: lorum/)
if defined?(java)
input 'raise java.lang.Exception.new("foo")'
input 'raise java.lang.Exception.new("foo")'
output(/Exception: foo/)
input 'raise java.io.IOException.new("bar")'
input 'raise java.io.IOException.new("bar")'
output(/IOException: bar/)
end
end
@ -67,11 +67,11 @@ describe Pry::REPL do
output ''
prompt(/10.*> $/)
input '_pry_.binding_stack.pop'
input '_pry_.binding_stack.pop'
output(/^=> #<Binding/)
prompt(/main.*> $/)
input '_pry_.binding_stack.pop'
input '_pry_.binding_stack.pop'
output(/^=> #<Binding/)
assert_exited
end
@ -127,7 +127,7 @@ describe Pry::REPL do
ReplTester.start(correct_indent: true, auto_indent: true) do
output=@pry.config.output
def output.tty?; true; end
input <<EOS
input <<EOS
loop do
break #note the tab here
end

View File

@ -204,16 +204,16 @@ describe Pry::WrappedModule do
@c = Class.new(@b)
end
it 'should return superclass for a wrapped class' do
it 'should return superclass for a wrapped class' do
expect(Pry::WrappedModule(@c).super.wrapped).to eq @b
end
it 'should return nth superclass for a wrapped class' do
it 'should return nth superclass for a wrapped class' do
d = Class.new(@c)
expect(Pry::WrappedModule(d).super(2).wrapped).to eq @b
end
it 'should ignore modules when retrieving nth superclass' do
it 'should ignore modules when retrieving nth superclass' do
expect(Pry::WrappedModule(@c).super(2).wrapped).to eq @a
end