Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto-correction for Rails/HasManyOrHasOneDependent to be the Rails default (nil) #1384

Open
jdufresne opened this issue Nov 8, 2024 · 0 comments

Comments

@jdufresne
Copy link
Contributor

Is your feature request related to a problem? Please describe.

I have a large legacy code base. When adopting rubocop-rails defaults, the Rails/HasManyOrHasOneDependent presents many offenses that require manual code updates. As this code base already uses the default dependent implicitly, it seems reasonable that RuboCop could auto-correct the code to continue using it by specifying the argument explicitly.

The documentation for has_many / dependent is at:

https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#method-i-has_many

Controls what happens to the associated objects when their owner is destroyed. ...

  • nil do nothing (default).

Describe the solution you'd like

Given:

class User < ActiveRecord::Base
  has_many :comments
end

After running rubocup -A with Rails/HasManyOrHasOneDependent enabled:

class User < ActiveRecord::Base
  has_many :comments, dependent: nil
end

Describe alternatives you've considered

  • Disabling this cop as manually correcting it is too much of a burden
  • Manually correcting the offeneses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant