Skip to content

Suggestion: validate boolean field conditions style #28

@hwo411

Description

@hwo411

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions