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

Fix Rails/UniquenessValidationWithoutIndex false positive on explicit disable #1008

Conversation

samrjenkins
Copy link
Contributor

@samrjenkins samrjenkins commented May 18, 2023

Fixes: Rails/UniqueValidationWithoutIndex

Currently validates :column_name, uniqueness: false will report an offence if the schema does not specify a unique index for the corresponding database column. The cop is currently insensitive to the value of the :uniqueness option. Any value (including falsy false and nil) will cause this cop to expect a unique index in the schema.

This pull request fixes this behaviour such that we will now only report offences when the value of the :uniqueness option is truthy.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@samrjenkins samrjenkins changed the title Fix uniqueness validation without index explicit disable Fix UniquenessValidationWithoutIndex false positive on explicit disable May 18, 2023
@samrjenkins samrjenkins changed the title Fix UniquenessValidationWithoutIndex false positive on explicit disable Fix Rails/UniquenessValidationWithoutIndex false positive on explicit disable May 18, 2023
@samrjenkins samrjenkins force-pushed the fix-uniqueness-validation-without-index-explicit-disable branch from 4d90e2b to 2c22cc6 Compare May 18, 2023 18:09
@koic
Copy link
Member

koic commented May 30, 2023

This looks good to me. Can you squash your commits into one?

@samrjenkins samrjenkins force-pushed the fix-uniqueness-validation-without-index-explicit-disable branch from ccaff47 to 497369a Compare May 30, 2023 13:41
@samrjenkins samrjenkins force-pushed the fix-uniqueness-validation-without-index-explicit-disable branch from 497369a to bafe572 Compare May 30, 2023 13:43
@koic koic merged commit 0be0e41 into rubocop:master Jun 1, 2023
10 checks passed
@koic
Copy link
Member

koic commented Jun 1, 2023

Thanks!

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.

None yet

2 participants