-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrails_logger.rb
More file actions
31 lines (27 loc) · 899 Bytes
/
rails_logger.rb
File metadata and controls
31 lines (27 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true
module RuboCop
module Cop
module Code0
module ZeroTrack
module Logs
# Cop that checks if 'timestamps' method is called with timezone information.
class RailsLogger < RuboCop::Cop::Base
MSG = 'Do not use `Rails.logger` directly, include `Code0::ZeroTrack::Loggable` instead'
LOG_METHODS = %i[debug error fatal info warn].freeze
LOG_METHODS_PATTERN = LOG_METHODS.map(&:inspect).join(' ').freeze
def_node_matcher :rails_logger_log?, <<~PATTERN
(send
(send (const nil? :Rails) :logger)
{#{LOG_METHODS_PATTERN}} ...
)
PATTERN
def on_send(node)
return unless rails_logger_log?(node)
add_offense(node)
end
end
end
end
end
end
end