Class: RuboCop::Cop::Vicenzo::Rails::EnumInclusionOfValidation
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Vicenzo::Rails::EnumInclusionOfValidation
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/vicenzo/rails/enum_inclusion_of_validation.rb
Overview
Ensures that enums using the new syntax include the
validate: { allow_nil: true } option.
Old-style enums (keyword argument syntax) are ignored.
Constant Summary collapse
- MSG_MISSING_VALIDATE =
'Add `validate: { allow_nil: true }` to the enum.'- MSG_INVALID_VALIDATE =
'The `validate` option for the enum must be `validate: { allow_nil: true }`.'- RESTRICT_ON_SEND =
[:enum].freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rubocop/cop/vicenzo/rails/enum_inclusion_of_validation.rb', line 32 def on_send(node) return unless node.command?(:enum) # Ignore old-style enums first_argument = node.first_argument return if first_argument&.hash_type? validate_kwarg = find_validate_option(node) register_offence_for(node, validate_kwarg) end |