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

Add the excessive_create_list cop #83

Merged

Conversation

ddieulivol
Copy link
Contributor

Cop used to signal when we create a lot of factory objects with FactoryBot (configurable with the MaxAmount option).

        # @example MaxAmount: 10 (default)
        #   # We do not allow more than 10 items to be created
        #
        #   # bad
        #   create_list(:merge_request, 1000, state: :opened)
        #
        #   # good
        #   create_list(:merge_request, 10, state: :opened)
        #

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.

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Thank you!

@ydah
Copy link
Member

ydah commented Nov 11, 2023

@ydah
Copy link
Member

ydah commented Nov 11, 2023

If this is an offense, isn't there a way to resolve it? Because, for example, if you want to create a record beyond 10, you're creating it because that's what you need, right? But if they make it an offense, the only way to solve the problem is to disable this cop, and I don't think that will lead to a fundamental solution. If I have missed something, please point it out.

@pirj
Copy link
Member

pirj commented Nov 11, 2023

We can think of this as LineLength, NestedGroups or MultipleMemoizedHelpers. There is usually no easy or automated way to fix the latter two. However, usually letting those numbers slide is causing increased maintenance costs.
Even the default 10 seems excessive to me. One commonly used case that comes to mind that would need that many is pagination. But usually this can be tested with a lower per_page value, or even by stubbing a hardcoded per page const.

@ddieulivol
Copy link
Contributor Author

CI seems to be failing, can you confirm? https://github.com/rubocop/rubocop-factory_bot/actions/runs/6827313104/job/18570505855#step:5:1

It's probably a change introduced in the latest rubocop version (given that the edge Rubocop job is failing). I'll go ahead and make the change 👍.

@ddieulivol
Copy link
Contributor Author

CI seems to be failing, can you confirm? https://github.com/rubocop/rubocop-factory_bot/actions/runs/6827313104/job/18570505855#step:5:1

It's probably a change introduced in the latest rubocop version (given that the edge Rubocop job is failing). I'll go ahead and make the change 👍.

Fixed in ad51687.

@pirj
Copy link
Member

pirj commented Nov 13, 2023

@ydah please merge at will

@ydah ydah merged commit 3ed6552 into rubocop:master Nov 13, 2023
21 checks passed
@ydah
Copy link
Member

ydah commented Nov 13, 2023

@ddieulivol Thank you for your great work!

@ddieulivol ddieulivol deleted the ddieulivol-add_excessive_create_list_cop branch November 13, 2023 16:03
@ddieulivol
Copy link
Contributor Author

Quick question: What's the release cadence for this gem? Is there a number of new features to be reached before we release a new version?

@ydah
Copy link
Member

ydah commented Nov 16, 2023

The following PRs will be merged:

And, we would like to proceed to release once the following issues are resolved:

@ydah
Copy link
Member

ydah commented Jan 4, 2024

@ddieulivol A version containing this cop has been released. Thank you for your contribution to this project!
https://github.com/rubocop/rubocop-factory_bot/releases/tag/v2.25.0

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