Class: Simplabs::Excellent::Checks::Rails::ValidationsCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/rails/validations_check.rb

Overview

This check reports ActiveRecord models that do not validate anything. Not validating anything in the model is usually not intended and has most likely just been forgotten. For more information on validations and why to use them, see guides.rubyonrails.org/activerecord_validations_callbacks.html#why-use-validations.

Applies to

  • ActiveRecord models

Instance Attribute Summary

Attributes inherited from Base

#interesting_files, #interesting_nodes, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_node, #warnings_for

Constructor Details

#initializeValidationsCheck

:nodoc:



19
20
21
22
# File 'lib/simplabs/excellent/checks/rails/validations_check.rb', line 19

def initialize #:nodoc:
  super
  @interesting_nodes = [:class]
end

Instance Method Details

#evaluate(context) ⇒ Object

:nodoc:



24
25
26
# File 'lib/simplabs/excellent/checks/rails/validations_check.rb', line 24

def evaluate(context) #:nodoc:
  add_warning(context, '{{class}} does not validate any attributes.', { :class => context.full_name }) if context.active_record_model? && !context.validating?
end