Class: RuboCop::Cop::Isucon::Sinatra::RackLogger

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/isucon/sinatra/rack_logger.rb

Overview

Disable request.env['rack.logger'] logging

Examples:

# bad
request.env['rack.logger'].warn 'drop post isu condition request'

# good
# no logging

Constant Summary collapse

MSG =
"Don't use `request.env['rack.logger']`"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object

Parameters:

  • node (RuboCop::AST::Node)


39
40
41
42
43
44
45
# File 'lib/rubocop/cop/isucon/sinatra/rack_logger.rb', line 39

def on_send(node)
  return unless rack_logger?(node)

  add_offense(node) do |corrector|
    perform_autocorrect(corrector: corrector, node: node)
  end
end

#rack_logger?(node) ⇒ Boolean

Parameters:

  • node (RuboCop::AST::Node)

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubocop/cop/isucon/sinatra/rack_logger.rb', line 23

def_node_matcher :rack_logger?, <<~PATTERN
  (send
    (send
      (send
        (send nil? :request)
        :env
      )
      :[]
      (str "rack.logger")
    )
    {:debug | :error | :fatal | :info | :warn}
    ...
  )
PATTERN