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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Include `**/factories.rb` in the inspection target. ([@r7kamura])

## 2.25.1 (2024-01-08)

- Fix a false positive for `FactoryBot/CreateList` when create call does have method calls and repeat multiple times with other argument. ([@ydah])
Expand Down
3 changes: 1 addition & 2 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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: .

- "**/spec/factories/**/*.rb"
- "**/test/factories.rb"
- "**/test/factories/**/*.rb"
- "**/features/support/factories/**/*.rb"
DocumentationBaseURL: https://docs.rubocop.org/rubocop-factory_bot
Expand Down