mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
rubocop: fix offences of the Style/RegexpLiteral cop
This commit is contained in:
parent
e64541d9c1
commit
4450fa75f0
13 changed files with 28 additions and 47 deletions
|
@ -314,25 +314,6 @@ Style/PerlBackrefs:
|
|||
- 'lib/pry/method.rb'
|
||||
- 'lib/pry/rubygem.rb'
|
||||
|
||||
# Offense count: 28
|
||||
# Cop supports --auto-correct.
|
||||
# Configuration parameters: EnforcedStyle, AllowInnerSlashes.
|
||||
# SupportedStyles: slashes, percent_r, mixed
|
||||
Style/RegexpLiteral:
|
||||
Exclude:
|
||||
- 'lib/pry/cli.rb'
|
||||
- 'lib/pry/command.rb'
|
||||
- 'lib/pry/commands/cat/file_formatter.rb'
|
||||
- 'lib/pry/commands/easter_eggs.rb'
|
||||
- 'lib/pry/commands/edit.rb'
|
||||
- 'lib/pry/helpers/documentation_helpers.rb'
|
||||
- 'lib/pry/indent.rb'
|
||||
- 'lib/pry/input_completer.rb'
|
||||
- 'lib/pry/object_path.rb'
|
||||
- 'lib/pry/rubygem.rb'
|
||||
- 'spec/pry_spec.rb'
|
||||
- 'spec/sticky_locals_spec.rb'
|
||||
|
||||
# Offense count: 12
|
||||
# Cop supports --auto-correct.
|
||||
Style/RescueModifier:
|
||||
|
|
|
@ -193,7 +193,7 @@ Pry::CLI.add_options do
|
|||
|
||||
on(:I=, "Add a path to the $LOAD_PATH", as: Array, delimiter: ":") do |load_path|
|
||||
load_path.map! do |path|
|
||||
/\A\.\// =~ path ? path : File.expand_path(path)
|
||||
%r{\A\./} =~ path ? path : File.expand_path(path)
|
||||
end
|
||||
|
||||
$LOAD_PATH.unshift(*load_path)
|
||||
|
|
|
@ -201,7 +201,7 @@ class Pry
|
|||
case Pry::Method(block).source_file
|
||||
when %r{/pry/.*_commands/(.*).rb}
|
||||
Regexp.last_match(1).capitalize.tr('_', " ")
|
||||
when %r{(pry-\w+)-([\d\.]+([\w\.]+)?)}
|
||||
when /(pry-\w+)-([\d\.]+([\w\.]+)?)/
|
||||
name = Regexp.last_match(1)
|
||||
version = Regexp.last_match(2)
|
||||
"#{name} (v#{version})"
|
||||
|
|
|
@ -21,7 +21,7 @@ class Pry
|
|||
end
|
||||
|
||||
def file_and_line
|
||||
file_name, line_num = file_with_embedded_line.split(/:(?!\/|\\)/)
|
||||
file_name, line_num = file_with_embedded_line.split(%r{:(?!/|\\)})
|
||||
|
||||
[file_name, line_num ? line_num.to_i : nil]
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ class Pry
|
|||
run ".nyancat"
|
||||
end
|
||||
|
||||
command(/!s\/(.*?)\/(.*?)/, "") do |source, dest|
|
||||
command(%r{!s/(.*?)/(.*?)}, "") do |source, dest|
|
||||
eval_string.gsub!(/#{source}/) { dest }
|
||||
run "show-input"
|
||||
end
|
||||
|
|
|
@ -194,7 +194,7 @@ class Pry
|
|||
|
||||
def probably_a_file?(str)
|
||||
[".rb", ".c", ".py", ".yml", ".gemspec"].include?(File.extname(str)) ||
|
||||
str =~ /\/|\\/
|
||||
str =~ %r{/|\\}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,10 +12,10 @@ class Pry
|
|||
|
||||
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 }
|
||||
comment.gsub(%r{<code>(?:\s*\n)?(.*?)\s*</code>}m) { CodeRay.scan(Regexp.last_match(1), :ruby).term }
|
||||
.gsub(%r{<em>(?:\s*\n)?(.*?)\s*</em>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
|
||||
.gsub(%r{<i>(?:\s*\n)?(.*?)\s*</i>}m) { "\e[1m#{Regexp.last_match(1)}\e[0m" }
|
||||
.gsub(%r{<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}`" }
|
||||
|
@ -49,7 +49,7 @@ class Pry
|
|||
# @param [String] code
|
||||
# @return [String]
|
||||
def strip_comments_from_c_code(code)
|
||||
code.sub(/\A\s*\/\*.*?\*\/\s*/m, '')
|
||||
code.sub(%r{\A\s*/\*.*?\*/\s*}m, '')
|
||||
end
|
||||
|
||||
# Given a string that makes up a comment in a source-code file parse out the content
|
||||
|
|
|
@ -257,7 +257,7 @@ class Pry
|
|||
# If the code just before an "if" or "while" token on a line looks like the end of a statement,
|
||||
# then we want to treat that "if" as a singleline, not multiline statement.
|
||||
def end_of_statement?(last_token, last_kind)
|
||||
(last_token =~ /^[)\]}\/]$/ || STATEMENT_END_TOKENS.include?(last_kind))
|
||||
(last_token =~ %r{^[)\]\}/]$} || STATEMENT_END_TOKENS.include?(last_kind))
|
||||
end
|
||||
|
||||
# Are we currently in the middle of a string literal.
|
||||
|
|
|
@ -6,7 +6,7 @@ class Pry
|
|||
ARRAY_REGEXP = /^([^\]]*\])\.([^.]*)$/.freeze
|
||||
SYMBOL_REGEXP = /^(:[^:.]*)$/.freeze
|
||||
SYMBOL_METHOD_CALL_REGEXP = /^(:[^:.]+)\.([^.]*)$/.freeze
|
||||
REGEX_REGEXP = /^(\/[^\/]*\/)\.([^.]*)$/.freeze
|
||||
REGEX_REGEXP = %r{^(/[^/]*/)\.([^.]*)$}.freeze
|
||||
PROC_OR_HASH_REGEXP = /^([^\}]*\})\.([^.]*)$/.freeze
|
||||
TOPLEVEL_LOOKUP_REGEXP = /^::([A-Z][^:\.\(]*)$/.freeze
|
||||
CONSTANT_REGEXP = /^([A-Z][A-Za-z0-9]*)$/.freeze
|
||||
|
@ -220,10 +220,10 @@ class Pry
|
|||
# path is a proc that takes an input and builds a full path.
|
||||
def build_path(input)
|
||||
# check to see if the input is a regex
|
||||
return proc { |i| i.to_s }, input if input[/\/\./]
|
||||
return proc { |i| i.to_s }, input if input[%r{/\.}]
|
||||
|
||||
trailing_slash = input.end_with?('/')
|
||||
contexts = input.chomp('/').split(/\//)
|
||||
contexts = input.chomp('/').split(%r{/})
|
||||
input = contexts[-1]
|
||||
path = proc do |i|
|
||||
p = contexts[0..-2].push(i).join('/')
|
||||
|
|
|
@ -32,7 +32,7 @@ class Pry
|
|||
|
||||
loop do
|
||||
# Scan for as long as we don't see a slash
|
||||
next_segment << scanner.scan(/[^\/]*/)
|
||||
next_segment << scanner.scan(%r{[^/]*})
|
||||
|
||||
if complete?(next_segment) || scanner.eos?
|
||||
scanner.getch # consume the slash
|
||||
|
|
|
@ -45,7 +45,7 @@ class Pry
|
|||
# @return [Array<String>] completions
|
||||
def complete(so_far)
|
||||
if so_far =~ / ([^ ]*)\z/
|
||||
list(%r{\A#{$2}}).map(&:name)
|
||||
list(/\A#{$2}/).map(&:name)
|
||||
else
|
||||
list.map(&:name)
|
||||
end
|
||||
|
|
|
@ -195,19 +195,19 @@ describe Pry do
|
|||
|
||||
describe "newline stripping from an empty string" do
|
||||
it "with double quotes" do
|
||||
expect(mock_pry('"', '"')).to match(%r{"\\n"})
|
||||
expect(mock_pry('"', "\n", "\n", "\n", '"')).to match(%r{"\\n\\n\\n\\n"})
|
||||
expect(mock_pry('"', '"')).to match(/"\\n"/)
|
||||
expect(mock_pry('"', "\n", "\n", "\n", '"')).to match(/"\\n\\n\\n\\n"/)
|
||||
end
|
||||
|
||||
it "with single quotes" do
|
||||
expect(mock_pry("'", "'")).to match(%r{"\\n"})
|
||||
expect(mock_pry("'", "\n", "\n", "\n", "'")).to match(%r{"\\n\\n\\n\\n"})
|
||||
expect(mock_pry("'", "'")).to match(/"\\n"/)
|
||||
expect(mock_pry("'", "\n", "\n", "\n", "'")).to match(/"\\n\\n\\n\\n"/)
|
||||
end
|
||||
|
||||
it "with fancy delimiters" do
|
||||
expect(mock_pry('%(', ')')).to match(%r{"\\n"})
|
||||
expect(mock_pry('%|', "\n", "\n", '|')).to match(%r{"\\n\\n\\n"})
|
||||
expect(mock_pry('%q[', "\n", "\n", ']')).to match(%r{"\\n\\n\\n"})
|
||||
expect(mock_pry('%(', ')')).to match(/"\\n"/)
|
||||
expect(mock_pry('%|', "\n", "\n", '|')).to match(/"\\n\\n\\n"/)
|
||||
expect(mock_pry('%q[', "\n", "\n", ']')).to match(/"\\n\\n\\n"/)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -224,9 +224,9 @@ describe Pry do
|
|||
|
||||
describe "newline from an empty heredoc" do
|
||||
it "works" do
|
||||
expect(mock_pry('<<HERE', 'HERE')).to match(%r{""})
|
||||
expect(mock_pry("<<'HERE'", "\n", 'HERE')).to match(%r{"\\n"})
|
||||
expect(mock_pry("<<-'HERE'", "\n", "\n", 'HERE')).to match(%r{"\\n\\n"})
|
||||
expect(mock_pry('<<HERE', 'HERE')).to match(/""/)
|
||||
expect(mock_pry("<<'HERE'", "\n", 'HERE')).to match(/"\\n"/)
|
||||
expect(mock_pry("<<-'HERE'", "\n", "\n", 'HERE')).to match(/"\\n\\n"/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -46,10 +46,10 @@ describe "Sticky locals (_file_ and friends)" do
|
|||
end
|
||||
|
||||
expect(pry_eval('file-and-dir-test', 'cd 0', '_file_'))
|
||||
.to match(/\/blah\/ostrich\.rb/)
|
||||
.to match(%r{/blah/ostrich\.rb})
|
||||
|
||||
expect(pry_eval('file-and-dir-test', 'cd 0', '_dir_'))
|
||||
.to match(/\/blah/)
|
||||
.to match(%r{/blah})
|
||||
|
||||
Pry.config.commands.delete "file-and-dir-test"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue