DEV: enable frozen string literal on all files

This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
This commit is contained in:
Sam Saffron
2019-05-03 08:17:27 +10:00
committed by Guo Xiang Tan
parent 4e1f25197d
commit 30990006a9
2201 changed files with 4482 additions and 90 deletions

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# see: https://github.com/rails/rails/issues/32995
#
# Rails 5.2 forces us to add Arel.sql to #order and #pluck

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ActiveRecord::Base
# Handle PG::UniqueViolation as well due to concurrency

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Just ignore included associations that are to be embedded in the root instead of
# throwing an exception in AMS 0.8.x.
#

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Ember
module Handlebars
class Template

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Speeds up #pluck so its about 2.2x faster, importantly makes pluck avoid creation of a slew
# of AR objects
#

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# review per rails release, this speeds up the inflector, we are not inflecting too much at the moment, except in dev
#
# note: I am working with the rails team on including this in official rails

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
class String
# new to Ruby 2.4, fastest way of matching a string to a regex
unless method_defined? :match?

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
#####
# Patch to allow open-uri to follow safe (http to https)
# and unsafe redirections (https to http).

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# perf fixes, review for each rails upgrade.
# This speeds up calls to present? and blank? on model instances

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Awaiting decision on https://github.com/rails/rails/issues/31190
if ENV['DISABLE_MIGRATION_ADVISORY_LOCK']
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# patch https://github.com/rack/rack/pull/600
#
class Rack::ETag

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Sam: This has now forked of rails. Trouble is we would never like to use "about 1 month" ever, we only want months for 2 or more months.
#
# Backporting a fix to rails itself may get too complex

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# this is a quick backport of a new method introduced in Rails 6
# to be removed after we upgrade to Rails 6
if ! defined? ActionView::Base.with_view_paths

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# barber patches to re-route raw compilation via ember compat handlebars
class Barber::Precompiler

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Discourse ships with a connection reaper
# this patch ensures that the connection reaper never runs in Rails
#

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# https://github.com/redis/redis-rb/pull/591
class Redis
class Client

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
unless ::Regexp.instance_methods.include?(:match?)
class ::Regexp
# this is the fast way of checking a regex (zero string allocs) added in Ruby 2.4

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# For some reason safe buffer is getting invalid encoding in some cases
# we work around the issue and log the problems
#
@@ -15,9 +17,9 @@ class ActiveSupport::SafeBuffer
raise
else
encoding_diags = "internal encoding #{Encoding.default_internal}, external encoding #{Encoding.default_external}"
encoding_diags = +"internal encoding #{Encoding.default_internal}, external encoding #{Encoding.default_external}"
unless encoding == Encoding::UTF_8
if encoding != Encoding::UTF_8
encoding_diags << " my encoding is #{encoding} "
self.force_encoding("UTF-8")
@@ -28,7 +30,7 @@ class ActiveSupport::SafeBuffer
Rails.logger.warn("Encountered a non UTF-8 string in SafeBuffer - #{self} - #{encoding_diags}")
end
unless value.encoding == Encoding::UTF_8
if value.encoding != Encoding::UTF_8
encoding_diags << " attempted to append encoding #{value.encoding} "

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'migration/safe_migrate'
Migration::SafeMigrate.patch_active_record!

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
module FreedomPatches
module SchemaMigrationDetails
def exec_migration(conn, direction)

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# This contains two patches to make sprockets more tolerable in dev
#
# 1. Stop computing asset paths which triggers sprockets to do mountains of work

View File

@@ -1,3 +1,5 @@
# frozen_string_literal: true
# This patch performs 2 functions
#
# 1. It caches all translations which drastically improves