<commit_before>require 'rake'
require 'rake/tasklib'

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

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


      def define
        desc 'Lint Chef cookbooks' unless ::Rake.application.last_comment
        task(name) do
          result = FoodCritic::Linter.new.check(options.merge(default_options))
          printer = options[:context] ? ContextOutput.new : SummaryOutput.new
          printer.output(result) if result.warnings.any?
          abort if result.failed?
        end
      end

      private
      def default_options
        {
          fail_tags: ['correctness'], # differs to default cmd-line behaviour
          cookbook_paths: files,
          exclude_paths: ['test/**/*', 'spec/**/*', 'features/**/*'],
          context: false,
          chef_version: FoodCritic::Linter::DEFAULT_CHEF_VERSION
        }
      end
    end
  end
end
<commit_msg>Added output for built-in rake tasks.<commit_after>require 'rake'
require 'rake/tasklib'

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

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


      def define
        desc 'Lint Chef cookbooks' unless ::Rake.application.last_comment
        task(name) do
          puts "Starting Foodcritic linting..."
          result = FoodCritic::Linter.new.check(options.merge(default_options))
          printer = options[:context] ? ContextOutput.new : SummaryOutput.new
          printer.output(result) if result.warnings.any?
          abort if result.failed?
          puts "Completed!"
        end
      end

      private
      def default_options
        {
          fail_tags: ['correctness'], # differs to default cmd-line behaviour
          cookbook_paths: files,
          exclude_paths: ['test/**/*', 'spec/**/*', 'features/**/*'],
          context: false,
          chef_version: FoodCritic::Linter::DEFAULT_CHEF_VERSION
        }
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.10365853658536585, 'fraction_numerical': 0.0, 'mean_word_length': 2.159559834938102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4483015', 'n_tokens_mistral': 670, 'n_tokens_neox': 656, 'n_words': 165}