1
0
Fork 0
mirror of https://github.com/pry/pry.git synced 2022-11-09 12:35:05 -05:00

rubocop: fix offences of the Layout/DotPosition cop

This commit is contained in:
Kyrylo Silin 2019-02-25 00:11:05 +02:00
parent d37f154150
commit e1f12f1c6c
16 changed files with 103 additions and 111 deletions

View file

@ -20,3 +20,6 @@ Metrics/ModuleLength:
Layout/CommentIndentation:
Exclude:
- 'spec/fixtures/example_nesting.rb'
Layout/MultilineMethodCallIndentation:
EnforcedStyle: indented

View file

@ -13,27 +13,6 @@ Gemspec/RequiredRubyVersion:
Exclude:
- 'pry.gemspec'
# Offense count: 47
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: leading, trailing
Layout/DotPosition:
Exclude:
- 'lib/pry/commands/cat/abstract_formatter.rb'
- 'lib/pry/commands/cat/exception_formatter.rb'
- 'lib/pry/commands/cat/input_expression_formatter.rb'
- 'lib/pry/commands/show_doc.rb'
- 'lib/pry/helpers/documentation_helpers.rb'
- 'lib/pry/wrapped_module.rb'
- 'spec/command_integration_spec.rb'
- 'spec/commands/show_source_spec.rb'
- 'spec/commands/whereami_spec.rb'
- 'spec/completion_spec.rb'
- 'spec/history_spec.rb'
- 'spec/method/patcher_spec.rb'
- 'spec/pry_defaults_spec.rb'
- 'spec/sticky_locals_spec.rb'
# Offense count: 4
# Cop supports --auto-correct.
# Configuration parameters: AllowBorderComment, AllowMarginComment.

View file

@ -5,10 +5,11 @@ class Pry
include Pry::Helpers::BaseHelpers
private
def decorate(content)
content.code_type = code_type
content.between(*between_lines).
with_line_numbers(use_line_numbers?).highlighted
content.between(*between_lines)
.with_line_numbers(use_line_numbers?).highlighted
end
def code_type

View file

@ -15,9 +15,11 @@ class Pry
def format
check_for_errors
set_file_and_dir_locals(backtrace_file, _pry_, _pry_.current_context)
code = decorate(Pry::Code.from_file(backtrace_file).
between(*start_and_end_line_for_code_window).
with_marker(backtrace_line))
code = decorate(
Pry::Code.from_file(backtrace_file)
.between(*start_and_end_line_for_code_window)
.with_marker(backtrace_line)
)
"#{header}#{code}"
end

View file

@ -31,8 +31,8 @@ class Pry
end
def numbered_input_items
@numbered_input_items ||= normalized_expression_range.zip(selected_input_items).
reject { |_, s| s.nil? || s == "" }
@numbered_input_items ||= normalized_expression_range.zip(selected_input_items)
.reject { |_, s| s.nil? || s == "" }
end
def normalized_expression_range

View file

@ -32,9 +32,11 @@ class Pry
# The docs for code_object prepared for display.
def content_for(code_object)
Code.new(render_doc_markup_for(code_object),
start_line_for(code_object), :text).
with_line_numbers(use_line_numbers?).to_s
Code.new(
render_doc_markup_for(code_object),
start_line_for(code_object),
:text
).with_line_numbers(use_line_numbers?).to_s
end
# process the markup (if necessary) and apply colors

View file

@ -4,18 +4,22 @@ class Pry
# This class contains methods useful for extracting
# documentation from methods and classes.
module DocumentationHelpers
YARD_TAGS = %w[
param return option yield attr attr_reader attr_writer deprecate example
raise
].freeze
module_function
def process_rdoc(comment)
comment = comment.dup
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan(Regexp.last_match(1), :ruby).term }.
gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }.
gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }.
gsub(/<tt>(?:\s*\n)?(.*?)\s*<\/tt>/m) { CodeRay.scan(Regexp.last_match(1), :ruby).term }.
gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{Regexp.last_match(1)}\e[0m" }.
gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan(Regexp.last_match(1), :ruby).term }.
gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan(Regexp.last_match(1), :ruby).term}`" }
comment.gsub(/<code>(?:\s*\n)?(.*?)\s*<\/code>/m) { CodeRay.scan(Regexp.last_match(1), :ruby).term }
.gsub(/<em>(?:\s*\n)?(.*?)\s*<\/em>/m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
.gsub(/<i>(?:\s*\n)?(.*?)\s*<\/i>/m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
.gsub(/<tt>(?:\s*\n)?(.*?)\s*<\/tt>/m) { CodeRay.scan(Regexp.last_match(1), :ruby).term }
.gsub(/\B\+(\w+?)\+\B/) { "\e[32m#{Regexp.last_match(1)}\e[0m" }
.gsub(/((?:^[ \t]+.+(?:\n+|\Z))+)/) { CodeRay.scan(Regexp.last_match(1), :ruby).term }
.gsub(/`(?:\s*\n)?([^\e]*?)\s*`/) { "`#{CodeRay.scan(Regexp.last_match(1), :ruby).term}`" }
end
def process_yardoc_tag(comment, tag)
@ -34,10 +38,9 @@ class Pry
end
def process_yardoc(comment)
yard_tags = ["param", "return", "option", "yield", "attr", "attr_reader", "attr_writer",
"deprecate", "example", "raise"]
(yard_tags - ["example"]).inject(comment) { |a, v| process_yardoc_tag(a, v) }.
gsub(/^@(#{yard_tags.join("|")})/) { "\e[33m#{Regexp.last_match(1)}\e[0m" }
(YARD_TAGS - %w[example])
.inject(comment) { |a, v| process_yardoc_tag(a, v) }
.gsub(/^@(#{YARD_TAGS.join("|")})/) { "\e[33m#{Regexp.last_match(1)}\e[0m" }
end
def process_comment_markup(comment)

View file

@ -309,14 +309,16 @@ class Pry
def all_source_locations_by_popularity
return @all_source_locations_by_popularity if @all_source_locations_by_popularity
ims = all_relevant_methods_for(wrapped)
@all_source_locations_by_popularity = ims.group_by { |v| Array(v.source_location).first }.
sort_by do |path, methods|
expanded = File.expand_path(path)
load_order = $LOADED_FEATURES.index { |file| expanded.end_with?(file) }
ims = all_relevant_methods_for(wrapped).group_by do |v|
Array(v.source_location).first
end
[-methods.size, load_order || (1.0 / 0.0)]
end
@all_source_locations_by_popularity = ims.sort_by do |path, methods|
expanded = File.expand_path(path)
load_order = $LOADED_FEATURES.index { |file| expanded.end_with?(file) }
[-methods.size, load_order || (1.0 / 0.0)]
end
end
# We only want methods that have a non-nil `source_location`. We also
@ -324,8 +326,8 @@ class Pry
#
# @return [Array<Pry::Method>]
def all_relevant_methods_for(mod)
methods = all_methods_for(mod).select(&:source_location).
reject { |x| method_defined_by_forwardable_module?(x) }
methods = all_methods_for(mod).select(&:source_location)
.reject { |x| method_defined_by_forwardable_module?(x) }
return methods unless methods.empty?

View file

@ -255,8 +255,8 @@ describe "commands" do
end
end
expect(pry_tester(commands: set).eval('hello #{Pad.bong}')).
to match(/Pad\.bong/)
expect(pry_tester(commands: set).eval('hello #{Pad.bong}'))
.to match(/Pad\.bong/)
end
it 'should NOT try to interpolate pure ruby code (no commands) ' do
@ -274,8 +274,8 @@ describe "commands" do
end
end
expect(pry_tester(commands: set).eval('hello baby')).
to match(/hello baby command/)
expect(pry_tester(commands: set).eval('hello baby'))
.to match(/hello baby command/)
end
it 'should create a command with a space in its name and pass an argument' do
@ -285,8 +285,8 @@ describe "commands" do
end
end
expect(pry_tester(commands: set).eval('hello baby john')).
to match(/hello baby command john/)
expect(pry_tester(commands: set).eval('hello baby john'))
.to match(/hello baby command john/)
end
it 'should create a regex command and be able to invoke it' do
@ -318,8 +318,8 @@ describe "commands" do
end
bong = "bong"
expect(pry_tester(binding, commands: set).eval('hello #{bong}')).
to match(/hello #{bong}/)
expect(pry_tester(binding, commands: set).eval('hello #{bong}'))
.to match(/hello #{bong}/)
end
it 'should create a regex command and arg_string should be interpolated' do
@ -333,9 +333,9 @@ describe "commands" do
bong = 'bong'
bang = 'bang'
expect(pry_tester(binding, commands: set).
eval('hellojohn #{bing} #{bong} #{bang}')).
to match(/hello john #{bing} #{bong} #{bang}/)
expect(pry_tester(binding, commands: set)
.eval('hellojohn #{bing} #{bong} #{bang}'))
.to match(/hello john #{bing} #{bong} #{bang}/)
end
it 'if a regex capture is missing it should be nil' do
@ -543,12 +543,12 @@ describe "commands" do
end
it 'should run a command with no parameter' do
expect(pry_tester(commands: @command_tester).eval('command1')).
to eq "command1\n"
expect(pry_tester(commands: @command_tester).eval('command1'))
.to eq "command1\n"
end
it 'should run a command with one parameter' do
expect(pry_tester(commands: @command_tester).eval('command2 horsey')).
to eq "horsey\n"
expect(pry_tester(commands: @command_tester).eval('command2 horsey'))
.to eq "horsey\n"
end
end

View file

@ -331,14 +331,14 @@ describe "show-source" do
it "should output source of its class if variable doesn't respond to source_location" do
_test_host = TestHost.new
expect(pry_eval(binding, 'show-source _test_host')).
to match(/class TestHost\n.*def hello/)
expect(pry_eval(binding, 'show-source _test_host'))
.to match(/class TestHost\n.*def hello/)
end
it "should output source of its class if constant doesn't respond to source_location" do
TEST_HOST = TestHost.new
expect(pry_eval(binding, 'show-source TEST_HOST')).
to match(/class TestHost\n.*def hello/)
expect(pry_eval(binding, 'show-source TEST_HOST'))
.to match(/class TestHost\n.*def hello/)
Object.remove_const(:TEST_HOST)
end
end
@ -388,38 +388,38 @@ describe "show-source" do
describe "basic functionality, should find top-level module definitions" do
it 'should show source for a class' do
expect(pry_eval('show-source ShowSourceTestClass')).
to match(/class ShowSourceTestClass.*?def alpha/m)
expect(pry_eval('show-source ShowSourceTestClass'))
.to match(/class ShowSourceTestClass.*?def alpha/m)
end
it 'should show source for a super class' do
expect(pry_eval('show-source -s ShowSourceTestClass')).
to match(/class ShowSourceTestSuperClass.*?def alpha/m)
expect(pry_eval('show-source -s ShowSourceTestClass'))
.to match(/class ShowSourceTestSuperClass.*?def alpha/m)
end
it 'should show source for a module' do
expect(pry_eval('show-source ShowSourceTestModule')).
to match(/module ShowSourceTestModule/)
expect(pry_eval('show-source ShowSourceTestModule'))
.to match(/module ShowSourceTestModule/)
end
it 'should show source for an ancestor module' do
expect(pry_eval('show-source -s ShowSourceTestModule')).
to match(/module ShowSourceTestSuperModule/)
expect(pry_eval('show-source -s ShowSourceTestModule'))
.to match(/module ShowSourceTestSuperModule/)
end
it 'should show source for a class when Const = Class.new syntax is used' do
expect(pry_eval('show-source ShowSourceTestClassWeirdSyntax')).
to match(/ShowSourceTestClassWeirdSyntax = Class.new/)
expect(pry_eval('show-source ShowSourceTestClassWeirdSyntax'))
.to match(/ShowSourceTestClassWeirdSyntax = Class.new/)
end
it 'should show source for a super class when Const = Class.new syntax is used' do
expect(pry_eval('show-source -s ShowSourceTestClassWeirdSyntax')).
to match(/class Object/)
expect(pry_eval('show-source -s ShowSourceTestClassWeirdSyntax'))
.to match(/class Object/)
end
it 'should show source for a module when Const = Module.new syntax is used' do
expect(pry_eval('show-source ShowSourceTestModuleWeirdSyntax')).
to match(/ShowSourceTestModuleWeirdSyntax = Module.new/)
expect(pry_eval('show-source ShowSourceTestModuleWeirdSyntax'))
.to match(/ShowSourceTestModuleWeirdSyntax = Module.new/)
end
end

View file

@ -30,8 +30,8 @@ describe "whereami" do
it 'should properly set _file_, _line_ and _dir_' do
class Cor
def blimey!
pry_eval(binding, 'whereami', '_file_').
should == File.expand_path(__FILE__)
pry_eval(binding, 'whereami', '_file_')
.should == File.expand_path(__FILE__)
end
end

View file

@ -46,13 +46,13 @@ describe Pry::InputCompleter do
object.class.send(:class_variable_set, :'@@number', 10)
# check to see if variables are in scope
expect(object.instance_variables.
map { |v| v.to_sym }.
include?(:'@name')).to eq true
expect(object.instance_variables
.map { |v| v.to_sym }
.include?(:'@name')).to eq true
expect(object.class.class_variables.
map { |v| v.to_sym }.
include?(:'@@number')).to eq true
expect(object.class.class_variables
.map { |v| v.to_sym }
.include?(:'@@number')).to eq true
# Complete instance variables.
b = Pry.binding_for(object)

View file

@ -146,9 +146,9 @@ describe Pry do
history = Pry::History.new(file_path: '~/test_history')
error = Class.new(RuntimeError)
expect(File).to receive(:open).
with(File.join(ENV['HOME'].to_s, "/test_history"), 'a', 0600).
and_raise(error)
expect(File).to receive(:open)
.with(File.join(ENV['HOME'].to_s, "/test_history"), 'a', 0600)
.and_raise(error)
expect { history.push 'a line' }.to raise_error error
end

View file

@ -13,8 +13,8 @@ describe Pry::Method::Patcher do
it "should return a new method with new source" do
expect(@method.source.strip).to eq "def @x.test; :before; end"
expect(@method.redefine("def @x.test; :after; end\n").
source.strip).to eq "def @x.test; :after; end"
expect(@method.redefine("def @x.test; :after; end\n")
.source.strip).to eq "def @x.test; :after; end"
end
it "should change the source of new Pry::Method objects" do

View file

@ -373,9 +373,9 @@ 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(:after_session, :my_name) { |out,_,_| out.puts "BYE" }
Pry.config.hooks = Pry::Hooks.new
.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
expect(@str_output.string).to match(/HELLO/)
@ -385,9 +385,9 @@ describe "test Pry defaults" do
@str_output = StringIO.new
Object.new.pry output: @str_output,
hooks: Pry::Hooks.new.
add_hook( :before_session, :my_name) { |out,_,_| out.puts "MORNING" }.
add_hook(:after_session, :my_name) { |out,_,_| out.puts "EVENING" }
hooks: Pry::Hooks.new
.add_hook( :before_session, :my_name) { |out,_,_| out.puts "MORNING" }
.add_hook(:after_session, :my_name) { |out,_,_| out.puts "EVENING" }
expect(@str_output.string).to match(/MORNING/)
expect(@str_output.string).to match(/EVENING/)
@ -396,16 +396,16 @@ describe "test Pry defaults" do
Pry.config.input.rewind
@str_output = StringIO.new
Object.new.pry output: @str_output,
hooks: Pry::Hooks.new.
add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
hooks: Pry::Hooks.new
.add_hook(:before_session, :my_name) { |out,_,_| out.puts "OPEN" }
expect(@str_output.string).to match(/OPEN/)
Pry.config.input.rewind
@str_output = StringIO.new
Object.new.pry output: @str_output,
hooks: Pry::Hooks.new.
add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
hooks: Pry::Hooks.new
.add_hook(:after_session, :my_name) { |out,_,_| out.puts "CLOSE" }
expect(@str_output.string).to match(/CLOSE/)

View file

@ -45,11 +45,11 @@ describe "Sticky locals (_file_ and friends)" do
set_file_and_dir_locals("/blah/ostrich.rb")
end
expect(pry_eval('file-and-dir-test', 'cd 0', '_file_')).
to match(/\/blah\/ostrich\.rb/)
expect(pry_eval('file-and-dir-test', 'cd 0', '_file_'))
.to match(/\/blah\/ostrich\.rb/)
expect(pry_eval('file-and-dir-test', 'cd 0', '_dir_')).
to match(/\/blah/)
expect(pry_eval('file-and-dir-test', 'cd 0', '_dir_'))
.to match(/\/blah/)
Pry.config.commands.delete "file-and-dir-test"
end