Class: RuboCop::Cop::Lint::UsePositiveInt32Validator

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/lint/use_positive_int32_validator.rb

Overview

Examples:

# bad
params do
  requires :id, type: Integer
end

# good
params do
  requires :id, type: Integer, positive_int32: true
end

Constant Summary collapse

MSG =
"If this Integer maps to a postgres Integer column, validate with `positive_int32: true`"

Instance Method Summary collapse

Instance Method Details

#on_block(node) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/rubocop/cop/lint/use_positive_int32_validator.rb', line 30

def on_block(node)
  return unless (hash = find_params_hashes(node))

  hash.each do |param|
    add_offense(param) if is_type_integer?(param) && !validates_integer?(param)
  end
end