Skip to content

Commit

Permalink
Rubocop: use %r for all regular expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
parkr committed Jun 3, 2016
1 parent 52fcd69 commit f5a0db9
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 91 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Style/RedundantReturn:
Style/RedundantSelf:
Enabled: false
Style/RegexpLiteral:
EnforcedStyle: slashes
EnforcedStyle: percent_r
Style/RescueModifier:
Enabled: false
Style/SignalException:
Expand Down
54 changes: 27 additions & 27 deletions features/step_definitions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@

#

Given(/^I have a blank site in "(.*)"$/) do |path|
Given(%r!^I have a blank site in "(.*)"$!) do |path|
unless File.exist?(path)
then FileUtils.mkdir_p(path)
end
end

#

Given(/^I do not have a "(.*)" directory$/) do |path|
Given(%r!^I do not have a "(.*)" directory$!) do |path|
Paths.test_dir.join(path).directory?
end

#

Given(/^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$/) do |file, key, value, text|
Given(%r!^I have an? "(.*)" page(?: with (.*) "(.*)")? that contains "(.*)"$!) do |file, key, value, text|
File.write(file, Jekyll::Utils.strip_heredoc(<<-DATA))
---
#{key || "layout"}: #{value || "nil"}
Expand All @@ -40,13 +40,13 @@

#

Given(/^I have an? "(.*)" file that contains "(.*)"$/) do |file, text|
Given(%r!^I have an? "(.*)" file that contains "(.*)"$!) do |file, text|
File.write(file, text)
end

#

Given(/^I have an? (.*) (layout|theme) that contains "(.*)"$/) do |name, type, text|
Given(%r!^I have an? (.*) (layout|theme) that contains "(.*)"$!) do |name, type, text|
folder = type == "layout" ? "_layouts" : "_theme"

destination_file = Pathname.new(File.join(folder, "#{name}.html"))
Expand All @@ -56,21 +56,21 @@

#

Given(/^I have an? "(.*)" file with content:$/) do |file, text|
Given(%r!^I have an? "(.*)" file with content:$!) do |file, text|
File.write(file, text)
end

#

Given(/^I have an? (.*) directory$/) do |dir|
Given(%r!^I have an? (.*) directory$!) do |dir|
unless File.directory?(dir)
then FileUtils.mkdir_p(dir)
end
end

#

Given(/^I have the following (draft|page|post)s?(?: (in|under) "([^"]+)")?:$/) do |status, direction, folder, table|
Given(%r!^I have the following (draft|page|post)s?(?: (in|under) "([^"]+)")?:$!) do |status, direction, folder, table|
table.hashes.each do |input_hash|
title = slug(input_hash["title"])
ext = input_hash["type"] || "markdown"
Expand All @@ -92,7 +92,7 @@

#

Given(/^I have a configuration file with "(.*)" set to "(.*)"$/) do |key, value|
Given(%r!^I have a configuration file with "(.*)" set to "(.*)"$!) do |key, value|
config = \
if source_dir.join("_config.yml").exist?
SafeYAML.load_file(source_dir.join("_config.yml"))
Expand All @@ -105,15 +105,15 @@

#

Given(/^I have a configuration file with:$/) do |table|
Given(%r!^I have a configuration file with:$!) do |table|
table.hashes.each do |row|
step %(I have a configuration file with "#{row["key"]}" set to "#{row["value"]}")
end
end

#

Given(/^I have a configuration file with "([^\"]*)" set to:$/) do |key, table|
Given(%r!^I have a configuration file with "([^\"]*)" set to:$!) do |key, table|
File.open("_config.yml", "w") do |f|
f.write("#{key}:\n")
table.hashes.each do |row|
Expand All @@ -124,20 +124,20 @@

#

Given(/^I have fixture collections$/) do
Given(%r!^I have fixture collections$!) do
FileUtils.cp_r Paths.source_dir.join("test", "source", "_methods"), source_dir
FileUtils.cp_r Paths.source_dir.join("test", "source", "_thanksgiving"), source_dir
end

#

Given(/^I wait (\d+) second(s?)$/) do |time, _|
Given(%r!^I wait (\d+) second(s?)$!) do |time, _|
sleep(time.to_f)
end

#

When(/^I run jekyll(.*)$/) do |args|
When(%r!^I run jekyll(.*)$!) do |args|
run_jekyll(args)
if args.include?("--verbose") || ENV["DEBUG"]
$stderr.puts "\n#{jekyll_run_output}\n"
Expand All @@ -146,7 +146,7 @@

#

When(/^I run bundle(.*)$/) do |args|
When(%r!^I run bundle(.*)$!) do |args|
run_bundle(args)
if args.include?("--verbose") || ENV["DEBUG"]
$stderr.puts "\n#{jekyll_run_output}\n"
Expand All @@ -155,21 +155,21 @@

#

When(/^I change "(.*)" to contain "(.*)"$/) do |file, text|
When(%r!^I change "(.*)" to contain "(.*)"$!) do |file, text|
File.open(file, "a") do |f|
f.write(text)
end
end

#

When(/^I delete the file "(.*)"$/) do |file|
When(%r!^I delete the file "(.*)"$!) do |file|
File.delete(file)
end

#

Then(/^the (.*) directory should +(not )?exist$/) do |dir, negative|
Then(%r!^the (.*) directory should +(not )?exist$!) do |dir, negative|
if negative.nil?
expect(Pathname.new(dir)).to exist
else
Expand All @@ -178,7 +178,7 @@
end

#
Then(/^I should (not )?see "(.*)" in "(.*)"$/) do |negative, text, file|
Then(%r!^I should (not )?see "(.*)" in "(.*)"$!) do |negative, text, file|
step %(the "#{file}" file should exist)
regexp = Regexp.new(text, Regexp::MULTILINE)
if negative.nil? || negative.empty?
Expand All @@ -190,20 +190,20 @@

#

Then(/^I should see exactly "(.*)" in "(.*)"$/) do |text, file|
Then(%r!^I should see exactly "(.*)" in "(.*)"$!) do |text, file|
step %(the "#{file}" file should exist)
expect(file_contents(file).strip).to eq text
end

#

Then(/^I should see escaped "(.*)" in "(.*)"$/) do |text, file|
Then(%r!^I should see escaped "(.*)" in "(.*)"$!) do |text, file|
step %(I should see "#{Regexp.escape(text)}" in "#{file}")
end

#

Then(/^the "(.*)" file should +(not )?exist$/) do |file, negative|
Then(%r!^the "(.*)" file should +(not )?exist$!) do |file, negative|
if negative.nil?
expect(Pathname.new(file)).to exist
else
Expand All @@ -213,19 +213,19 @@

#

Then(/^I should see today's time in "(.*)"$/) do |file|
Then(%r!^I should see today's time in "(.*)"$!) do |file|
step %(I should see "#{seconds_agnostic_time(Time.now)}" in "#{file}")
end

#

Then(/^I should see today's date in "(.*)"$/) do |file|
Then(%r!^I should see today's date in "(.*)"$!) do |file|
step %(I should see "#{Date.today}" in "#{file}")
end

#

Then(/^I should (not )?see "(.*)" in the build output$/) do |negative, text|
Then(%r!^I should (not )?see "(.*)" in the build output$!) do |negative, text|
if negative.nil? || negative.empty?
expect(jekyll_run_output).to match Regexp.new(text)
else
Expand All @@ -235,12 +235,12 @@

#

Then(/^I should get a zero exit(?:\-| )status$/) do
Then(%r!^I should get a zero exit(?:\-| )status$!) do
step %(I should see "EXIT STATUS: 0" in the build output)
end

#

Then(/^I should get a non-zero exit(?:\-| )status$/) do
Then(%r!^I should get a non-zero exit(?:\-| )status$!) do
step %(I should not see "EXIT STATUS: 0" in the build output)
end
4 changes: 2 additions & 2 deletions features/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def file_content_from_hash(input_hash)
Jekyll::Utils.strip_heredoc(<<-EOF)
---
#{matter.gsub(
/\n/, "\n "
%r!\n!, "\n "
)}
---
#{content}
Expand Down Expand Up @@ -121,7 +121,7 @@ def run_in_shell(*args)
def slug(title = nil)
if !title
then Time.now.strftime("%s%9N") # nanoseconds since the Epoch
else title.downcase.gsub(/[^\w]/, " ").strip.gsub(/\s+/, "-")
else title.downcase.gsub(%r![^\w]!, " ").strip.gsub(%r!\s+!, "-")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/commands/doctor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def conflicting_urls(site)
def fsnotify_buggy?(_site)
return true unless Utils::Platforms.osx?
if Dir.pwd != `pwd`.strip
Jekyll.logger.error " " + <<-STR.strip.gsub(/\n\s+/, "\n ")
Jekyll.logger.error " " + <<-STR.strip.gsub(%r!\n\s+!, "\n ")
We have detected that there might be trouble using fsevent on your
operating system, you can read https://github.com/thibaudgg/rb-fsevent/wiki/no-fsevents-fired-(OSX-bug)
for possible work arounds or you can work around it immediately
Expand Down
4 changes: 2 additions & 2 deletions lib/jekyll/commands/serve/servlet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ def do_GET(req, res)

private
def validate_and_ensure_charset(_req, res)
key = res.header.keys.grep(/content-type/i).first
key = res.header.keys.grep(%r!content-type!i).first
typ = res.header[key]

unless typ =~ /;\s*charset=/
unless typ =~ %r!;\s*charset=!
res.header[key] = "#{typ}; charset=#{@jekyll_opts["encoding"]}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/converters/markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def custom_processor

private
def custom_class_allowed?(parser_name)
parser_name !~ /[^A-Za-z0-9_]/ && self.class.constants.include?(
parser_name !~ %r![^A-Za-z0-9_]! && self.class.constants.include?(
parser_name.to_sym
)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/converters/markdown/kramdown_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def highlighter
private
def strip_coderay_prefix(hash)
hash.each_with_object({}) do |(key, val), hsh|
cleaned_key = key.gsub(/\Acoderay_/, "")
cleaned_key = key.gsub(%r!\Acoderay_!, "")

if key != cleaned_key
Jekyll::Deprecator.deprecation_message(
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/converters/markdown/redcarpet_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module CommonMethods
def add_code_tags(code, lang)
code = code.to_s
code = code.sub(
/<pre>/,
%r!<pre>!,
"<pre><code class=\"language-#{lang}\" data-lang=\"#{lang}\">"
)
code = code.sub(%r!</pre>!, "</code></pre>")
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/excerpt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def extract_excerpt(doc_content)
if tail.empty?
head
else
"" << head << "\n\n" << tail.scan(/^\[[^\]]+\]:.+$/).join("\n")
"" << head << "\n\n" << tail.scan(%r!^\[[^\]]+\]:.+$!).join("\n")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll/log_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def abort_with(topic, message = nil)
#
# Returns the formatted message
def message(topic, message)
msg = formatted_topic(topic) + message.to_s.gsub(/\s+/, " ")
msg = formatted_topic(topic) + message.to_s.gsub(%r!\s+!, " ")
messages << msg
msg
end
Expand Down
6 changes: 3 additions & 3 deletions lib/jekyll/readers/data_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def read_data_file(path)
end

def sanitize_filename(name)
name.gsub!(/[^\w\s-]+/, "")
name.gsub!(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
name.gsub(/\s+/, "_")
name.gsub!(%r![^\w\s-]+!, "")
name.gsub!(%r!(^|\b\s)\s+($|\s?\b)!, '\\1\\2')
name.gsub(%r!\s+!, "_")
end
end
end
6 changes: 3 additions & 3 deletions lib/jekyll/tags/highlight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class HighlightBlock < Liquid::Block
# forms: name, name=value, or name="<quoted list>"
#
# <quoted list> is a space-separated list of numbers
SYNTAX = /^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$/
SYNTAX = %r!^([a-zA-Z0-9.+#-]+)((\s+\w+(=(\w+|"([0-9]+\s)*[0-9]+"))?)*)$!

def initialize(tag_name, markup, tokens)
super
Expand All @@ -29,7 +29,7 @@ def initialize(tag_name, markup, tokens)
def render(context)
prefix = context["highlighter_prefix"] || ""
suffix = context["highlighter_suffix"] || ""
code = super.to_s.gsub(/\A(\n|\r)+|(\n|\r)+\z/, "")
code = super.to_s.gsub(%r!\A(\n|\r)+|(\n|\r)+\z!, "")

is_safe = !!context.registers[:site].safe

Expand Down Expand Up @@ -67,7 +67,7 @@ def parse_options(input)
options = {}
unless input.empty?
# Split along 3 possible forms -- key="<quoted list>", key=value, or key
input.scan(/(?:\w="[^"]*"|\w=\w|\w)+/) do |opt|
input.scan(%r!(?:\w="[^"]*"|\w=\w|\w)+!) do |opt|
key, value = opt.split("=")
# If a quoted list, convert to array
if value && value.include?("\"")
Expand Down
Loading

0 comments on commit f5a0db9

Please sign in to comment.