Skip to content

Conversation

ydakuka
Copy link

@ydakuka ydakuka commented Feb 23, 2025

Fix #13


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.

@ydakuka ydakuka requested a review from a team as a code owner February 23, 2025 06:49
@pirj
Copy link
Member

pirj commented Feb 23, 2025

What about (1..3).map { |n| create(:foo, n) }?

@pirj
Copy link
Member

pirj commented Feb 23, 2025

Please correct me if I’m mistaken, but create_pair/create_list is a syntactic sugar over create in iterators.
Is it worth adding that much code to cover this edge case?

Not to mention that create_list may be inferior in some cases thoughtbot/factory_bot#1444

I kindly appreciate an immense effort you’ve put into this PR, @ydakuka 🙏🙌🙇‍♂️
What motivated you to do so in the first place? Is it some major frustration over the codebase you’re working with on a daily basis?

@ydakuka
Copy link
Author

ydakuka commented Feb 23, 2025

What about (1..3).map { |n| create(:foo, n) }?

It will be ignored, like this: https://github.com/rubocop/rubocop-factory_bot/blob/master/spec/rubocop/cop/factory_bot/create_list_spec.rb#L63

@ydakuka
Copy link
Author

ydakuka commented Feb 23, 2025

Please correct me if I’m mistaken, but create_pair/create_list is a syntactic sugar over create in iterators.
Is it worth adding that much code to cover this edge case?

There is the issue #50 for this edge case, but personally, I don’t use it at all.

Not to mention that create_list may be inferior in some cases thoughtbot/factory_bot#1444

I can add an exception to ignore cases where create_list takes a block. What do you think about it? Or is n.times { ... } a better replacement for this case?
I've found more cases why this replacement might be unsafe. Hm.

I kindly appreciate an immense effort you’ve put into this PR, @ydakuka 🙏🙌🙇‍♂️
What motivated you to do so in the first place? Is it some major frustration over the codebase you’re working with on a daily basis?

No, I found an interesting issue and have some time to work on it.

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.

Detect iterations over range in FactoryBot/CreateList

2 participants