Sha256: b5ced14ecc1778186be5a517cb34c078e8509372f3ee7e6da3653585b80a1941
Contents?: true
Size: 1.18 KB
Versions: 12
Compression:
Stored size: 1.18 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Rails # This cop checks for the use of output calls like puts and print # # @example # # bad # puts 'A debug message' # pp 'A debug message' # print 'A debug message' # # # good # Rails.logger.debug 'A debug message' class Output < Cop MSG = 'Do not write to stdout. ' \ "Use Rails's logger if you want to log." def_node_matcher :output?, <<-PATTERN (send nil? {:ap :p :pp :pretty_print :print :puts} ...) PATTERN def_node_matcher :io_output?, <<-PATTERN (send { (gvar #match_gvar?) {(const nil? :STDOUT) (const nil? :STDERR)} } {:binwrite :syswrite :write :write_nonblock} ...) PATTERN def on_send(node) return unless (output?(node) || io_output?(node)) && node.arguments? add_offense(node, location: :selector) end private def match_gvar?(sym) %i[$stdout $stderr].include?(sym) end end end end end
Version data entries
12 entries across 12 versions & 2 rubygems