rubocop-rails icon indicating copy to clipboard operation
rubocop-rails copied to clipboard

Cop idea: Meaningful Foreign Key Naming cop

Open ydakuka opened this issue 2 years ago • 4 comments

Reference: https://rails.rubystyle.guide/#meaningful-foreign-key-naming

Actual behavior

I have the code:

# frozen_string_literal: true

class AddFkArticlesToAuthors < ActiveRecord::Migration[6.0]
  def change
    add_foreign_key :articles, :authors
  end
end

I will run rubocop and not get any offences:

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop db/migrate/20230827081451_add_fk_articles_to_authors.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Rubocop

ydakuka@yauhenid:~/Work/project$ bin/rails_docker rubocop -V
1.55.1 (using Parser 3.2.2.3, rubocop-ast 1.29.0, running on ruby 2.7.8) [x86_64-linux]
  - rubocop-capybara 2.18.0
  - rubocop-factory_bot 2.23.1
  - rubocop-performance 1.18.0
  - rubocop-rails 2.20.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.23.0
  - rubocop-thread_safety 0.5.1

ydakuka avatar Aug 27 '23 08:08 ydakuka

Is this truly best practice? I doubt the validity of the style guide rule.

koic avatar Aug 27 '23 08:08 koic

See https://github.com/rubocop/rails-style-guide/pull/189 and https://github.com/rubocop/rails-style-guide/pull/295

ydakuka avatar Aug 28 '23 12:08 ydakuka

Agreed with @koic. I do not believe many people would wish to write explicit names or that this will be much useful.

fatkodima avatar Aug 29 '23 07:08 fatkodima

https://github.com/rubocop/rails-style-guide/pull/295#issuecomment-1699388210

I’m on the fence. Let’s see real-workd usages to decide

pirj avatar Aug 30 '23 15:08 pirj