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

Fix a false negative for `FactoryBot/AssociationStyle` when using keyword traits with explicit associations

Open r7kamura opened this issue 1 week ago • 0 comments
trafficstars

A change related to keywords was introduced here:

  • https://github.com/rubocop/rubocop-factory_bot/pull/60

At that time, the implementation was adjusted so that the following code would not be treated as an offense, but shouldn’t this actually be considered an offense?

# bad
association :foo, :alias

# good
foo factory: %i[foo alias]

In addition to changing the implementation, I made a few improvements:

  1. Converted KEYWORDS from an Array to a Set to improve performance.
  2. Updated the code so that only correctable explicit associations are treated as offenses, making the intention clearer.

Before submitting the PR make sure the following are checked:

  • [x] Feature branch is up-to-date with master (if not - rebase it).
  • [x] Squashed related commits together.
  • [x] Added tests.
  • [x] Updated documentation.
  • [x] Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • [x] The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have created a new cop:

  • [ ] Added the new cop to config/default.yml.
  • [ ] The cop is configured as Enabled: pending in config/default.yml.
  • [ ] The cop documents examples of good and bad code.
  • [ ] The tests assert both that bad code is reported and that good code is not reported.
  • [ ] Set VersionAdded: "<<next>>" in default/config.yml.

If you have modified an existing cop's configuration options:

  • [ ] Set VersionChanged: "<<next>>" in config/default.yml.

r7kamura avatar Nov 18 '25 04:11 r7kamura