Class: Rubocop::Cop::NxtCop::UseOfRailsLogger

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Defined in:
lib/rubocop/cop/nxt_cop/use_of_rails_logger.rb

Overview

Ensures that the NxtCore logger is used instead of ‘Rails.logger`.

Constant Summary collapse

RESTRICT_ON_SEND =
[:logger].freeze
MSG =
'Use of Rails.logger is not allowed. Use `logger` and include `Nxt::Loggable`'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/rubocop/cop/nxt_cop/use_of_rails_logger.rb', line 14

def on_send(node)
  return unless node.receiver&.const_type? && node.receiver.short_name == :Rails

  add_offense(node, message: MSG) do |corrector|
    corrected = node.source.gsub('Rails.logger', 'logger')
    corrector.replace(node, corrected)
  end
end