require 'rake'
require 'rake/tasklib'

module FoodCritic
  module Rake
    class LintTask < ::Rake::TaskLib
      attr_accessor :name, :files
      attr_writer :options

      def initialize(name = :foodcritic)
        @name = name
        @files = Dir.pwd
        @options = {}
        yield self if block_given?
        define
      end

      def options
        {:fail_tags => ['correctness'], # differs to default cmd-line behaviour
         :exclude_paths => ['test/**/*']}.merge(@options)
      end

      def define
        desc "Lint Chef cookbooks"
        task(name) do
          result = FoodCritic::Linter.new.check(files, options)
          puts result
          fail if result.failed?
        end
      end

    end
  end
end

require 'rake'
require 'rake/tasklib'

module FoodCritic
  module Rake
    class LintTask < ::Rake::TaskLib
      attr_accessor :name, :files
      attr_writer :options

      def initialize(name = :foodcritic)
        @name = name
        @files = Dir.pwd
        @options = {}
        yield self if block_given?
        define
      end

      def options
        {:fail_tags => ['correctness'], # differs to default cmd-line behaviour
         :exclude_paths => ['test/**/*']}.merge(@options)
      end

      def define
        desc "Lint Chef cookbooks"
        task(name) do
          result = FoodCritic::Linter.new.check(files, options)
          if result.warnings.any?
            puts result
          end

          fail result.to_s if result.failed?
        end
      end

    end
  end
end

Reduce unnecessary blank lines from console output if there's nothing to print.
Reduce unnecessary blank lines from console output if there's nothing to print.

We only print the food critic reviews if there's a warning and fail with a proper message if there's any.