0

I'd like rubocop but have it create no output if there are no offenses. I've played with the documented command line options, and taken a quick peek a the config option and source code without seeing anything promising.

The closest I've come is rubocop -f o, but even that produces a summary line:

$ rubocop -f o

--
0  Total

Any ideas on how to suppress output on a clean, successful run?

David Hempy
  • 5,373
  • 2
  • 40
  • 68

1 Answers1

1

I believe there's no predefined option to do what you ask. The best option I think is to implement a custom formatter with the desired behaviour and use that to run RuboCop. As a super simple example consider the following, inspired by RuboCop's SimpleTextFormatter:

# my_rubocop_formatter.rb
class MyRuboCopFormatter < RuboCop::Formatter::BaseFormatter
  def started(target_files)
    @total_offenses = 0
  end
  def file_finished(file, offenses)
    unless offenses.empty?
      output.puts(offenses)
      @total_offenses += offenses.count
    end
  end
  def finished(inspected_files)
    puts @total_offenses unless @total_offenses.zero?
  end
end

You can run RuboCop using it with the following command:

rubocop -r '/path/to/my_rubocop_formatter.rb' \ 
        -f MyRuboCopFormatter file_to_check.rb
toro2k
  • 19,020
  • 7
  • 64
  • 71
  • I'm doing just that right now. I'm a bit hung up on getting the --require and --format options to actually invoke my new formatter...but I'm sure I'll get past that. Thanks for the advice, @toro2k ! – David Hempy Jan 20 '15 at 16:19