class RuboCop::Cop::Style::StderrPuts
This cop identifies places where `$stderr.puts` can be replaced by `warn`. The latter has the advantage of easily being disabled by, the `-W0` interpreter flag or setting `$VERBOSE` to `nil`.
@example
# bad $stderr.puts('hello') # good warn('hello')
Constants
- MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/rubocop/cop/style/stderr_puts.rb, line 36 def autocorrect(node) lambda do |corrector| corrector.replace(stderr_puts_range(node), 'warn') end end
on_send(node)
click to toggle source
# File lib/rubocop/cop/style/stderr_puts.rb, line 30 def on_send(node) return unless stderr_puts?(node) add_offense(node, location: stderr_puts_range(node)) end
Private Instance Methods
message(node)
click to toggle source
# File lib/rubocop/cop/style/stderr_puts.rb, line 44 def message(node) format(MSG, bad: "#{node.receiver.source}.#{node.method_name}") end
stderr_gvar?(sym)
click to toggle source
# File lib/rubocop/cop/style/stderr_puts.rb, line 48 def stderr_gvar?(sym) sym == :$stderr end
stderr_puts_range(send)
click to toggle source
# File lib/rubocop/cop/style/stderr_puts.rb, line 52 def stderr_puts_range(send) range_between( send.loc.expression.begin_pos, send.loc.selector.end_pos ) end