Skip to content

Commit

Permalink
DEV: enable frozen string literal on all files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SamSaffron authored and tgxworld committed May 13, 2019
1 parent 4e1f251 commit 3099000
Show file tree
Hide file tree
Showing 2,201 changed files with 4,482 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/about_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'

class AboutController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/emojis_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'upload_creator'

class Admin::EmojisController < Admin::AdminController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/flagged_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'flag_query'

class Admin::FlaggedTopicsController < Admin::AdminController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/flags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'flag_query'

class Admin::FlagsController < Admin::AdminController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::GroupsController < Admin::AdminController
def bulk
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/impersonate_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::ImpersonateController < Admin::AdminController

def create
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/permalinks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::PermalinksController < Admin::AdminController

before_action :fetch_permalink, only: [:destroy]
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/plugins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::PluginsController < Admin::AdminController

def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/reports_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'report'

class Admin::ReportsController < Admin::AdminController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/screened_emails_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::ScreenedEmailsController < Admin::AdminController

def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/screened_ip_addresses_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'ip_addr'

class Admin::ScreenedIpAddressesController < Admin::AdminController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/screened_urls_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::ScreenedUrlsController < Admin::AdminController

def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/search_logs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::SearchLogsController < Admin::AdminController

def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/site_settings_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/site_texts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'seed_data/categories'
require_dependency 'seed_data/topics'

Expand Down
4 changes: 3 additions & 1 deletion app/controllers/admin/staff_action_logs_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::StaffActionLogsController < Admin::AdminController

def index
Expand All @@ -22,7 +24,7 @@ def diff

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,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/themes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'upload_creator'
require_dependency 'theme_store/tgz_exporter'
require 'base64'
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/user_fields_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::UserFieldsController < Admin::AdminController

def self.columns
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'user_destroyer'
require_dependency 'admin_user_index_query'
require_dependency 'admin_confirmation'
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/versions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse_updates'

class Admin::VersionsController < Admin::AdminController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/watched_words_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Admin::WatchedWordsController < Admin::AdminController

def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/web_hooks_controller.rb
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/badges_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class BadgesController < ApplicationController
skip_before_action :check_xhr, only: [:index, :show]

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'category_serializer'

class CategoriesController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/category_hashtags_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class CategoryHashtagsController < ApplicationController
requires_login

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/clicks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ClicksController < ApplicationController
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/composer_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'html_to_markdown'

class ComposerController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/composer_messages_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'composer_messages_finder'

class ComposerMessagesController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/directory_items_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class DirectoryItemsController < ApplicationController
PAGE_SIZE = 50

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/draft_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class DraftController < ApplicationController
requires_login

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/drafts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class DraftsController < ApplicationController
requires_login

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/email_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class EmailController < ApplicationController
layout 'no_ember'

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/embed_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class EmbedController < ApplicationController
skip_before_action :check_xhr, :preload_json, :verify_authenticity_token

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/exceptions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ExceptionsController < ApplicationController
skip_before_action :check_xhr, :preload_json
before_action :hide_search
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/export_csv_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class ExportCsvController < ApplicationController

skip_before_action :preload_json, :check_xhr, only: [:show]
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/finish_installation_controller.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class GroupsController < ApplicationController
include ApplicationHelper

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/highlight_js_controller.rb
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/inline_onebox_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'inline_oneboxer'

class InlineOneboxController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/invites_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'

class InvitesController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/list_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'topic_list_responder'

class ListController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/notifications_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'notification_serializer'

class NotificationsController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/offline_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/onebox_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'oneboxer'

class OneboxController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/permalinks_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PermalinksController < ApplicationController
skip_before_action :check_xhr, :preload_json

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/post_action_users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse'

class PostActionUsersController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/post_actions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'discourse'

class PostActionsController < ApplicationController
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'new_post_manager'
require_dependency 'post_creator'
require_dependency 'post_action_destroyer'
Expand Down Expand Up @@ -762,7 +764,7 @@ def create_params
end

def signature_for(args)
"post##" << Digest::SHA1.hexdigest(args
+"post##" << Digest::SHA1.hexdigest(args
.to_h
.to_a
.concat([["user", current_user.id]])
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/push_notification_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class PushNotificationController < ApplicationController
layout false
before_action :ensure_logged_in
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/queued_posts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'queued_post_serializer'

class QueuedPostsController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/qunit_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/robots_txt_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/safe_mode_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class SafeModeController < ApplicationController
layout 'no_ember'
before_action :ensure_safe_mode_enabled
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'search'

class SearchController < ApplicationController
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'rate_limiter'
require_dependency 'single_sign_on'
require_dependency 'single_sign_on_provider'
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/similar_topics_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'similar_topic_serializer'
require_dependency 'search/grouped_search_results'

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_dependency 'site_serializer'

class SiteController < ApplicationController
Expand Down
Loading

0 comments on commit 3099000

Please sign in to comment.