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

Include **/factories.rb in the inspection target #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

r7kamura
Copy link
Contributor

According to the factory_bot documentation, the default FactoryBot.definition_file_paths also includes factories.rb.

The load order is controlled by the FactoryBot.definition_file_paths attribute. The default load order is:

  1. factories.rb
  2. test/factories.rb
  3. test/factories/**/*.rb
  4. spec/factories.rb
  5. spec/factories/**/*.rb

Therefore, it would be reasonable to include this file in the inspection target.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • 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 r7kamura requested a review from a team as a code owner February 19, 2024 10:31
@@ -2,9 +2,8 @@
FactoryBot:
Enabled: true
Include:
- "**/spec/factories.rb"
- "**/factories.rb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m uncertain if it’s deliberate or not, but they would also load from factories/**/*.rb

Yet another doc https://github.com/thoughtbot/factory_bot/blob/cf3f21fcbbccbc40849c74a84eeb0bb0bd6c7606/docs/src/defining/file-paths.md?plain=1#L7 yhat doesn’t mention this consistently.

@@ -2,9 +2,8 @@
FactoryBot:
Enabled: true
Include:
- "**/spec/factories.rb"
- "**/factories.rb"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But would we also analyze eg app/presenters/factories.rb?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I think this is a risk we should accept when we decide to put **/ at the beginning of Include. It is also inconsistent that other Includes support it, but not only here.
Since it is rare for a constant to be defined in the plural form, I believe that this is rarely a problem in practice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that factory_bot defaults to **/factories.rb as the definition file path. However, I doubt that it should be the default for rubocop-factory_bot. Because I am concerned about the increased risk of false positives, as also #104 (comment).

Also, even if some users wanted to fix this, I felt it was not necessary to include it in the default because it could be avoided by simply adding the target path to FactoryBot: Include: .

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

Successfully merging this pull request may close these issues.

3 participants