From aa3dcabd874a3e82e455e85a1c94a7abaac2900a Mon Sep 17 00:00:00 2001 From: Yasuo Honda Date: Wed, 28 Feb 2018 04:33:37 +0000 Subject: Add `Style/RedundantFreeze` to remove redudant `.freeze` Since Rails 6.0 will support Ruby 2.4.1 or higher `# frozen_string_literal: true` magic comment is enough to make string object frozen. This magic comment is enabled by `Style/FrozenStringLiteralComment` cop. * Exclude these files not to auto correct false positive `Regexp#freeze` - 'actionpack/lib/action_dispatch/journey/router/utils.rb' - 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb' It has been fixed by https://github.com/rubocop-hq/rubocop/pull/6333 Once the newer version of RuboCop released and available at Code Climate these exclude entries should be removed. * Replace `String#freeze` with `String#-@` manually if explicit frozen string objects are required - 'actionpack/test/controller/test_case_test.rb' - 'activemodel/test/cases/type/string_test.rb' - 'activesupport/lib/active_support/core_ext/string/strip.rb' - 'activesupport/test/core_ext/string_ext_test.rb' - 'railties/test/generators/actions_test.rb' --- railties/lib/rails/backtrace_cleaner.rb | 8 ++++---- railties/lib/rails/commands/server/server_command.rb | 2 +- railties/test/generators/actions_test.rb | 2 +- railties/test/generators/resource_generator_test.rb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index b1e3c923b7..7c2eb1dc42 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -6,13 +6,13 @@ module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner APP_DIRS_PATTERN = /^\/?(app|config|lib|test|\(\w*\))/ RENDER_TEMPLATE_PATTERN = /:in `.*_\w+_{2,3}\d+_\d+'/ - EMPTY_STRING = "".freeze - SLASH = "/".freeze - DOT_SLASH = "./".freeze + EMPTY_STRING = "" + SLASH = "/" + DOT_SLASH = "./" def initialize super - @root = "#{Rails.root}/".freeze + @root = "#{Rails.root}/" add_filter { |line| line.sub(@root, EMPTY_STRING) } add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, EMPTY_STRING) } add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests diff --git a/railties/lib/rails/commands/server/server_command.rb b/railties/lib/rails/commands/server/server_command.rb index 9d517f3239..70789e0303 100644 --- a/railties/lib/rails/commands/server/server_command.rb +++ b/railties/lib/rails/commands/server/server_command.rb @@ -109,7 +109,7 @@ module Rails RACK_SERVERS = %w(cgi fastcgi webrick lsws scgi thin puma unicorn) DEFAULT_PORT = 3000 - DEFAULT_PID_PATH = "tmp/pids/server.pid".freeze + DEFAULT_PID_PATH = "tmp/pids/server.pid" argument :using, optional: true diff --git a/railties/test/generators/actions_test.rb b/railties/test/generators/actions_test.rb index da52b6076a..6d53230eab 100644 --- a/railties/test/generators/actions_test.rb +++ b/railties/test/generators/actions_test.rb @@ -125,7 +125,7 @@ class ActionsTest < Rails::Generators::TestCase def test_gem_works_even_if_frozen_string_is_passed_as_argument run_generator - action :gem, "frozen_gem".freeze, "1.0.0".freeze + action :gem, -"frozen_gem", -"1.0.0" assert_file "Gemfile", /^gem 'frozen_gem', '1.0.0'$/ end diff --git a/railties/test/generators/resource_generator_test.rb b/railties/test/generators/resource_generator_test.rb index 7a470d0d91..b99b4baf6b 100644 --- a/railties/test/generators/resource_generator_test.rb +++ b/railties/test/generators/resource_generator_test.rb @@ -65,7 +65,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase end def test_plural_names_are_singularized - content = run_generator ["accounts".freeze] + content = run_generator ["accounts"] assert_file "app/models/account.rb", /class Account < ApplicationRecord/ assert_file "test/models/account_test.rb", /class AccountTest/ assert_match(/\[WARNING\] The model name 'accounts' was recognized as a plural, using the singular 'account' instead\. Override with --force-plural or setup custom inflection rules for this noun before running the generator\./, content) @@ -79,7 +79,7 @@ class ResourceGeneratorTest < Rails::Generators::TestCase end def test_mass_nouns_do_not_throw_warnings - content = run_generator ["sheep".freeze] + content = run_generator ["sheep"] assert_no_match(/\[WARNING\]/, content) end -- cgit v1.2.3