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

Add autocorrection for `Rails/ReflectionClassName`

Open tejasbubane opened this issue 5 years ago • 2 comments

Before submitting the PR make sure the following are checked:

  • [x] Wrote good commit messages.
  • [ ] Commit message starts with [Fix #issue-number] (if the related issue exists).
  • [x] Feature branch is up-to-date with master (if not - rebase it).
  • [x] Squashed related commits together.
  • [x] Added tests.
  • [x] Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • [ ] If this is a new cop, consider making a corresponding update to the Rails Style Guide.
  • [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • [x] Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

tejasbubane avatar Jul 20 '20 19:07 tejasbubane

~~Waiting for #302 to be merged to fix the CI.~~ Fixed

tejasbubane avatar Jul 21 '20 10:07 tejasbubane

@tejasbubane ping.

koic avatar Jun 06 '22 03:06 koic

@koic Sorry for the delay on this one, I've made the changes to autocorrect only for constants or .name or .to_s.

tejasbubane avatar Jan 04 '23 22:01 tejasbubane

@tejasbubane Can you rebase with the latest master branch?

koic avatar Apr 03 '23 02:04 koic

@koic Rebased.

tejasbubane avatar Apr 03 '23 10:04 tejasbubane

Thanks!

koic avatar Apr 03 '23 16:04 koic

Is there an advantage to using this rule or is this just a stylistic choice? The advantage I can see to using reflection is that if a class name changes and your relation relies on it, it will be obvious very quickly as your app will fail to start if you have failed to update references to the underlying class.

alex-tan avatar Nov 06 '23 12:11 alex-tan

It will fail both ways, won’t it? I guess to save on cascade class autoloading.

pirj avatar Nov 06 '23 18:11 pirj

Ah I see. If there's a circular dependency.

Thanks.

alex-tan avatar Nov 07 '23 20:11 alex-tan