From 16e08228df47ba658796c52608bbd866b3a87cf8 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Sun, 30 Apr 2023 00:43:50 -0400 Subject: [PATCH] Fix Rails/SquishedSQLHeredocs cop (#24694) --- .rubocop_todo.yml | 9 --------- db/migrate/20170920024819_status_ids_to_timestamp_ids.rb | 4 ++-- .../20180608213548_reject_following_blocked_users.rb | 4 ++-- .../20190519130537_remove_boosts_widening_audience.rb | 2 +- lib/mastodon/snowflake.rb | 2 +- lib/tasks/tests.rake | 2 +- 6 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 42ea2342bd..172f44bad1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1520,15 +1520,6 @@ Rails/SkipsModelValidations: - 'spec/services/follow_service_spec.rb' - 'spec/services/update_account_service_spec.rb' -# This cop supports unsafe autocorrection (--autocorrect-all). -Rails/SquishedSQLHeredocs: - Exclude: - - 'db/migrate/20170920024819_status_ids_to_timestamp_ids.rb' - - 'db/migrate/20180608213548_reject_following_blocked_users.rb' - - 'db/post_migrate/20190519130537_remove_boosts_widening_audience.rb' - - 'lib/mastodon/snowflake.rb' - - 'lib/tasks/tests.rake' - Rails/TransactionExitStatement: Exclude: - 'app/lib/activitypub/activity/announce.rb' diff --git a/db/migrate/20170920024819_status_ids_to_timestamp_ids.rb b/db/migrate/20170920024819_status_ids_to_timestamp_ids.rb index 8679f8ece8..82e91f1e11 100644 --- a/db/migrate/20170920024819_status_ids_to_timestamp_ids.rb +++ b/db/migrate/20170920024819_status_ids_to_timestamp_ids.rb @@ -4,7 +4,7 @@ class StatusIdsToTimestampIds < ActiveRecord::Migration[5.1] Mastodon::Snowflake.define_timestamp_id # Set up the statuses.id column to use our timestamp-based IDs. - ActiveRecord::Base.connection.execute(<<~SQL) + ActiveRecord::Base.connection.execute(<<~SQL.squish) ALTER TABLE statuses ALTER COLUMN id SET DEFAULT timestamp_id('statuses') @@ -21,7 +21,7 @@ class StatusIdsToTimestampIds < ActiveRecord::Migration[5.1] # We lock the table during this so that the ID won't get clobbered, # but ID is indexed, so this should be a fast operation. - ActiveRecord::Base.connection.execute(<<~SQL) + ActiveRecord::Base.connection.execute(<<~SQL.squish) LOCK statuses; SELECT setval('statuses_id_seq', (SELECT MAX(id) FROM statuses)); ALTER TABLE statuses diff --git a/db/migrate/20180608213548_reject_following_blocked_users.rb b/db/migrate/20180608213548_reject_following_blocked_users.rb index 78f8df5383..bb21bd8fa0 100644 --- a/db/migrate/20180608213548_reject_following_blocked_users.rb +++ b/db/migrate/20180608213548_reject_following_blocked_users.rb @@ -2,14 +2,14 @@ class RejectFollowingBlockedUsers < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - blocked_follows = Follow.find_by_sql(<<-SQL) + blocked_follows = Follow.find_by_sql(<<-SQL.squish) select f.* from follows f inner join blocks b on f.account_id = b.target_account_id and f.target_account_id = b.account_id SQL - domain_blocked_follows = Follow.find_by_sql(<<-SQL) + domain_blocked_follows = Follow.find_by_sql(<<-SQL.squish) select f.* from follows f inner join accounts following on f.account_id = following.id inner join account_domain_blocks b on diff --git a/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb b/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb index d2d9242392..f1708b2e11 100644 --- a/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb +++ b/db/post_migrate/20190519130537_remove_boosts_widening_audience.rb @@ -2,7 +2,7 @@ class RemoveBoostsWideningAudience < ActiveRecord::Migration[5.2] disable_ddl_transaction! def up - public_boosts = Status.find_by_sql(<<-SQL) + public_boosts = Status.find_by_sql(<<-SQL.squish) SELECT boost.id FROM statuses AS boost LEFT JOIN statuses AS boosted ON boost.reblog_of_id = boosted.id diff --git a/lib/mastodon/snowflake.rb b/lib/mastodon/snowflake.rb index 8030288aff..32ed140c30 100644 --- a/lib/mastodon/snowflake.rb +++ b/lib/mastodon/snowflake.rb @@ -146,7 +146,7 @@ module Mastodon::Snowflake private def already_defined? - connection.execute(<<~SQL).values.first.first + connection.execute(<<~SQL.squish).values.first.first SELECT EXISTS( SELECT * FROM pg_proc WHERE proname = 'timestamp_id' ); diff --git a/lib/tasks/tests.rake b/lib/tasks/tests.rake index 35073b78bb..ceb421f4b2 100644 --- a/lib/tasks/tests.rake +++ b/lib/tasks/tests.rake @@ -113,7 +113,7 @@ namespace :tests do desc 'Populate the database with test data for 2.4.0' task populate_v2_4: :environment do # rubocop:disable Naming/VariableNumber - ActiveRecord::Base.connection.execute(<<~SQL) + ActiveRecord::Base.connection.execute(<<~SQL.squish) INSERT INTO "settings" (id, thing_type, thing_id, var, value, created_at, updated_at) VALUES