Skip to content

Commit

Permalink
Enable Style/PercentLiteralDelimiters cop in rubygems
Browse files Browse the repository at this point in the history
So it matches the style used by bundler.
  • Loading branch information
deivid-rodriguez committed Mar 26, 2020
1 parent c948d5a commit ab0580f
Show file tree
Hide file tree
Showing 49 changed files with 309 additions and 306 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Expand Up @@ -89,3 +89,6 @@ Style/MutableConstant:

Style/BlockDelimiters:
Enabled: true

Style/PercentLiteralDelimiters:
Enabled: true
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -76,7 +76,7 @@ namespace :rubocop do
end
end

task rubocop: %w(rubocop:rubygems rubocop:bundler)
task rubocop: %w[rubocop:rubygems rubocop:bundler]

desc "Run a test suite bisection"
task(:bisect) do
Expand Down Expand Up @@ -275,7 +275,7 @@ namespace 'blog' do

history.force_encoding Encoding::UTF_8

_, change_log, = history.split %r%^===\s*\d.*%, 3
_, change_log, = history.split %r{^===\s*\d.*}, 3

change_types = []

Expand Down Expand Up @@ -386,7 +386,7 @@ module Rubygems

def self.all
files = []
exclude = %r[\.git|\./bundler/(?!lib|man|exe|[^/]+\.md|bundler.gemspec)]ox
exclude = %r{\.git|\./bundler/(?!lib|man|exe|[^/]+\.md|bundler.gemspec)}ox
tracked_files = `git ls-files`.split("\n").map {|f| "./#{f}" }

tracked_files.each do |path|
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems.rb
Expand Up @@ -1011,7 +1011,7 @@ def self.plugin_suffix_regexp
def self.suffixes
@suffixes ||= ['',
'.rb',
*%w(DLEXT DLEXT2).map do |key|
*%w[DLEXT DLEXT2].map do |key|
val = RbConfig::CONFIG[key]
next unless val and not val.empty?
".#{val}"
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/setup_command.rb
Expand Up @@ -546,7 +546,7 @@ def remove_old_bin_files(bin_dir)
next unless Gem.win_platform?

File.open "#{old_bin_path}.bat", 'w' do |fp|
fp.puts %{@ECHO.#{deprecation_message}}
fp.puts %(@ECHO.#{deprecation_message})
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/ext/ext_conf_builder.rb
Expand Up @@ -27,7 +27,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil)
# Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
tmp_dest = get_relative_path(tmp_dest)

Tempfile.open %w"siteconf .rb", "." do |siteconf|
Tempfile.open %w[siteconf .rb], "." do |siteconf|
siteconf.puts "require 'rbconfig'"
siteconf.puts "dest_path = #{tmp_dest.dump}"
%w[sitearchdir sitelibdir].each do |dir|
Expand Down
8 changes: 4 additions & 4 deletions lib/rubygems/safe_yaml.rb
Expand Up @@ -7,7 +7,7 @@ module Gem
# Psych.safe_load

module SafeYAML
PERMITTED_CLASSES = %w(
PERMITTED_CLASSES = %w[
Symbol
Time
Date
Expand All @@ -19,12 +19,12 @@ module SafeYAML
Gem::Version::Requirement
YAML::Syck::DefaultKey
Syck::DefaultKey
).freeze
].freeze

PERMITTED_SYMBOLS = %w(
PERMITTED_SYMBOLS = %w[
development
runtime
).freeze
].freeze

if ::YAML.respond_to? :safe_load
def self.safe_load(input)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/server.rb
Expand Up @@ -573,7 +573,7 @@ def quick(req, res)
add_date res

case req.request_uri.path
when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)\.gemspec\.rz$| then
when %r{^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)\.gemspec\.rz$} then
marshal_format, full_name = $1, $2
specs = Gem::Specification.find_all_by_full_name(full_name)

Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/source/git.rb
Expand Up @@ -228,8 +228,8 @@ def uri_hash # :nodoc:
require 'digest' # required here to avoid deadlocking in Gem.activate_bin_path (because digest is a gem on 2.5+)

normalized =
if @repository =~ %r%^\w+://(\w+@)?%
uri = URI(@repository).normalize.to_s.sub %r%/$%,''
if @repository =~ %r{^\w+://(\w+@)?}
uri = URI(@repository).normalize.to_s.sub %r{/$},''
uri.sub(/\A(\w+)/) { $1.downcase }
else
@repository
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/specification.rb
Expand Up @@ -2188,7 +2188,7 @@ def pretty_print(q) # :nodoc:

attributes.each do |attr_name|
current_value = self.send attr_name
current_value = current_value.sort if %i(files test_files).include? attr_name
current_value = current_value.sort if %i[files test_files].include? attr_name
if current_value != default_value(attr_name) or
self.class.required_attribute? attr_name

Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/test_case.rb
Expand Up @@ -576,7 +576,7 @@ def have_git?
end

def in_path?(executable) # :nodoc:
return true if %r%\A([A-Z]:|/)% =~ executable and File.exist? executable
return true if %r{\A([A-Z]:|/)} =~ executable and File.exist? executable

ENV['PATH'].split(File::PATH_SEPARATOR).any? do |directory|
File.exist? File.join directory, executable
Expand Down Expand Up @@ -1286,7 +1286,7 @@ class << self

def escape_path(*path)
path = File.join(*path)
if %r'\A[-+:/=@,.\w]+\z' =~ path
if %r{\A[-+:/=@,.\w]+\z} =~ path
path
else
"\"#{path.gsub(/[`$"]/, '\\&')}\""
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/test_utilities.rb
Expand Up @@ -49,7 +49,7 @@ def find_data(path, nargs = 3)

path = path.to_s
@paths << path
raise ArgumentError, 'need full URI' unless path =~ %r'^https?://'
raise ArgumentError, 'need full URI' unless path =~ %r{^https?://}

unless @data.key? path
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
Expand Down Expand Up @@ -121,7 +121,7 @@ def fetch_size(path)
path = path.to_s
@paths << path

raise ArgumentError, 'need full URI' unless path =~ %r'^http://'
raise ArgumentError, 'need full URI' unless path =~ %r{^http://}

unless @data.key? path
raise Gem::RemoteFetcher::FetchError.new("no data for #{path}", path)
Expand Down
8 changes: 4 additions & 4 deletions lib/rubygems/util/licenses.rb
Expand Up @@ -9,7 +9,7 @@ class Gem::Licenses

# Software Package Data Exchange (SPDX) standard open-source software
# license identifiers
LICENSE_IDENTIFIERS = %w(
LICENSE_IDENTIFIERS = %w[
0BSD
AAL
ADSL
Expand Down Expand Up @@ -379,10 +379,10 @@ class Gem::Licenses
xinetd
xpp
zlib-acknowledgement
).freeze
].freeze

# exception identifiers
EXCEPTION_IDENTIFIERS = %w(
EXCEPTION_IDENTIFIERS = %w[
389-exception
Autoconf-exception-2.0
Autoconf-exception-3.0
Expand Down Expand Up @@ -410,7 +410,7 @@ class Gem::Licenses
mif-exception
openvpn-openssl-exception
u-boot-exception-2.0
).freeze
].freeze

REGEXP = %r{
\A
Expand Down
40 changes: 20 additions & 20 deletions test/rubygems/test_gem.rb
Expand Up @@ -42,12 +42,12 @@ def test_self_finish_resolve

a1.activate

assert_equal %w(a-1), loaded_spec_names
assert_equal %w[a-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names

Gem.finish_resolve

assert_equal %w(a-1 b-2 c-2), loaded_spec_names
assert_equal %w[a-1 b-2 c-2], loaded_spec_names
assert_equal [], unresolved_names
end
end
Expand All @@ -66,12 +66,12 @@ def test_self_finish_resolve_wtf

a1.activate

assert_equal %w(a-1), loaded_spec_names
assert_equal %w[a-1], loaded_spec_names
assert_equal ["b (> 0)", "d (> 0)"], unresolved_names

Gem.finish_resolve

assert_equal %w(a-1 b-1 c-1 d-2), loaded_spec_names
assert_equal %w[a-1 b-1 c-1 d-2], loaded_spec_names
assert_equal [], unresolved_names
end
end
Expand All @@ -89,12 +89,12 @@ def test_self_finish_resolve_respects_loaded_specs
a1.activate
c1.activate

assert_equal %w(a-1 c-1), loaded_spec_names
assert_equal %w[a-1 c-1], loaded_spec_names
assert_equal ["b (> 0)"], unresolved_names

Gem.finish_resolve

assert_equal %w(a-1 b-1 c-1), loaded_spec_names
assert_equal %w[a-1 b-1 c-1], loaded_spec_names
assert_equal [], unresolved_names
end
end
Expand Down Expand Up @@ -299,7 +299,7 @@ def test_activate_bin_path_resolves_eagerly
gem 'c'
Gem.finish_resolve

assert_equal %w(a-1 b-2 c-1), loaded_spec_names
assert_equal %w[a-1 b-2 c-1], loaded_spec_names
end

def test_activate_bin_path_in_debug_mode
Expand Down Expand Up @@ -383,7 +383,7 @@ def test_activate_bin_path_selects_exact_bundler_version_if_present

load Gem.activate_bin_path("bundler", "bundle", ">= 0.a")

assert_equal %w(bundler-2.0.0), loaded_spec_names
assert_equal %w[bundler-2.0.0], loaded_spec_names
end

def test_activate_bin_path_respects_underscore_selection_if_given
Expand Down Expand Up @@ -417,7 +417,7 @@ def test_activate_bin_path_respects_underscore_selection_if_given

load Gem.activate_bin_path("bundler", "bundle", "= 1.17.3")

assert_equal %w(bundler-1.17.3), loaded_spec_names
assert_equal %w[bundler-1.17.3], loaded_spec_names
end

def test_self_bin_path_no_exec_name
Expand Down Expand Up @@ -716,7 +716,7 @@ def test_self_find_files

discover_path = File.join 'lib', 'sff', 'discover.rb'

foo1, foo2 = %w(1 2).map do |version|
foo1, foo2 = %w[1 2].map do |version|
spec = quick_gem 'sff', version do |s|
s.files << discover_path
end
Expand Down Expand Up @@ -748,7 +748,7 @@ def test_self_find_files_with_gemfile

discover_path = File.join 'lib', 'sff', 'discover.rb'

foo1, _ = %w(1 2).map do |version|
foo1, _ = %w[1 2].map do |version|
spec = quick_gem 'sff', version do |s|
s.files << discover_path
end
Expand Down Expand Up @@ -784,7 +784,7 @@ def test_self_find_latest_files

discover_path = File.join 'lib', 'sff', 'discover.rb'

_, foo2 = %w(1 2).map do |version|
_, foo2 = %w[1 2].map do |version|
spec = quick_gem 'sff', version do |s|
s.files << discover_path
end
Expand Down Expand Up @@ -1274,7 +1274,7 @@ def test_self_try_activate_missing_dep
Gem.try_activate 'a_file'
end

assert_match %r%Could not find 'b' %, e.message
assert_match %r{Could not find 'b' }, e.message
end

def test_self_try_activate_missing_prerelease
Expand All @@ -1294,7 +1294,7 @@ def test_self_try_activate_missing_prerelease
Gem.try_activate 'a_file'
end

assert_match %r%Could not find 'b' \(= 1.0rc1\)%, e.message
assert_match %r{Could not find 'b' \(= 1.0rc1\)}, e.message
end

def test_self_try_activate_missing_extensions
Expand Down Expand Up @@ -1399,7 +1399,7 @@ def test_self_needs

activated = Gem::Specification.map { |x| x.full_name }

assert_equal %w!a-1 b-1 c-2!, activated.sort
assert_equal %w[a-1 b-1 c-2], activated.sort
end

def test_self_needs_picks_up_unresolved_deps
Expand All @@ -1419,7 +1419,7 @@ def test_self_needs_picks_up_unresolved_deps
require "d#{$$}"
end

assert_equal %w!a-1 b-1 c-2 d-1 e-1!, loaded_spec_names
assert_equal %w[a-1 b-1 c-2 d-1 e-1], loaded_spec_names
end
end

Expand Down Expand Up @@ -1611,7 +1611,7 @@ def test_auto_activation_of_specific_gemdeps_file

Gem.use_gemdeps

assert_equal add_bundler_full_name(%W(a-1 b-1 c-1)), loaded_spec_names
assert_equal add_bundler_full_name(%W[a-1 b-1 c-1]), loaded_spec_names
end

def test_auto_activation_of_used_gemdeps_file
Expand Down Expand Up @@ -1765,7 +1765,7 @@ def test_use_gemdeps

Gem.use_gemdeps gem_deps_file

assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
refute_nil Gem.gemdeps
end

Expand Down Expand Up @@ -1825,7 +1825,7 @@ def test_use_gemdeps_automatic

Gem.use_gemdeps

assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
Expand Down Expand Up @@ -1902,7 +1902,7 @@ def test_use_gemdeps_specific

Gem.use_gemdeps

assert_equal add_bundler_full_name(%W(a-1)), loaded_spec_names
assert_equal add_bundler_full_name(%W[a-1]), loaded_spec_names
ensure
ENV['RUBYGEMS_GEMDEPS'] = rubygems_gemdeps
end
Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_command.rb
Expand Up @@ -103,7 +103,7 @@ def test_defaults
@cmd.invoke
end

assert_match %r|Usage: gem doit|, @ui.output
assert_match %r{Usage: gem doit}, @ui.output
end

def test_invoke
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_invoke_with_options
@cmd.invoke '-h'
end

assert_match %r|Usage: gem doit|, @ui.output
assert_match %r{Usage: gem doit}, @ui.output
end

def test_option_recognition
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_cleanup_command.rb
Expand Up @@ -220,7 +220,7 @@ def test_execute_ignore_default_gem_verbose
@cmd.execute
end

assert_match %r%^Skipped default gems: b-2%, @ui.output
assert_match %r{^Skipped default gems: b-2}, @ui.output
assert_empty @ui.error
end

Expand Down

0 comments on commit ab0580f

Please sign in to comment.