class RuboCop::Cop::Rails::EagerEvaluationLogMessage


Rails.logger.debug { “The time is #{Time.zone.now}.” }
# good
Rails.logger.debug “The time is #{Time.zone.now}.”
# bad
@example
when no output would be produced anyway.
‘Rails.logger.debug` prevents costly evaluation of interpolated strings
arguments passed as method arguments. Passing a block to
in log output. However, Ruby must eagerly evaluate interpolated string
At the `:info` log level, `Rails.logger.debug` statements do not result
By default, Rails production environments use the `:info` log level.
`Rails.logger.debug`.
Checks that blocks are used for interpolated strings passed to

def self.autocorrect_incompatible_with

def self.autocorrect_incompatible_with
  [Style::MethodCallWithArgsParentheses]
end

def on_send(node)

def on_send(node)
  return if node.parent&.block_type?
  interpolated_string_passed_to_debug(node) do |arguments|
    range = replacement_range(node)
    replacement = replacement_source(node, arguments)
    add_offense(range) do |corrector|
      corrector.replace(range, replacement)
    end
  end
end

def replacement_range(node)

def replacement_range(node)
  stop = node.source_range.end
  start = node.loc.selector.end
  if node.parenthesized_call?
    stop.with(begin_pos: start.begin_pos)
  else
    stop.with(begin_pos: start.begin_pos + 1)
  end
end

def replacement_source(node, arguments)

def replacement_source(node, arguments)
  if node.parenthesized_call?
    " { #{arguments.source} }"
  else
    "{ #{arguments.source} }"
  end
end