DEV: stop freezing frozen strings

DEV: stop freezing frozen strings

We have the # frozen_string_literal: true comment on all our files. This means all string literals are frozen. There is no need to call #freeze on any literals.

For files with # frozen_string_literal: true

puts %w{a b}[0].frozen?
=> true

puts "hi".frozen?
=> true

puts "a #{1} b".frozen?
=> true

puts ("a " + "b").frozen?
=> false

puts (-("a " + "b")).frozen?
=> true

For more details see: https://samsaffron.com/archive/2018/02/16/reducing-string-duplication-in-ruby

diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb
index 8481531..acb39e7 100644
--- a/app/controllers/categories_controller.rb
+++ b/app/controllers/categories_controller.rb
@@ -24,7 +24,7 @@ class CategoriesController < ApplicationController
     parent_category = Category.find_by_slug(params[:parent_category_id]) || Category.find_by(id: params[:parent_category_id].to_i)
 
     category_options = {
-      is_homepage: current_homepage == "categories".freeze,
+      is_homepage: current_homepage == "categories",
       parent_category_id: params[:parent_category_id],
       include_topics: include_topics(parent_category)
     }
@@ -53,10 +53,10 @@ class CategoriesController < ApplicationController
           no_definitions: true
         }
 
-        if style == "categories_and_latest_topics".freeze
+        if style == "categories_and_latest_topics"
           @topic_list = TopicQuery.new(current_user, topic_options).list_latest
           @topic_list.more_topics_url = url_for(public_send("latest_path"))
-        elsif style == "categories_and_top_topics".freeze
+        elsif style == "categories_and_top_topics"
           @topic_list = TopicQuery.new(nil, topic_options).list_top_for(SiteSetting.top_page_default_timeframe.to_sym)
           @topic_list.more_topics_url = url_for(public_send("top_path"))
         end
@@ -245,7 +245,7 @@ class CategoriesController < ApplicationController
     discourse_expires_in 1.minute
 
     category_options = {
-      is_homepage: current_homepage == "categories".freeze,
+      is_homepage: current_homepage == "categories",
       parent_category_id: params[:parent_category_id],
       include_topics: false
     }
@@ -354,8 +354,8 @@ class CategoriesController < ApplicationController
     view_context.mobile_view? ||
       params[:include_topics] ||
       (parent_category && parent_category.subcategory_list_includes_topics?) ||
-      style == "categories_with_featured_topics".freeze ||
-      style == "categories_boxes_with_topics".freeze ||
-      style == "categories_with_top_topics".freeze
+      style == "categories_with_featured_topics" ||
+      style == "categories_boxes_with_topics" ||
+      style == "categories_with_top_topics"
   end
 end
diff --git a/app/controllers/webhooks_controller.rb b/app/controllers/webhooks_controller.rb
index 320abe1..347ff52 100644
--- a/app/controllers/webhooks_controller.rb
+++ b/app/controllers/webhooks_controller.rb
@@ -15,13 +15,13 @@ class WebhooksController < ActionController::Base
     events.each do |event|
       message_id = (event["smtp-id"] || "").tr("<>", "")
       to_address = event["email"]
-      if event["event"] == "bounce".freeze
+      if event["event"] == "bounce"
         if event["status"]["4."]
           process_bounce(message_id, to_address, SiteSetting.soft_bounce_score)
         else
           process_bounce(message_id, to_address, SiteSetting.hard_bounce_score)
         end
-      elsif event["event"] == "dropped".freeze
+      elsif event["event"] == "dropped"
         process_bounce(message_id, to_address, SiteSetting.hard_bounce_score)
       end
     end
@@ -34,7 +34,7 @@ class WebhooksController < ActionController::Base
     events.each do |event|
       message_id = event["CustomID"]
       to_address = event["email"]
-      if event["event"] == "bounce".freeze
+      if event["event"] == "bounce"
         if event["hard_bounce"]
           process_bounce(message_id, to_address, SiteSetting.hard_bounce_score)
         else
@@ -156,9 +156,9 @@ class WebhooksController < ActionController::Base
     # only handle soft bounces, because hard bounces are also handled
     # by the "dropped" event and we don't want to increase bounce score twice
     # for the same message
-    if event == "bounced".freeze && params["error"]["4."]
+    if event == "bounced" && params["error"]["4."]
       process_bounce(message_id, to_address, SiteSetting.soft_bounce_score)
-    elsif event == "dropped".freeze
+    elsif event == "dropped"
       process_bounce(message_id, to_address, SiteSetting.hard_bounce_score)
     end
 
@@ -174,10 +174,10 @@ class WebhooksController < ActionController::Base
     to_address = data["recipient"]
     severity = data["severity"]
 
-    if data["event"] == "failed".freeze
-      if severity == "temporary".freeze
+    if data["event"] == "failed"
+      if severity == "temporary"
         process_bounce(message_id, to_address, SiteSetting.soft_bounce_score)
-      elsif severity == "permanent".freeze
+      elsif severity == "permanent"
         process_bounce(message_id, to_address, SiteSetting.hard_bounce_score)
       end
     end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 0042227..482b247 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -36,7 +36,7 @@ module ApplicationHelper
   end
 
   def shared_session_key
-    if SiteSetting.long_polling_base_url != '/'.freeze && current_user
+    if SiteSetting.long_polling_base_url != '/' && current_user
       sk = "shared_session_key"
       return request.env[sk] if request.env[sk]
 
@@ -282,7 +282,7 @@ module ApplicationHelper
         'query-input' => 'required name=search_term_string',
       }
     }
-    content_tag(:script, MultiJson.dump(json).html_safe, type: 'application/ld+json'.freeze)
+    content_tag(:script, MultiJson.dump(json).html_safe, type: 'application/ld+json')
   end
 
   def gsub_emoji_to_unicode(str)
diff --git a/app/jobs/regular/bulk_user_title_update.rb b/app/jobs/regular/bulk_user_title_update.rb
index 97d3f68..e98c024 100644
--- a/app/jobs/regular/bulk_user_title_update.rb
+++ b/app/jobs/regular/bulk_user_title_update.rb
@@ -2,8 +2,8 @@
 
 module Jobs
   class BulkUserTitleUpdate < ::Jobs::Base
-    UPDATE_ACTION = 'update'.freeze
-    RESET_ACTION = 'reset'.freeze
+    UPDATE_ACTION = 'update'
+    RESET_ACTION = 'reset'
 
     def execute(args)
       new_title = args[:new_title]
diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb
index 3c7fc34..94371ea 100644
--- a/app/jobs/regular/emit_web_hook_event.rb
+++ b/app/jobs/regular/emit_web_hook_event.rb
@@ -4,8 +4,8 @@ require 'excon'
 
 module Jobs
   class EmitWebHookEvent < ::Jobs::Base
-    PING_EVENT = 'ping'.freeze
-    MAX_RETRY_COUNT = 4.freeze
+    PING_EVENT = 'ping'
+    MAX_RETRY_COUNT = 4
     RETRY_BACKOFF = 5
 
     def execute(args)
diff --git a/app/jobs/scheduled/bookmark_reminder_notifications.rb b/app/jobs/scheduled/bookmark_reminder_notifications.rb
index 991e0d2..4dca47c 100644
--- a/app/jobs/scheduled/bookmark_reminder_notifications.rb
+++ b/app/jobs/scheduled/bookmark_reminder_notifications.rb
@@ -6,7 +6,7 @@ module Jobs
   # Any leftovers will be caught in the next run, because the reminder_at column
   # is set to NULL once a reminder has been sent.
   class BookmarkReminderNotifications < ::Jobs::Scheduled
-    JOB_RUN_NUMBER_KEY ||= 'jobs_bookmark_reminder_notifications_job_run_num'.freeze
+    JOB_RUN_NUMBER_KEY ||= 'jobs_bookmark_reminder_notifications_job_run_num'
     AT_DESKTOP_CONSISTENCY_RUN_NUMBER ||= 6
 
     every 5.minutes
diff --git a/app/jobs/scheduled/pending_queued_posts_reminder.rb b/app/jobs/scheduled/pending_queued_posts_reminder.rb
index 29bc670..c3a283b 100644
--- a/app/jobs/scheduled/pending_queued_posts_reminder.rb
+++ b/app/jobs/scheduled/pending_queued_posts_reminder.rb
@@ -41,7 +41,7 @@ module Jobs
     end
 
     def self.last_notified_key
-      "last_notified_queued_post_id".freeze
+      "last_notified_queued_post_id"
     end
   end
 end
diff --git a/app/jobs/scheduled/pending_reviewables_reminder.rb b/app/jobs/scheduled/pending_reviewables_reminder.rb
index df7a6a8..3cc4b12 100644
--- a/app/jobs/scheduled/pending_reviewables_reminder.rb
+++ b/app/jobs/scheduled/pending_reviewables_reminder.rb
@@ -45,7 +45,7 @@ module Jobs
     end
 
     def self.last_notified_key

[... diff too long, it was truncated ...]

GitHub sha: d0d5a138

Did you consider adding this to rubocop? That’s the only way to prevent them from sneaking back in in the future.

2 Likes