Skip to content

Commit

Permalink
[Fix #106] Mark Rails/ReflectionClassName as unsafe
Browse files Browse the repository at this point in the history
Fixes #106.

This PR marks `Rails/ReflectionClassName` as unsafe.

And it would be possible to exclude `to_s` call other than constants.
I will consider opening it as a separate PR.
  • Loading branch information
koic committed Apr 27, 2021
1 parent 64a44f1 commit c9d6e7e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
* [#451](https://github.com/rubocop/rubocop-rails/issues/451): Make `Rails/RelativeDateConstant` aware of `yesterday` and `tomorrow` methods. ([@koic][])
* [#454](https://github.com/rubocop/rubocop-rails/pull/454): Mark `Rails/WhereExists` as unsafe auto-correction. ([@koic][])
* [#379](https://github.com/rubocop/rubocop-rails/issues/379): Mark `Rails/DynamicFindBy` as unsafe. ([@koic][])
* [#106](https://github.com/rubocop/rubocop-rails/issues/106): Mark `Rails/ReflectionClassName` as unsafe. ([@koic][])
* [#456](https://github.com/rubocop/rubocop-rails/pull/456): Drop Ruby 2.4 support. ([@koic][])
* [#462](https://github.com/rubocop/rubocop-rails/pull/462): Require RuboCop 1.7 or higher. ([@koic][])

Expand Down
2 changes: 2 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,9 @@ Rails/RedundantReceiverInWithOptions:
Rails/ReflectionClassName:
Description: 'Use a string for `class_name` option value in the definition of a reflection.'
Enabled: true
Safe: false
VersionAdded: '0.64'
VersionChanged: '2.10'

Rails/RefuteMethods:
Description: 'Use `assert_not` methods instead of `refute` methods.'
Expand Down
6 changes: 4 additions & 2 deletions docs/modules/ROOT/pages/cops_rails.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3163,14 +3163,16 @@ end
| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged

| Enabled
| Yes
| No
| No
| 0.64
| -
| 2.10
|===

This cop checks if the value of the option `class_name`, in
the definition of a reflection is a string.
It is marked as unsafe because it cannot be determined whether
constant or method return value specified to `class_name` is a string.

=== Examples

Expand Down
2 changes: 2 additions & 0 deletions lib/rubocop/cop/rails/reflection_class_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Cop
module Rails
# This cop checks if the value of the option `class_name`, in
# the definition of a reflection is a string.
# It is marked as unsafe because it cannot be determined whether
# constant or method return value specified to `class_name` is a string.
#
# @example
# # bad
Expand Down

0 comments on commit c9d6e7e

Please sign in to comment.