class RuboCop::Cop::Style::StderrPuts
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
- RESTRICT_ON_SEND
Public Instance Methods
Source
# File lib/rubocop/cop/style/stderr_puts.rb, line 32 def on_send(node) return unless stderr_puts?(node) message = message(node) add_offense(stderr_puts_range(node), message: message) do |corrector| corrector.replace(stderr_puts_range(node), 'warn') end end
Private Instance Methods
Source
# File lib/rubocop/cop/style/stderr_puts.rb, line 43 def message(node) format(MSG, bad: "#{node.receiver.source}.#{node.method_name}") end
Source
# File lib/rubocop/cop/style/stderr_puts.rb, line 47 def stderr_gvar?(sym) sym == :$stderr end
Source
# File lib/rubocop/cop/style/stderr_puts.rb, line 51 def stderr_puts_range(send) range_between(send.source_range.begin_pos, send.loc.selector.end_pos) end