Class: RuboCop::Cop::Isucon::Sinatra::DisableLogging

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

Overview

Disable sinatra logging

Examples:

# bad
class App < Sinatra::Base
  enable :logging
end

# bad
class App < Sinatra::Base
end

# good
class App < Sinatra::Base
  disable :logging
end

Constant Summary collapse

MSG =
"Disable sinatra logging."

Instance Method Summary collapse

Methods included from Mixin::SinatraMethods

#parent_is_sinatra_app?, #subclass_of_sinatra_base?, #subclass_of_sinatra_base_contains_logging?

Instance Method Details

#logging_enabled?(node) ⇒ Boolean

Parameters:

  • node (RuboCop::AST::Node)

Returns:

  • (Boolean)


34
35
36
# File 'lib/rubocop/cop/isucon/sinatra/disable_logging.rb', line 34

def_node_matcher :logging_enabled?, <<~PATTERN
  (send nil? :enable (sym :logging))
PATTERN

#on_class(node) ⇒ Object

Parameters:

  • node (RuboCop::AST::Node)


49
50
51
52
53
54
55
56
# File 'lib/rubocop/cop/isucon/sinatra/disable_logging.rb', line 49

def on_class(node)
  return unless subclass_of_sinatra_base?(node)
  return if subclass_of_sinatra_base_contains_logging?(node)

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

#on_send(node) ⇒ Object

Parameters:

  • node (RuboCop::AST::Node)


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

def on_send(node)
  return unless parent_is_sinatra_app?(node)
  return unless logging_enabled?(node)

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