rubocop-rails
rubocop-rails copied to clipboard
Cop idea: Meaningful Foreign Key Naming cop
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
Is this truly best practice? I doubt the validity of the style guide rule.
See https://github.com/rubocop/rails-style-guide/pull/189 and https://github.com/rubocop/rails-style-guide/pull/295
Agreed with @koic. I do not believe many people would wish to write explicit names or that this will be much useful.
https://github.com/rubocop/rails-style-guide/pull/295#issuecomment-1699388210
I’m on the fence. Let’s see real-workd usages to decide