rubocop-rails
rubocop-rails copied to clipboard
Add new `Rails/ValidationsGrouping` cop
Closes #555.
Autocorrection is more involved, so I suggest to leave it as a future improvement.
Tested on gitlab's codebase: a bunch of offenses, no errors.
@fatkodima
A suggestion, to simplify the autocorrection, maybe the config SingleAttributeValidations
could be instead an other cop that can be disable if not wanted.
A cop with check and autocorrect
# bad
validates :email, format: { with: /@/ }
validates :email, presence: true
# good
validates :email, presence: true, format: { with: /@/ }
and the other
# bad
validates :name, :bio, presence: true
# good
validates :name, presence: true
validates :bio, presence: true
The combination of both cops will help to follow the style guide.
What do you think?