Sha256: 1a2644a984598d7ca57daf175ba60ab4b53636e55aff2ecd99b3dbe064f1f88c

Contents?: true

Size: 792 Bytes

Versions: 28

Compression:

Stored size: 792 Bytes

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.".freeze

        def_node_matcher :output?, <<-PATTERN
          (send nil? {:ap :p :pp :pretty_print :print :puts} ...)
        PATTERN

        def on_send(node)
          return unless output?(node) && node.arguments?

          add_offense(node, location: :selector)
        end
      end
    end
  end
end

Version data entries

28 entries across 26 versions & 3 rubygems

Version Path
rubocop-0.65.0 lib/rubocop/cop/rails/output.rb
rubocop-0.64.0 lib/rubocop/cop/rails/output.rb
rubocop-0.63.1 lib/rubocop/cop/rails/output.rb
rubocop-0.63.0 lib/rubocop/cop/rails/output.rb
rubocop-0.62.0 lib/rubocop/cop/rails/output.rb
rubocop-0.61.1 lib/rubocop/cop/rails/output.rb
rubocop-0.61.0 lib/rubocop/cop/rails/output.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/rails/output.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/rails/output.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/rails/output.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/rails/output.rb
rubocop-0.60.0 lib/rubocop/cop/rails/output.rb
rubocop-0.59.2 lib/rubocop/cop/rails/output.rb
rubocop-0.59.1 lib/rubocop/cop/rails/output.rb
rubocop-0.59.0 lib/rubocop/cop/rails/output.rb
rubocop-0.58.2 lib/rubocop/cop/rails/output.rb
rubocop-0.58.1 lib/rubocop/cop/rails/output.rb
rubocop-0.58.0 lib/rubocop/cop/rails/output.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/rails/output.rb
rubocop-0.57.2 lib/rubocop/cop/rails/output.rb