Class: RuboCop::Cop::Rails::I18nLazyLookup
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::I18nLazyLookup
- Extended by:
- AutoCorrector
- Includes:
- VisibilityHelp
- Defined in:
- lib/rubocop/cop/rails/i18n_lazy_lookup.rb
Overview
Checks for places where I18n “lazy” lookup can be used.
Constant Summary collapse
- MSG =
'Use "lazy" lookup for the text used in controllers.'- RESTRICT_ON_SEND =
%i[translate t].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubocop/cop/rails/i18n_lazy_lookup.rb', line 43 def on_send(node) translate_call?(node) do |key_node| key = key_node.value return if key.to_s.start_with?('.') controller, action = controller_and_action(node) return unless controller && action scoped_key = get_scoped_key(key_node, controller, action) return unless key == scoped_key add_offense(key_node) do |corrector| unscoped_key = key_node.value.to_s.split('.').last corrector.replace(key_node, "'.#{unscoped_key}'") end end end |