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

@ -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:

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

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

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'

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.

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
class AboutController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'upload_creator'
class Admin::EmojisController < Admin::AdminController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'flag_query'
class Admin::FlaggedTopicsController < Admin::AdminController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require 'flag_query'
class Admin::FlagsController < Admin::AdminController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::GroupsController < Admin::AdminController
def bulk
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::ImpersonateController < Admin::AdminController
def create

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::PermalinksController < Admin::AdminController
before_action :fetch_permalink, only: [:destroy]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::PluginsController < Admin::AdminController
def index

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'report'
class Admin::ReportsController < Admin::AdminController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::ScreenedEmailsController < Admin::AdminController
def index

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'ip_addr'
class Admin::ScreenedIpAddressesController < Admin::AdminController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::ScreenedUrlsController < Admin::AdminController
def index

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::SearchLogsController < Admin::AdminController
def index

View File

@ -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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'seed_data/categories'
require_dependency 'seed_data/topics'

View File

@ -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,

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'upload_creator'
require_dependency 'theme_store/tgz_exporter'
require 'base64'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::UserFieldsController < Admin::AdminController
def self.columns

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'user_destroyer'
require_dependency 'admin_user_index_query'
require_dependency 'admin_confirmation'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse_updates'
class Admin::VersionsController < Admin::AdminController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Admin::WatchedWordsController < Admin::AdminController
def index

View File

@ -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)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class BadgesController < ApplicationController
skip_before_action :check_xhr, only: [:index, :show]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'category_serializer'
class CategoriesController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class CategoryHashtagsController < ApplicationController
requires_login

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ClicksController < ApplicationController
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'html_to_markdown'
class ComposerController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'composer_messages_finder'
class ComposerMessagesController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class DirectoryItemsController < ApplicationController
PAGE_SIZE = 50

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class DraftController < ApplicationController
requires_login

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class DraftsController < ApplicationController
requires_login

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EmailController < ApplicationController
layout 'no_ember'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class EmbedController < ApplicationController
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ExceptionsController < ApplicationController
skip_before_action :check_xhr, :preload_json
before_action :hide_search

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class ExportCsvController < ApplicationController
skip_before_action :preload_json, :check_xhr, only: [:show]

View File

@ -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'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class GroupsController < ApplicationController
include ApplicationHelper

View File

@ -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]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'inline_oneboxer'
class InlineOneboxController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
class InvitesController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'topic_list_responder'
class ListController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'notification_serializer'
class NotificationsController < ApplicationController

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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'oneboxer'
class OneboxController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class PermalinksController < ApplicationController
skip_before_action :check_xhr, :preload_json

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse'
class PostActionUsersController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse'
class PostActionsController < ApplicationController

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]])

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class PushNotificationController < ApplicationController
layout false
before_action :ensure_logged_in

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'queued_post_serializer'
class QueuedPostsController < ApplicationController

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

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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class SafeModeController < ApplicationController
layout 'no_ember'
before_action :ensure_safe_mode_enabled

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'search'
class SearchController < ApplicationController

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'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'similar_topic_serializer'
require_dependency 'search/grouped_search_results'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'site_serializer'
class SiteController < ApplicationController

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]))

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'wizard'
require_dependency 'wizard/builder'
require_dependency 'wizard/step_updater'

View File

@ -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]

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class TagGroupsController < ApplicationController
requires_login

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'topic_list_responder'
require_dependency 'topics_bulk_action'
require_dependency 'topic_query'

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)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'topic_view'
require_dependency 'promotion'
require_dependency 'url_helper'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "mini_mime"
require_dependency 'upload_creator'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class UserActionsController < ApplicationController
def index

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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'letter_avatar'
class UserAvatarsController < ApplicationController

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class UserBadgesController < ApplicationController
before_action :ensure_badges_enabled

View File

@ -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

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'discourse_hub'
require_dependency 'user_name_suggester'
require_dependency 'rate_limiter'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'rate_limiter'
require_dependency 'email_validator'
require_dependency 'email_updater'

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require "openssl"
class WebhooksController < ActionController::Base

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'wizard'
require_dependency 'wizard/builder'

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?

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module EmailHelper
def mailing_list_topic(topic, post_count)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module EmbedHelper
def embed_post_date(dt)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module ListHelper
def page_links(topic)
posts = topic.posts_count

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module TopicsHelper
include ApplicationHelper

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|

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
def self.queued

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Skippable
extend ActiveSupport::Concern

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
class Jobs::Onceoff < Jobs::Base
sidekiq_options retry: false

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class CleanUpSidekiqStatistic < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class ClearWidthAndHeight < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class CorrectMissingDualstackUrls < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class CreateTagsSearchIndex < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixFeaturedLinkForTopics < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixInvalidGravatarUploads < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency "upload_fixer"
module Jobs

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixOutOfSyncUserUploadedAvatar < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
module Jobs
class FixPostsRead < Jobs::Onceoff
def execute_onceoff(args)

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'user_destroyer'
module Jobs

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
require_dependency 'jobs/scheduled/grant_anniversary_badges'
module Jobs

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