mirror of https://github.com/rails/rails
Update `rubocop-performance` and enable more performance-related cops
This commit is contained in:
parent
c6dbb4eb16
commit
3158bbb9f6
12
.rubocop.yml
12
.rubocop.yml
|
@ -312,5 +312,17 @@ Performance/DeleteSuffix:
|
|||
Performance/OpenStruct:
|
||||
Enabled: true
|
||||
|
||||
Performance/InefficientHashSearch:
|
||||
Enabled: true
|
||||
|
||||
Performance/ConstantRegexp:
|
||||
Enabled: true
|
||||
|
||||
Performance/RedundantStringChars:
|
||||
Enabled: true
|
||||
|
||||
Performance/StringInclude:
|
||||
Enabled: true
|
||||
|
||||
Minitest/UnreachableAssertion:
|
||||
Enabled: true
|
||||
|
|
|
@ -502,11 +502,14 @@ module ActionController
|
|||
array_params.each { |param| (param[1] || +"").gsub! %r/^"|"$/, "" }
|
||||
end
|
||||
|
||||
WHITESPACED_AUTHN_PAIR_DELIMITERS = /\s*#{AUTHN_PAIR_DELIMITERS}\s*/
|
||||
private_constant :WHITESPACED_AUTHN_PAIR_DELIMITERS
|
||||
|
||||
# This method takes an authorization body and splits up the key-value
|
||||
# pairs by the standardized <tt>:</tt>, <tt>;</tt>, or <tt>\t</tt>
|
||||
# delimiters defined in +AUTHN_PAIR_DELIMITERS+.
|
||||
def raw_params(auth)
|
||||
_raw_params = auth.sub(TOKEN_REGEX, "").split(/\s*#{AUTHN_PAIR_DELIMITERS}\s*/)
|
||||
_raw_params = auth.sub(TOKEN_REGEX, "").split(WHITESPACED_AUTHN_PAIR_DELIMITERS)
|
||||
|
||||
if !_raw_params.first&.start_with?(TOKEN_KEY)
|
||||
_raw_params[0] = "#{TOKEN_KEY}#{_raw_params.first}"
|
||||
|
|
|
@ -30,7 +30,7 @@ module ActionDispatch
|
|||
def assert_response(type, message = nil)
|
||||
message ||= generate_response_message(type)
|
||||
|
||||
if RESPONSE_PREDICATES.keys.include?(type)
|
||||
if RESPONSE_PREDICATES.key?(type)
|
||||
assert @response.public_send(RESPONSE_PREDICATES[type]), message
|
||||
else
|
||||
assert_equal AssertionResponse.new(type).code, @response.response_code, message
|
||||
|
@ -93,7 +93,7 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def code_with_name(code_or_name)
|
||||
if RESPONSE_PREDICATES.values.include?("#{code_or_name}?".to_sym)
|
||||
if RESPONSE_PREDICATES.value?("#{code_or_name}?".to_sym)
|
||||
code_or_name = RESPONSE_PREDICATES.invert["#{code_or_name}?".to_sym]
|
||||
end
|
||||
|
||||
|
|
|
@ -193,6 +193,9 @@ module ActionView
|
|||
@source.to_s
|
||||
end
|
||||
|
||||
LEADING_ENCODING_REGEXP = /\A#{ENCODING_FLAG}/
|
||||
private_constant :LEADING_ENCODING_REGEXP
|
||||
|
||||
# This method is responsible for properly setting the encoding of the
|
||||
# source. Until this point, we assume that the source is BINARY data.
|
||||
# If no additional information is supplied, we assume the encoding is
|
||||
|
@ -211,7 +214,7 @@ module ActionView
|
|||
# Look for # encoding: *. If we find one, we'll encode the
|
||||
# String in that encoding, otherwise, we'll use the
|
||||
# default external encoding.
|
||||
if source.sub!(/\A#{ENCODING_FLAG}/, "")
|
||||
if source.sub!(LEADING_ENCODING_REGEXP, "")
|
||||
encoding = magic_encoding = $1
|
||||
else
|
||||
encoding = Encoding.default_external
|
||||
|
|
|
@ -61,7 +61,7 @@ module ActiveRecord
|
|||
|
||||
# Given a attribute name, it returns the name of the source attribute when it's a preserved one.
|
||||
def source_attribute_from_preserved_attribute(attribute_name)
|
||||
attribute_name.to_s.sub(ORIGINAL_ATTRIBUTE_PREFIX, "") if /^#{ORIGINAL_ATTRIBUTE_PREFIX}/.match?(attribute_name)
|
||||
attribute_name.to_s.sub(ORIGINAL_ATTRIBUTE_PREFIX, "") if attribute_name.start_with?(ORIGINAL_ATTRIBUTE_PREFIX)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -59,7 +59,7 @@ module ActiveRecord
|
|||
unless fixture_set_names.empty?
|
||||
self.fixture_sets = fixture_sets.dup
|
||||
fixture_set_names.each do |fs_name|
|
||||
key = fs_name.match?(%r{/}) ? -fs_name.to_s.tr("/", "_") : fs_name
|
||||
key = fs_name.to_s.include?("/") ? -fs_name.to_s.tr("/", "_") : fs_name
|
||||
key = -key.to_s if key.is_a?(Symbol)
|
||||
fs_name = -fs_name.to_s if fs_name.is_a?(Symbol)
|
||||
fixture_sets[key] = fs_name
|
||||
|
|
|
@ -35,7 +35,7 @@ class TestRun
|
|||
end
|
||||
|
||||
def completed?
|
||||
@qunit_testresult.text =~ /Tests completed/
|
||||
@qunit_testresult.text.include?("Tests completed")
|
||||
end
|
||||
|
||||
def result
|
||||
|
|
|
@ -49,7 +49,7 @@ module Epub # :nodoc:
|
|||
end
|
||||
|
||||
def is_name_invalid(name)
|
||||
(/[0-9]/ === name.chars.first)
|
||||
name.match?(/\A\d/)
|
||||
end
|
||||
|
||||
def fix_file_names(output_dir)
|
||||
|
|
|
@ -6,6 +6,7 @@ module Rails
|
|||
module Generators
|
||||
class BenchmarkGenerator < NamedBase
|
||||
IPS_GEM_NAME = "benchmark-ips"
|
||||
IPS_GEM_USED_REGEXP = /gem.*\b#{IPS_GEM_NAME}\b.*/
|
||||
|
||||
argument :reports, type: :array, default: ["before", "after"]
|
||||
|
||||
|
@ -21,7 +22,7 @@ module Rails
|
|||
|
||||
def ips_installed?
|
||||
in_root do
|
||||
return File.read("Gemfile").match?(/gem.*\b#{IPS_GEM_NAME}\b.*/)
|
||||
return File.read("Gemfile").match?(IPS_GEM_USED_REGEXP)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -314,7 +314,7 @@ module Announcement
|
|||
end
|
||||
|
||||
def rc?
|
||||
@version =~ /rc/
|
||||
@version.include?("rc")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue