From c07dff72278fb7f2a3c4c71212a0773a2b25c790 Mon Sep 17 00:00:00 2001 From: Ryuta Kamizono Date: Fri, 5 Jun 2020 12:40:39 +0900 Subject: [PATCH] Auto-correct for `delete_prefix`/`delete_suffix` Follow up to #39409. --- Gemfile.lock | 2 +- .../active_record/connection_adapters/postgresql/column.rb | 2 +- activesupport/lib/active_support/dependencies.rb | 6 +++--- .../lib/active_support/evented_file_update_checker.rb | 2 +- activesupport/lib/active_support/inflector/methods.rb | 2 +- guides/rails_guides/generator.rb | 2 +- railties/lib/rails/code_statistics_calculator.rb | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f337e3b3fb8..3eae0f1ebd7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -415,7 +415,7 @@ GEM rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 2.0) - rubocop-performance (1.6.0) + rubocop-performance (1.6.1) rubocop (>= 0.71.0) rubocop-rails (2.5.2) activesupport diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb index f1ecf6df305..b9d10e9e2f8 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/column.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/column.rb @@ -21,7 +21,7 @@ module ActiveRecord alias :array? :array def sql_type - super.sub(/\[\]\z/, "") + super.delete_suffix("[]") end def init_with(coder) diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 2b0be9f995c..874f672c9f8 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -544,7 +544,7 @@ module ActiveSupport #:nodoc: if file_path expanded = File.expand_path(file_path) - expanded.sub!(/\.rb\z/, "") + expanded.delete_suffix!(".rb") if loading.include?(expanded) raise "Circular dependency detected while autoloading constant #{qualified_name}" @@ -733,7 +733,7 @@ module ActiveSupport #:nodoc: def remove_constant(const) #:nodoc: # 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::)+/, "") constants = normalized.split("::") @@ -743,7 +743,7 @@ module ActiveSupport #:nodoc: file_path = search_for_file(const.underscore) if file_path expanded = File.expand_path(file_path) - expanded.sub!(/\.rb\z/, "") + expanded.delete_suffix!(".rb") loaded.delete(expanded) end diff --git a/activesupport/lib/active_support/evented_file_update_checker.rb b/activesupport/lib/active_support/evented_file_update_checker.rb index 82695e4168c..646be7d6f18 100644 --- a/activesupport/lib/active_support/evented_file_update_checker.rb +++ b/activesupport/lib/active_support/evented_file_update_checker.rb @@ -160,7 +160,7 @@ module ActiveSupport end def normalize_extension(ext) - ext.to_s.sub(/\A\./, "") + ext.to_s.delete_prefix(".") end # Given a collection of Pathname objects returns the longest subpath diff --git a/activesupport/lib/active_support/inflector/methods.rb b/activesupport/lib/active_support/inflector/methods.rb index 74574ab7c27..127d88cb300 100644 --- a/activesupport/lib/active_support/inflector/methods.rb +++ b/activesupport/lib/active_support/inflector/methods.rb @@ -133,7 +133,7 @@ module ActiveSupport result.sub!(/\A_+/, "") unless keep_id_suffix - result.sub!(/_id\z/, "") + result.delete_suffix!("_id") end result.tr!("_", " ") diff --git a/guides/rails_guides/generator.rb b/guides/rails_guides/generator.rb index 2af55074025..50cb05f5644 100644 --- a/guides/rails_guides/generator.rb +++ b/guides/rails_guides/generator.rb @@ -129,7 +129,7 @@ module RailsGuides if guide.end_with?(".md") guide.sub(/md\z/, "html") else - guide.sub(/\.erb\z/, "") + guide.delete_suffix(".erb") end end diff --git a/railties/lib/rails/code_statistics_calculator.rb b/railties/lib/rails/code_statistics_calculator.rb index 8dd415d9d13..d9efd63a7e1 100644 --- a/railties/lib/rails/code_statistics_calculator.rb +++ b/railties/lib/rails/code_statistics_calculator.rb @@ -82,7 +82,7 @@ class CodeStatisticsCalculator #:nodoc: if file_path.end_with? "_test.rb" :minitest else - File.extname(file_path).sub(/\A\./, "").downcase.to_sym + File.extname(file_path).delete_prefix(".").downcase.to_sym end end end