1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Auto-correct for delete_prefix/delete_suffix

Follow up to #39409.
This commit is contained in:
Ryuta Kamizono 2020-06-05 12:40:39 +09:00
parent c2dc793e59
commit c07dff7227
7 changed files with 9 additions and 9 deletions

View file

@ -415,7 +415,7 @@ GEM
rexml rexml
ruby-progressbar (~> 1.7) ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0) unicode-display_width (>= 1.4.0, < 2.0)
rubocop-performance (1.6.0) rubocop-performance (1.6.1)
rubocop (>= 0.71.0) rubocop (>= 0.71.0)
rubocop-rails (2.5.2) rubocop-rails (2.5.2)
activesupport activesupport

View file

@ -21,7 +21,7 @@ module ActiveRecord
alias :array? :array alias :array? :array
def sql_type def sql_type
super.sub(/\[\]\z/, "") super.delete_suffix("[]")
end end
def init_with(coder) def init_with(coder)

View file

@ -544,7 +544,7 @@ module ActiveSupport #:nodoc:
if file_path if file_path
expanded = File.expand_path(file_path) expanded = File.expand_path(file_path)
expanded.sub!(/\.rb\z/, "") expanded.delete_suffix!(".rb")
if loading.include?(expanded) if loading.include?(expanded)
raise "Circular dependency detected while autoloading constant #{qualified_name}" raise "Circular dependency detected while autoloading constant #{qualified_name}"
@ -733,7 +733,7 @@ module ActiveSupport #:nodoc:
def remove_constant(const) #:nodoc: def remove_constant(const) #:nodoc:
# Normalize ::Foo, ::Object::Foo, Object::Foo, Object::Object::Foo, etc. as Foo. # Normalize ::Foo, ::Object::Foo, Object::Foo, Object::Object::Foo, etc. as Foo.
normalized = const.to_s.sub(/\A::/, "") normalized = const.to_s.delete_prefix("::")
normalized.sub!(/\A(Object::)+/, "") normalized.sub!(/\A(Object::)+/, "")
constants = normalized.split("::") constants = normalized.split("::")
@ -743,7 +743,7 @@ module ActiveSupport #:nodoc:
file_path = search_for_file(const.underscore) file_path = search_for_file(const.underscore)
if file_path if file_path
expanded = File.expand_path(file_path) expanded = File.expand_path(file_path)
expanded.sub!(/\.rb\z/, "") expanded.delete_suffix!(".rb")
loaded.delete(expanded) loaded.delete(expanded)
end end

View file

@ -160,7 +160,7 @@ module ActiveSupport
end end
def normalize_extension(ext) def normalize_extension(ext)
ext.to_s.sub(/\A\./, "") ext.to_s.delete_prefix(".")
end end
# Given a collection of Pathname objects returns the longest subpath # Given a collection of Pathname objects returns the longest subpath

View file

@ -133,7 +133,7 @@ module ActiveSupport
result.sub!(/\A_+/, "") result.sub!(/\A_+/, "")
unless keep_id_suffix unless keep_id_suffix
result.sub!(/_id\z/, "") result.delete_suffix!("_id")
end end
result.tr!("_", " ") result.tr!("_", " ")

View file

@ -129,7 +129,7 @@ module RailsGuides
if guide.end_with?(".md") if guide.end_with?(".md")
guide.sub(/md\z/, "html") guide.sub(/md\z/, "html")
else else
guide.sub(/\.erb\z/, "") guide.delete_suffix(".erb")
end end
end end

View file

@ -82,7 +82,7 @@ class CodeStatisticsCalculator #:nodoc:
if file_path.end_with? "_test.rb" if file_path.end_with? "_test.rb"
:minitest :minitest
else else
File.extname(file_path).sub(/\A\./, "").downcase.to_sym File.extname(file_path).delete_prefix(".").downcase.to_sym
end end
end end
end end