about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNick Schonning <nschonni@gmail.com>2023-02-19 20:19:40 -0500
committerGitHub <noreply@github.com>2023-02-20 02:19:40 +0100
commit597767a9f7ca846be9fbca826aba362f8387a60f (patch)
treec25188e552be7112fecc4654c0e25ed2ebd4768d
parent8ef09813a2b46d99fe9c7e39beba2a68052c17d1 (diff)
Autofix Rubocop Rails/RedundantForeignKey (#23731)
-rw-r--r--.rubocop_todo.yml12
-rw-r--r--app/models/custom_filter.rb4
-rw-r--r--app/models/follow_recommendation.rb2
-rw-r--r--app/models/report.rb2
-rw-r--r--app/models/status.rb2
-rw-r--r--app/models/user_ip.rb2
-rw-r--r--db/post_migrate/20221101190723_backfill_admin_action_logs.rb2
-rw-r--r--db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb2
8 files changed, 8 insertions, 20 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 6fb471600..1a524e6fd 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -2459,18 +2459,6 @@ Rails/RakeEnvironment:
     - 'lib/tasks/repo.rake'
     - 'lib/tasks/statistics.rake'
 
-# Offense count: 8
-# This cop supports safe autocorrection (--autocorrect).
-Rails/RedundantForeignKey:
-  Exclude:
-    - 'app/models/custom_filter.rb'
-    - 'app/models/follow_recommendation.rb'
-    - 'app/models/report.rb'
-    - 'app/models/status.rb'
-    - 'app/models/user_ip.rb'
-    - 'db/post_migrate/20221101190723_backfill_admin_action_logs.rb'
-    - 'db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb'
-
 # Offense count: 29
 # Configuration parameters: Include.
 # Include: db/**/*.rb
diff --git a/app/models/custom_filter.rb b/app/models/custom_filter.rb
index 5a4a974be..b70e53bd5 100644
--- a/app/models/custom_filter.rb
+++ b/app/models/custom_filter.rb
@@ -33,8 +33,8 @@ class CustomFilter < ApplicationRecord
   enum action: [:warn, :hide], _suffix: :action
 
   belongs_to :account
-  has_many :keywords, class_name: 'CustomFilterKeyword', foreign_key: :custom_filter_id, inverse_of: :custom_filter, dependent: :destroy
-  has_many :statuses, class_name: 'CustomFilterStatus', foreign_key: :custom_filter_id, inverse_of: :custom_filter, dependent: :destroy
+  has_many :keywords, class_name: 'CustomFilterKeyword', inverse_of: :custom_filter, dependent: :destroy
+  has_many :statuses, class_name: 'CustomFilterStatus', inverse_of: :custom_filter, dependent: :destroy
   accepts_nested_attributes_for :keywords, reject_if: :all_blank, allow_destroy: true
 
   validates :title, :context, presence: true
diff --git a/app/models/follow_recommendation.rb b/app/models/follow_recommendation.rb
index e552b5a88..501f8ecb6 100644
--- a/app/models/follow_recommendation.rb
+++ b/app/models/follow_recommendation.rb
@@ -12,7 +12,7 @@ class FollowRecommendation < ApplicationRecord
   self.primary_key = :account_id
 
   belongs_to :account_summary, foreign_key: :account_id
-  belongs_to :account, foreign_key: :account_id
+  belongs_to :account
 
   scope :localized, ->(locale) { joins(:account_summary).merge(AccountSummary.localized(locale)) }
 
diff --git a/app/models/report.rb b/app/models/report.rb
index 525d22ad5..fe6c292c5 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -32,7 +32,7 @@ class Report < ApplicationRecord
   belongs_to :action_taken_by_account, class_name: 'Account', optional: true
   belongs_to :assigned_account, class_name: 'Account', optional: true
 
-  has_many :notes, class_name: 'ReportNote', foreign_key: :report_id, inverse_of: :report, dependent: :destroy
+  has_many :notes, class_name: 'ReportNote', inverse_of: :report, dependent: :destroy
   has_many :notifications, as: :activity, dependent: :destroy
 
   scope :unresolved, -> { where(action_taken_at: nil) }
diff --git a/app/models/status.rb b/app/models/status.rb
index 102dfa994..e0ad29103 100644
--- a/app/models/status.rb
+++ b/app/models/status.rb
@@ -53,7 +53,7 @@ class Status < ApplicationRecord
   belongs_to :application, class_name: 'Doorkeeper::Application', optional: true
 
   belongs_to :account, inverse_of: :statuses
-  belongs_to :in_reply_to_account, foreign_key: 'in_reply_to_account_id', class_name: 'Account', optional: true
+  belongs_to :in_reply_to_account, class_name: 'Account', optional: true
   belongs_to :conversation, optional: true
   belongs_to :preloadable_poll, class_name: 'Poll', foreign_key: 'poll_id', optional: true
 
diff --git a/app/models/user_ip.rb b/app/models/user_ip.rb
index a8e802e13..1da615762 100644
--- a/app/models/user_ip.rb
+++ b/app/models/user_ip.rb
@@ -11,7 +11,7 @@
 class UserIp < ApplicationRecord
   self.primary_key = :user_id
 
-  belongs_to :user, foreign_key: :user_id
+  belongs_to :user
 
   def readonly?
     true
diff --git a/db/post_migrate/20221101190723_backfill_admin_action_logs.rb b/db/post_migrate/20221101190723_backfill_admin_action_logs.rb
index 48ef1e6e3..6ab76a8f7 100644
--- a/db/post_migrate/20221101190723_backfill_admin_action_logs.rb
+++ b/db/post_migrate/20221101190723_backfill_admin_action_logs.rb
@@ -62,7 +62,7 @@ class BackfillAdminActionLogs < ActiveRecord::Migration[6.1]
     # Cannot use usual polymorphic support because of namespacing issues
     belongs_to :status, foreign_key: :target_id
     belongs_to :account, foreign_key: :target_id
-    belongs_to :user, foreign_key: :user_id
+    belongs_to :user
     belongs_to :domain_block, foreign_key: :target_id
     belongs_to :domain_allow, foreign_key: :target_id
     belongs_to :email_domain_block, foreign_key: :target_id
diff --git a/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb b/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb
index 279053ab9..42b7f3625 100644
--- a/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb
+++ b/db/post_migrate/20221206114142_backfill_admin_action_logs_again.rb
@@ -62,7 +62,7 @@ class BackfillAdminActionLogsAgain < ActiveRecord::Migration[6.1]
     # Cannot use usual polymorphic support because of namespacing issues
     belongs_to :status, foreign_key: :target_id
     belongs_to :account, foreign_key: :target_id
-    belongs_to :user, foreign_key: :user_id
+    belongs_to :user
     belongs_to :domain_block, foreign_key: :target_id
     belongs_to :domain_allow, foreign_key: :target_id
     belongs_to :email_domain_block, foreign_key: :target_id