diff --git a/CHANGELOG.md b/CHANGELOG.md index fd48b276e4a..eec3ce1acc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Do not annotate message with cop name in JSON output. ([@elebow][]) * [#6914](https://github.com/rubocop-hq/rubocop/issues/6914): [Fix #6914] Fix an error for `Rails/RedundantAllowNil` when with interpolations. ([@Blue-Pix][]) +* [#6941](https://github.com/rubocop-hq/rubocop/issues/6941): Add missing absence validations to `Rails/Validation`. ([@jmanian][]) ### Changes @@ -3946,3 +3947,4 @@ [@thomthom]: https://github.com/thomthom [@Blue-Pix]: https://github.com/Blue-Pix [@Mange]: https://github.com/Mange +[@jmanian]: https://github.com/jmanian diff --git a/lib/rubocop/cop/rails/validation.rb b/lib/rubocop/cop/rails/validation.rb index 42a07532399..18db2f45a6b 100644 --- a/lib/rubocop/cop/rails/validation.rb +++ b/lib/rubocop/cop/rails/validation.rb @@ -15,6 +15,7 @@ module Rails # validates_length_of :foo # validates_numericality_of :foo # validates_presence_of :foo + # validates_absence_of :foo # validates_size_of :foo # validates_uniqueness_of :foo # @@ -27,6 +28,7 @@ module Rails # validates :foo, length: true # validates :foo, numericality: true # validates :foo, presence: true + # validates :foo, absence: true # validates :foo, size: true # validates :foo, uniqueness: true # @@ -43,6 +45,7 @@ class Validation < Cop length numericality presence + absence size uniqueness ].freeze diff --git a/manual/cops_rails.md b/manual/cops_rails.md index 2bdc961395d..ab3b8586f6f 100644 --- a/manual/cops_rails.md +++ b/manual/cops_rails.md @@ -2350,6 +2350,7 @@ validates_inclusion_of :foo validates_length_of :foo validates_numericality_of :foo validates_presence_of :foo +validates_absence_of :foo validates_size_of :foo validates_uniqueness_of :foo @@ -2362,6 +2363,7 @@ validates :foo, inclusion: true validates :foo, length: true validates :foo, numericality: true validates :foo, presence: true +validates :foo, absence: true validates :foo, size: true validates :foo, uniqueness: true ```