Class: RuboCop::Cop::Legion::HelperMigration::DirectLogging
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Legion::HelperMigration::DirectLogging
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/legion/helper_migration/direct_logging.rb
Overview
Detects direct calls to ‘Legion::Logging.*` and suggests using the `log.*` helper instead (via `Helpers::Lex` or `Legion::Logging::Helper`).
Constant Summary collapse
- MSG =
'Use `log.%<method>s(msg)` instead of `Legion::Logging.%<method>s`. ' \ 'Include `Helpers::Lex` or `Legion::Logging::Helper`.'
- RESTRICT_ON_SEND =
%i[info warn error debug fatal].freeze
Instance Method Summary collapse
Instance Method Details
#legion_logging_call?(node) ⇒ Object
27 28 29 |
# File 'lib/rubocop/cop/legion/helper_migration/direct_logging.rb', line 27 def_node_matcher :legion_logging_call?, <<~PATTERN (send (const (const nil? :Legion) :Logging) {:info :warn :error :debug :fatal} ...) PATTERN |
#on_send(node) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rubocop/cop/legion/helper_migration/direct_logging.rb', line 31 def on_send(node) return unless legion_logging_call?(node) method_name = node.method_name = format(MSG, method: method_name) add_offense(node, message: ) do |corrector| args_source = node.arguments.map(&:source).join(', ') corrector.replace(node, "log.#{method_name}(#{args_source})") end end |