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
+3
View File
@@ -12,6 +12,9 @@ AllCops:
Style/AndOr:
Enabled: true
Style/FrozenStringLiteralComment:
Enabled: true
# Do not use braces for hash literals when they are the last argument of a
# method call.
Style/BracesAroundHashParameters:
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
# Install development dependencies on Mac OS X using Homebrew (http://mxcl.github.com/homebrew)
# you probably already have git installed; ensure that it is the latest version
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
if github.pr_json && (github.pr_json["additions"] || 0) > 250 || (github.pr_json["deletions"] || 0) > 250
warn("This pull request is big! We prefer smaller PRs whenever possible, as they are easier to review. Can this be split into a few smaller PRs?")
end
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
source 'https://rubygems.org'
# if there is a super emergency and rubygems is playing up, try
#source 'http://production.cf.rubygems.org'
+2
View File
@@ -1,4 +1,6 @@
#!/usr/bin/env rake
# frozen_string_literal: true
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
class AboutController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'upload_creator'
class Admin::EmojisController < Admin::AdminController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'flag_query'
class Admin::FlaggedTopicsController < Admin::AdminController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'flag_query'
class Admin::FlagsController < Admin::AdminController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::GroupsController < Admin::AdminController
def bulk
end
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::ImpersonateController < Admin::AdminController
def create
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::PermalinksController < Admin::AdminController
before_action :fetch_permalink, only: [:destroy]
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::PluginsController < Admin::AdminController
def index
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'report'
class Admin::ReportsController < Admin::AdminController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::ScreenedEmailsController < Admin::AdminController
def index
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'ip_addr'
class Admin::ScreenedIpAddressesController < Admin::AdminController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::ScreenedUrlsController < Admin::AdminController
def index
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::SearchLogsController < Admin::AdminController
def index
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::SiteSettingsController < Admin::AdminController
rescue_from Discourse::InvalidParameters do |e|
render_json_error e.message, status: 422
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'seed_data/categories'
require_dependency 'seed_data/topics'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::StaffActionLogsController < Admin::AdminController
def index
@@ -22,7 +24,7 @@ class Admin::StaffActionLogsController < Admin::AdminController
diff_fields = {}
output = "<h2>#{CGI.escapeHTML(cur["name"].to_s)}</h2><p></p>"
output = +"<h2>#{CGI.escapeHTML(cur["name"].to_s)}</h2><p></p>"
diff_fields["name"] = {
prev: prev["name"].to_s,
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'upload_creator'
require_dependency 'theme_store/tgz_exporter'
require 'base64'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::UserFieldsController < Admin::AdminController
def self.columns
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'user_destroyer'
require_dependency 'admin_user_index_query'
require_dependency 'admin_confirmation'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse_updates'
class Admin::VersionsController < Admin::AdminController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::WatchedWordsController < Admin::AdminController
def index
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::WebHooksController < Admin::AdminController
before_action :fetch_web_hook, only: %i(show update destroy list_events bulk_events ping)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class BadgesController < ApplicationController
skip_before_action :check_xhr, only: [:index, :show]
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'category_serializer'
class CategoriesController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class CategoryHashtagsController < ApplicationController
requires_login
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ClicksController < ApplicationController
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'html_to_markdown'
class ComposerController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'composer_messages_finder'
class ComposerMessagesController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class DirectoryItemsController < ApplicationController
PAGE_SIZE = 50
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class DraftController < ApplicationController
requires_login
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class DraftsController < ApplicationController
requires_login
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class EmailController < ApplicationController
layout 'no_ember'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class EmbedController < ApplicationController
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ExceptionsController < ApplicationController
skip_before_action :check_xhr, :preload_json
before_action :hide_search
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ExportCsvController < ApplicationController
skip_before_action :preload_json, :check_xhr, only: [:show]
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class FinishInstallationController < ApplicationController
skip_before_action :check_xhr, :preload_json, :redirect_to_login_if_required
layout 'finish_installation'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class GroupsController < ApplicationController
include ApplicationHelper
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class HighlightJsController < ApplicationController
skip_before_action :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show]
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'inline_oneboxer'
class InlineOneboxController < ApplicationController
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
class InvitesController < ApplicationController
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'topic_list_responder'
class ListController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'notification_serializer'
class NotificationsController < ApplicationController
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class OfflineController < ApplicationController
layout false
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'oneboxer'
class OneboxController < ApplicationController
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class PermalinksController < ApplicationController
skip_before_action :check_xhr, :preload_json
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse'
class PostActionUsersController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse'
class PostActionsController < ApplicationController
+3 -1
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'new_post_manager'
require_dependency 'post_creator'
require_dependency 'post_action_destroyer'
@@ -762,7 +764,7 @@ class PostsController < ApplicationController
end
def signature_for(args)
"post##" << Digest::SHA1.hexdigest(args
+"post##" << Digest::SHA1.hexdigest(args
.to_h
.to_a
.concat([["user", current_user.id]])
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class PushNotificationController < ApplicationController
layout false
before_action :ensure_logged_in
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'queued_post_serializer'
class QueuedPostsController < ApplicationController
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class QunitController < ApplicationController
skip_before_action :check_xhr, :preload_json, :redirect_to_login_if_required
layout false
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class RobotsTxtController < ApplicationController
layout false
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class SafeModeController < ApplicationController
layout 'no_ember'
before_action :ensure_safe_mode_enabled
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'search'
class SearchController < ApplicationController
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
require_dependency 'single_sign_on'
require_dependency 'single_sign_on_provider'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'similar_topic_serializer'
require_dependency 'search/grouped_search_results'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'site_serializer'
class SiteController < ApplicationController
+3 -1
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'distributed_memoizer'
require_dependency 'file_helper'
@@ -35,7 +37,7 @@ class StaticController < ApplicationController
@page = 'faq' if @page == 'guidelines'
# Don't allow paths like ".." or "/" or anything hacky like that
@page.gsub!(/[^a-z0-9\_\-]/, '')
@page = @page.gsub(/[^a-z0-9\_\-]/, '')
if map.has_key?(@page)
@topic = Topic.find_by_id(SiteSetting.get(map[@page][:topic_id]))
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'wizard'
require_dependency 'wizard/builder'
require_dependency 'wizard/step_updater'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class StylesheetsController < ApplicationController
skip_before_action :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_source_map]
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class TagGroupsController < ApplicationController
requires_login
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'topic_list_responder'
require_dependency 'topics_bulk_action'
require_dependency 'topic_query'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class ThemesController < ::ApplicationController
def assets
theme_ids = params[:ids].to_s.split("-").map(&:to_i)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'topic_view'
require_dependency 'promotion'
require_dependency 'url_helper'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "mini_mime"
require_dependency 'upload_creator'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class UserActionsController < ApplicationController
def index
+3 -1
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class UserApiKeysController < ApplicationController
layout 'no_ember'
@@ -91,7 +93,7 @@ class UserApiKeysController < ApplicationController
end
if params[:auth_redirect]
redirect_path = "#{params[:auth_redirect]}?payload=#{CGI.escape(@payload)}"
redirect_path = +"#{params[:auth_redirect]}?payload=#{CGI.escape(@payload)}"
redirect_path << "&oneTimePassword=#{CGI.escape(otp_payload)}" if scopes.include?("one_time_password")
redirect_to(redirect_path)
else
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'letter_avatar'
class UserAvatarsController < ApplicationController
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class UserBadgesController < ApplicationController
before_action :ensure_badges_enabled
@@ -1,4 +1,6 @@
# -*- encoding : utf-8 -*-
# frozen_string_literal: true
require_dependency 'email'
require_dependency 'enum'
require_dependency 'user_name_suggester'
@@ -58,7 +60,7 @@ class Users::OmniauthCallbacksController < ApplicationController
end
if parsed && (parsed.host == nil || parsed.host == Discourse.current_hostname)
@origin = "#{parsed.path}"
@origin = +"#{parsed.path}"
@origin << "?#{parsed.query}" if parsed.query
end
end
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse_hub'
require_dependency 'user_name_suggester'
require_dependency 'rate_limiter'
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
require_dependency 'email_validator'
require_dependency 'email_updater'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require "openssl"
class WebhooksController < ActionController::Base
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'wizard'
require_dependency 'wizard/builder'
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module CommonHelper
def render_google_universal_analytics_code
if Rails.env.production? && SiteSetting.ga_universal_tracking_code.present?
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module EmailHelper
def mailing_list_topic(topic, post_count)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module EmbedHelper
def embed_post_date(dt)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module ListHelper
def page_links(topic)
posts = topic.posts_count
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module TopicsHelper
include ApplicationHelper
+4 -2
View File
@@ -1,9 +1,11 @@
# frozen_string_literal: true
module UserNotificationsHelper
include GlobalPath
def indent(text, by = 2)
spacer = " " * by
result = ""
result = +""
text.each_line do |line|
result << spacer << line
end
@@ -32,7 +34,7 @@ module UserNotificationsHelper
def first_paragraphs_from(html)
doc = Nokogiri::HTML(html)
result = ""
result = +""
length = 0
doc.css('body > p, aside.onebox, body > ul, body > blockquote').each do |node|
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
def self.queued
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Skippable
extend ActiveSupport::Concern
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
class Jobs::Onceoff < Jobs::Base
sidekiq_options retry: false
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class CleanUpSidekiqStatistic < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class ClearWidthAndHeight < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class CorrectMissingDualstackUrls < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class CreateTagsSearchIndex < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixFeaturedLinkForTopics < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixInvalidGravatarUploads < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency "upload_fixer"
module Jobs
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixOutOfSyncUserUploadedAvatar < Jobs::Onceoff
def execute_onceoff(args)
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixPostsRead < Jobs::Onceoff
def execute_onceoff(args)
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'user_destroyer'
module Jobs
@@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'jobs/scheduled/grant_anniversary_badges'
module Jobs
+2
View File
@@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixS3Etags < Jobs::Onceoff

Some files were not shown because too many files have changed in this diff Show More