brew vendor-gems: commit updates.

This commit is contained in:
Mike McQuaid 2020-06-05 08:45:48 +01:00
parent 2427d16a59
commit e0906312c8
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
37 changed files with 201 additions and 79 deletions

View File

@ -14,7 +14,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ast-2.4.0/lib"
$:.unshift "#{path}/"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/byebug-11.1.3"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/byebug-11.1.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/connection_pool-2.2.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/connection_pool-2.2.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/json-2.3.0"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/json-2.3.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/docile-1.3.2/lib"
@ -46,11 +46,12 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mechanize-2.7.6/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/mustache-1.1.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel-1.19.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parallel_tests-2.32.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.7.1.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/parser-2.7.1.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/plist-3.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rainbow-3.0.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/universal-darwin-19/2.6.0/rdiscount-2.2.0.1"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rdiscount-2.2.0.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/regexp_parser-1.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rexml-3.2.4/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ronn-0.7.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-support-3.9.3/lib"
@ -64,7 +65,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-ast-0.0.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.7.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.84.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.6.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.85.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.6.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.39.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"

View File

@ -1,41 +0,0 @@
# frozen_string_literal: true
module RuboCop
module Cop
# Common functionality for handling regexp metacharacters.
module RegexpMetacharacter
def literal_at_start?(regex_str)
# is this regexp 'literal' in the sense of only matching literal
# chars, rather than using metachars like `.` and `*` and so on?
# also, is it anchored at the start of the string?
# (tricky: \s, \d, and so on are metacharacters, but other characters
# escaped with a slash are just literals. LITERAL_REGEX takes all
# that into account.)
regex_str =~ /\A(\\A|\^)(?:#{Util::LITERAL_REGEX})+\z/
end
def literal_at_end?(regex_str)
# is this regexp 'literal' in the sense of only matching literal
# chars, rather than using metachars like . and * and so on?
# also, is it anchored at the end of the string?
regex_str =~ /\A(?:#{Util::LITERAL_REGEX})+(\\z|\$)\z/
end
def drop_start_metacharacter(regexp_string)
if regexp_string.start_with?('\\A')
regexp_string[2..-1] # drop `\A` anchor
else
regexp_string[1..-1] # drop `^` anchor
end
end
def drop_end_metacharacter(regexp_string)
if regexp_string.end_with?('\\z')
regexp_string.chomp('\z') # drop `\z` anchor
else
regexp_string.chop # drop `$` anchor
end
end
end
end
end

View File

@ -58,11 +58,13 @@ Performance/Count:
Performance/DeletePrefix:
Description: 'Use `delete_prefix` instead of `gsub`.'
Enabled: true
SafeMultiline: true
VersionAdded: '1.6'
Performance/DeleteSuffix:
Description: 'Use `delete_suffix` instead of `gsub`.'
Enabled: true
SafeMultiline: true
VersionAdded: '1.6'
Performance/Detect:
@ -99,8 +101,9 @@ Performance/EndWith:
SafeAutoCorrect: false
AutoCorrect: false
Enabled: true
SafeMultiline: true
VersionAdded: '0.36'
VersionChanged: '0.44'
VersionChanged: '1.6'
Performance/FixedSize:
Description: 'Do not compute the size of statically sized objects except in constants.'
@ -193,8 +196,9 @@ Performance/StartWith:
SafeAutoCorrect: false
AutoCorrect: false
Enabled: true
SafeMultiline: true
VersionAdded: '0.36'
VersionChanged: '0.44'
VersionChanged: '1.6'
Performance/StringReplacement:
Description: >-

View File

@ -0,0 +1,76 @@
# frozen_string_literal: true
module RuboCop
module Cop
# Common functionality for handling regexp metacharacters.
module RegexpMetacharacter
private
def literal_at_start?(regexp)
return true if literal_at_start_with_backslash_a?(regexp)
!safe_multiline? && literal_at_start_with_caret?(regexp)
end
def literal_at_end?(regexp)
return true if literal_at_end_with_backslash_z?(regexp)
!safe_multiline? && literal_at_end_with_dollar?(regexp)
end
def literal_at_start_with_backslash_a?(regex_str)
# is this regexp 'literal' in the sense of only matching literal
# chars, rather than using metachars like `.` and `*` and so on?
# also, is it anchored at the start of the string?
# (tricky: \s, \d, and so on are metacharacters, but other characters
# escaped with a slash are just literals. LITERAL_REGEX takes all
# that into account.)
/\A\\A(?:#{Util::LITERAL_REGEX})+\z/.match?(regex_str)
end
def literal_at_start_with_caret?(regex_str)
# is this regexp 'literal' in the sense of only matching literal
# chars, rather than using metachars like `.` and `*` and so on?
# also, is it anchored at the start of the string?
# (tricky: \s, \d, and so on are metacharacters, but other characters
# escaped with a slash are just literals. LITERAL_REGEX takes all
# that into account.)
/\A\^(?:#{Util::LITERAL_REGEX})+\z/.match?(regex_str)
end
def literal_at_end_with_backslash_z?(regex_str)
# is this regexp 'literal' in the sense of only matching literal
# chars, rather than using metachars like . and * and so on?
# also, is it anchored at the end of the string?
/\A(?:#{Util::LITERAL_REGEX})+\\z\z/.match?(regex_str)
end
def literal_at_end_with_dollar?(regex_str)
# is this regexp 'literal' in the sense of only matching literal
# chars, rather than using metachars like . and * and so on?
# also, is it anchored at the end of the string?
/\A(?:#{Util::LITERAL_REGEX})+\$\z/.match?(regex_str)
end
def drop_start_metacharacter(regexp_string)
if regexp_string.start_with?('\\A')
regexp_string[2..-1] # drop `\A` anchor
else
regexp_string[1..-1] # drop `^` anchor
end
end
def drop_end_metacharacter(regexp_string)
if regexp_string.end_with?('\\z')
regexp_string.chomp('\z') # drop `\z` anchor
else
regexp_string.chop # drop `$` anchor
end
end
def safe_multiline?
cop_config.fetch('SafeMultiline', true)
end
end
end
end

View File

@ -5,24 +5,44 @@ module RuboCop
module Performance
# In Ruby 2.5, `String#delete_prefix` has been added.
#
# This cop identifies places where `gsub(/\Aprefix/, '')`
# This cop identifies places where `gsub(/\Aprefix/, '')` and `sub(/\Aprefix/, '')`
# can be replaced by `delete_prefix('prefix')`.
#
# The `delete_prefix('prefix')` method is faster than
# `gsub(/\Aprefix/, '')`.
# This cop has `SafeMultiline` configuration option that `true` by default because
# `^prefix` is unsafe as it will behave incompatible with `delete_prefix`
# for receiver is multiline string.
#
# The `delete_prefix('prefix')` method is faster than `gsub(/\Aprefix/, '')`.
#
# @example
#
# # bad
# str.gsub(/\Aprefix/, '')
# str.gsub!(/\Aprefix/, '')
# str.gsub(/^prefix/, '')
# str.gsub!(/^prefix/, '')
#
# str.sub(/\Aprefix/, '')
# str.sub!(/\Aprefix/, '')
#
# # good
# str.delete_prefix('prefix')
# str.delete_prefix!('prefix')
#
# @example SafeMultiline: true (default)
#
# # good
# str.gsub(/^prefix/, '')
# str.gsub!(/^prefix/, '')
# str.sub(/^prefix/, '')
# str.sub!(/^prefix/, '')
#
# @example SafeMultiline: false
#
# # bad
# str.gsub(/^prefix/, '')
# str.gsub!(/^prefix/, '')
# str.sub(/^prefix/, '')
# str.sub!(/^prefix/, '')
#
class DeletePrefix < Cop
extend TargetRubyVersion
include RegexpMetacharacter
@ -33,15 +53,17 @@ module RuboCop
PREFERRED_METHODS = {
gsub: :delete_prefix,
gsub!: :delete_prefix!
gsub!: :delete_prefix!,
sub: :delete_prefix,
sub!: :delete_prefix!
}.freeze
def_node_matcher :gsub_method?, <<~PATTERN
(send $!nil? ${:gsub :gsub!} (regexp (str $#literal_at_start?) (regopt)) (str $_))
def_node_matcher :delete_prefix_candidate?, <<~PATTERN
(send $!nil? ${:gsub :gsub! :sub :sub!} (regexp (str $#literal_at_start?) (regopt)) (str $_))
PATTERN
def on_send(node)
gsub_method?(node) do |_, bad_method, _, replace_string|
delete_prefix_candidate?(node) do |_, bad_method, _, replace_string|
return unless replace_string.blank?
good_method = PREFERRED_METHODS[bad_method]
@ -53,7 +75,7 @@ module RuboCop
end
def autocorrect(node)
gsub_method?(node) do |receiver, bad_method, regexp_str, _|
delete_prefix_candidate?(node) do |receiver, bad_method, regexp_str, _|
lambda do |corrector|
good_method = PREFERRED_METHODS[bad_method]
regexp_str = drop_start_metacharacter(regexp_str)
@ -62,7 +84,9 @@ module RuboCop
new_code = "#{receiver.source}.#{good_method}(#{string_literal})"
corrector.replace(node, new_code)
# TODO: `source_range` is no longer required when RuboCop 0.81 or lower support will be dropped.
# https://github.com/rubocop-hq/rubocop/commit/82eb350d2cba16
corrector.replace(node.source_range, new_code)
end
end
end

View File

@ -5,24 +5,44 @@ module RuboCop
module Performance
# In Ruby 2.5, `String#delete_suffix` has been added.
#
# This cop identifies places where `gsub(/suffix\z/, '')`
# This cop identifies places where `gsub(/suffix\z/, '')` and `sub(/suffix\z/, '')`
# can be replaced by `delete_suffix('suffix')`.
#
# The `delete_suffix('suffix')` method is faster than
# `gsub(/suffix\z/, '')`.
# This cop has `SafeMultiline` configuration option that `true` by default because
# `suffix$` is unsafe as it will behave incompatible with `delete_suffix?`
# for receiver is multiline string.
#
# The `delete_suffix('suffix')` method is faster than `gsub(/suffix\z/, '')`.
#
# @example
#
# # bad
# str.gsub(/suffix\z/, '')
# str.gsub!(/suffix\z/, '')
# str.gsub(/suffix$/, '')
# str.gsub!(/suffix$/, '')
#
# str.sub(/suffix\z/, '')
# str.sub!(/suffix\z/, '')
#
# # good
# str.delete_suffix('suffix')
# str.delete_suffix!('suffix')
#
# @example SafeMultiline: true (default)
#
# # good
# str.gsub(/suffix$/, '')
# str.gsub!(/suffix$/, '')
# str.sub(/suffix$/, '')
# str.sub!(/suffix$/, '')
#
# @example SafeMultiline: false
#
# # bad
# str.gsub(/suffix$/, '')
# str.gsub!(/suffix$/, '')
# str.sub(/suffix$/, '')
# str.sub!(/suffix$/, '')
#
class DeleteSuffix < Cop
extend TargetRubyVersion
include RegexpMetacharacter
@ -33,15 +53,17 @@ module RuboCop
PREFERRED_METHODS = {
gsub: :delete_suffix,
gsub!: :delete_suffix!
gsub!: :delete_suffix!,
sub: :delete_suffix,
sub!: :delete_suffix!
}.freeze
def_node_matcher :gsub_method?, <<~PATTERN
(send $!nil? ${:gsub :gsub!} (regexp (str $#literal_at_end?) (regopt)) (str $_))
def_node_matcher :delete_suffix_candidate?, <<~PATTERN
(send $!nil? ${:gsub :gsub! :sub :sub!} (regexp (str $#literal_at_end?) (regopt)) (str $_))
PATTERN
def on_send(node)
gsub_method?(node) do |_, bad_method, _, replace_string|
delete_suffix_candidate?(node) do |_, bad_method, _, replace_string|
return unless replace_string.blank?
good_method = PREFERRED_METHODS[bad_method]
@ -53,7 +75,7 @@ module RuboCop
end
def autocorrect(node)
gsub_method?(node) do |receiver, bad_method, regexp_str, _|
delete_suffix_candidate?(node) do |receiver, bad_method, regexp_str, _|
lambda do |corrector|
good_method = PREFERRED_METHODS[bad_method]
regexp_str = drop_end_metacharacter(regexp_str)
@ -62,7 +84,9 @@ module RuboCop
new_code = "#{receiver.source}.#{good_method}(#{string_literal})"
corrector.replace(node, new_code)
# TODO: `source_range` is no longer required when RuboCop 0.81 or lower support will be dropped.
# https://github.com/rubocop-hq/rubocop/commit/82eb350d2cba16
corrector.replace(node.source_range, new_code)
end
end
end

View File

@ -3,8 +3,11 @@
module RuboCop
module Cop
module Performance
# This cop identifies unnecessary use of a regex where `String#end_with?`
# would suffice.
# This cop identifies unnecessary use of a regex where `String#end_with?` would suffice.
#
# This cop has `SafeMultiline` configuration option that `true` by default because
# `end$` is unsafe as it will behave incompatible with `end_with?`
# for receiver is multiline string.
#
# @example
# # bad
@ -15,6 +18,22 @@ module RuboCop
# 'abc'.match(/bc\Z/)
# /bc\Z/.match('abc')
#
# # good
# 'abc'.end_with?('bc')
#
# @example SafeMultiline: true (default)
#
# # good
# 'abc'.match?(/bc$/)
# /bc$/.match?('abc')
# 'abc' =~ /bc$/
# /bc$/ =~ 'abc'
# 'abc'.match(/bc$/)
# /bc$/.match('abc')
#
# @example SafeMultiline: false
#
# # bad
# 'abc'.match?(/bc$/)
# /bc$/.match?('abc')
# 'abc' =~ /bc$/
@ -22,8 +41,6 @@ module RuboCop
# 'abc'.match(/bc$/)
# /bc$/.match('abc')
#
# # good
# 'abc'.end_with?('bc')
class EndWith < Cop
include RegexpMetacharacter

View File

@ -3,8 +3,11 @@
module RuboCop
module Cop
module Performance
# This cop identifies unnecessary use of a regex where
# `String#start_with?` would suffice.
# This cop identifies unnecessary use of a regex where `String#start_with?` would suffice.
#
# This cop has `SafeMultiline` configuration option that `true` by default because
# `^start` is unsafe as it will behave incompatible with `start_with?`
# for receiver is multiline string.
#
# @example
# # bad
@ -15,6 +18,22 @@ module RuboCop
# 'abc'.match(/\Aab/)
# /\Aab/.match('abc')
#
# # good
# 'abc'.start_with?('ab')
#
# @example SafeMultiline: true (default)
#
# # good
# 'abc'.match?(/^ab/)
# /^ab/.match?('abc')
# 'abc' =~ /^ab/
# /^ab/ =~ 'abc'
# 'abc'.match(/^ab/)
# /^ab/.match('abc')
#
# @example SafeMultiline: false
#
# # bad
# 'abc'.match?(/^ab/)
# /^ab/.match?('abc')
# 'abc' =~ /^ab/
@ -22,8 +41,6 @@ module RuboCop
# 'abc'.match(/^ab/)
# /^ab/.match('abc')
#
# # good
# 'abc'.start_with?('ab')
class StartWith < Cop
include RegexpMetacharacter

View File

@ -7,7 +7,7 @@ module RuboCop
# literal instead of `String#dup` and `String.new`.
# Unary plus operator is faster than `String#dup`.
#
# Note: `String.new` (without operator) is not exactly the same as `+''`.
# NOTE: `String.new` (without operator) is not exactly the same as `+''`.
# These differ in encoding. `String.new.encoding` is always `ASCII-8BIT`.
# However, `(+'').encoding` is the same as script encoding(e.g. `UTF-8`).
# So, if you expect `ASCII-8BIT` encoding, disable this cop.