Class: RuboCop::Rails::ErrorsAddWithSymbol
- Inherits:
-
Cop::Cop
- Object
- Cop::Cop
- RuboCop::Rails::ErrorsAddWithSymbol
- Defined in:
- lib/rubocop/rails/errors_add_with_symbol.rb
Overview
This cop enforces usage of ActiveModel::Errors#add with symbols
When a symbol is passed to this method, then the I18n lookup happens within the method, allowing to generate error messages in different languages. That’s not possible when already translated strings are passed to this method.
Constant Summary collapse
- MSG =
'Only pass symbols to `errors.add`'.freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rubocop/rails/errors_add_with_symbol.rb', line 23 def on_send(node) captures = errors_add?(node) return unless captures = captures[1] return if .nil? || .sym_type? || symbolizes?() generate_offense(node) end |