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

Suggestion: validate boolean field conditions style #28

Open
hwo411 opened this issue Jan 6, 2023 · 1 comment
Open

Suggestion: validate boolean field conditions style #28

hwo411 opened this issue Jan 6, 2023 · 1 comment

Comments

@hwo411
Copy link

hwo411 commented Jan 6, 2023

Hi rubocop & sequel users and rubocop-sequel maintainers!

We've recently faced an issue with partial indexes using boolean field.

Basically, when index has condition WHERE field and sequel generates (where(field: true) as WHERE field IS TRUE, index isn't used, by postgres regardless of the nullability of the field. The same is true vice-versa. This is the expected behavior, but we only faced it recently when we discovered that partial index can help us. Before, we didn't pay attention to which conditions we used and used them interchangeably (and it didn't create a problem because of not-nullable columns).

What I think would be great in rubocop-sequel is to enforce boolean conditions to one style:
either you use where(field: true), where { field =~ true } and where: Sequel[:field] =~ true,
or you use where(:field), where { field } and where: Sequel[:field].

The former is preferred and should be default because of null handling, but one may have a different setup, so I guess having it configurable might make sense.

I think such cop may help with different kinds of related problems.

Do you think it make sense to have such cop?

@cyberdelia
Copy link
Collaborator

Sure, want to give that change a try?

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

No branches or pull requests

2 participants