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-13 09:31:32 +08:00
committed by Guo Xiang Tan
parent 4e1f25197d
commit 30990006a9
2201 changed files with 4482 additions and 90 deletions
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
if ENV['DISCOURSE_DUMP_HEAP'] == "1"
require 'objspace'
ObjectSpace.trace_object_allocations_start
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Discourse::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Load the rails application
require File.expand_path('../application', __FILE__)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Discourse::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Discourse::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Discourse::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Discourse::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
+2
View File
@@ -1,2 +1,4 @@
# frozen_string_literal: true
require 'mini_sql_multisite_connection'
::DB = MiniSqlMultisiteConnection.instance
@@ -1,3 +1,5 @@
# frozen_string_literal: true
unless Discourse.skip_post_deployment_migrations?
Rails.application.config.paths['db/migrate'] << Rails.root.join(
Discourse::DB_POST_MIGRATE_PATH
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
if Rails.env.development? && ENV['DISCOURSE_FLUSH_REDIS']
puts "Flushing redis (development mode)"
$redis.flushall
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Dir["#{Rails.root}/lib/freedom_patches/*.rb"].each do |f|
require(f)
end
+2
View File
@@ -1 +1,3 @@
# frozen_string_literal: true
require 'sql_builder'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
MessageBus.site_id_lookup do |env = nil|
if env
setup_message_bus_env(env)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# load up git version into memory
# this way if it changes underneath we still have
# the original version
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Some sanity checking so we don't count on an unindexed column on boot
begin
if ActiveRecord::Base.connection.table_exists?(:users) &&
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# If Mini Profiler is included via gem
if Rails.configuration.respond_to?(:load_mini_profiler) && Rails.configuration.load_mini_profiler
require 'rack-mini-profiler'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "openssl"
require "openid_redis_store"
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'discourse_iife'
Rails.application.config.assets.configure do |env|
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'rack/protection'
Rails.configuration.middleware.use Rack::Protection::FrameOptions
@@ -1,3 +1,5 @@
# frozen_string_literal: true
%i(
topic_recovered
).each do |event|
@@ -1 +1,3 @@
# frozen_string_literal: true
Excon::DEFAULTS[:omit_default_port] = true
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency "site_icon_manager"
DiscourseEvent.on(:site_setting_changed) do |name, old_value, new_value|
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# tiny middleware to force https if needed
class Discourse::ForceHttpsMiddleware
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "middleware/anonymous_cache"
enabled =
+2
View File
@@ -1 +1,3 @@
# frozen_string_literal: true
require_dependency 'scheduler/defer'
+2
View File
@@ -1,2 +1,4 @@
# frozen_string_literal: true
# pg performs inconsistently with large amounts of connections
Discourse.start_connection_reaper
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# order: after 02-freedom_patches.rb
require 'i18n/backend/discourse_i18n'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
if Rails.env.development? && RUBY_VERSION.match?(/^2\.5\.[23]/)
STDERR.puts "WARNING: Discourse development environment runs slower on Ruby 2.5.3 or below"
STDERR.puts "We recommend you upgrade to Ruby 2.6.1 for the optimal development performance"
+2
View File
@@ -1,2 +1,4 @@
# frozen_string_literal: true
# Not sure why it's not using this by default!
MultiJson.engine = :oj
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'twitter_api'
Onebox.options = {
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'webpush'
if SiteSetting.vapid_public_key.blank? || SiteSetting.vapid_private_key.blank? || SiteSetting.vapid_public_key_bytes.blank?
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
Rails.application.config.assets.configure do |env|
env.logger = Logger.new('/dev/null')
end
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Not fussed setting secret_token anymore, that is only required for
# backwards support of "seamless" upgrade from Rails 3.
# Discourse has shipped Rails 3 for a very long time.
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
#
require_dependency 'discourse_cookie_store'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "sidekiq/pausable"
Sidekiq.configure_client do |config|
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class SilenceLogger < Rails::Rack::Logger
PATH_INFO = 'PATH_INFO'.freeze
HTTP_X_SILENCE_LOGGER = 'HTTP_X_SILENCE_LOGGER'.freeze
@@ -1 +1,3 @@
# frozen_string_literal: true
ActiveRecord::Base.public_send(:include, ActiveModel::ForbiddenAttributesProtection)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Check that the app is configured correctly. Raise some helpful errors if something is wrong.
if defined?(Rails::Server) && Rails.env.production? # Only run these checks when starting up a production server
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# this is a trivial graceful restart on touch of tmp/restart.
#
# It simply drains all the requests (waits up to 4 seconds) and issues a HUP
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Be sure to restart your server when you modify this file.
#
# This file contains settings for ActionController::ParamsWrapper which
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
if (Rails.env.production? && SiteSetting.logging_provider == 'lograge') || ENV["ENABLE_LOGRAGE"]
require 'lograge'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# we want MesageBus in the absolute front
# this is important cause the vast majority of web requests go to it
# this allows us to avoid full middleware crawls each time
+2
View File
@@ -1,4 +1,6 @@
# encoding: utf-8
# frozen_string_literal: true
# source: https://github.com/svenfuchs/i18n/blob/master/test/test_data/locales/plurals.rb
{
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
if ENV['RAILS_ENV'] == 'production'
# First, you need to change these below to your situation.
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "sidekiq/web"
require "mini_scheduler/web"
require_dependency "admin_constraint"
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# spring speeds up your dev environment, similar to zeus but build in Ruby
#
# gem install spring
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# See http://unicorn.bogomips.org/Unicorn/Configurator.html
if ENV["LOGSTASH_UNICORN_URI"]