Sha256: 9d769bd1f4b5c7900b5e9062e2f2985ec5ca59dfa70b8e08c0fb20157d08633d

Contents?: true

Size: 1.08 KB

Versions: 14

Compression:

Stored size: 1.08 KB

Contents

require 'knife-spork/plugins/plugin'

module KnifeSpork
  module Plugins
    class Foodcritic < Plugin
      name :foodcritic
      hooks :after_check, :before_upload

      def perform
        safe_require 'foodcritic'

        tags = config.tags || []
        fail_tags = config.fail_tags || ['any']
        include_rules = config.include_rules || []

        cookbooks.each do |cookbook|
          ui.info "Running foodcritic against #{cookbook.name}@#{cookbook.version}..."

          cookbook_path = cookbook.root_dir

          ui.info cookbook_path
          
          options = {:tags => tags, :fail_tags => fail_tags, :include_rules => include_rules}
          review = ::FoodCritic::Linter.new.check([cookbook_path], options)

          if review.failed?
            ui.error "Foodcritic failed!"
            review.to_s.split("\n").each{ |r| ui.error r.to_s }
            exit(1) if config.epic_fail
          else
            ui.info "Passed!"
          end
        end
      end

      def epic_fail?
        config.epic_fail.nil? ? 'true' : config.epic_fail
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
knife-spork-1.0.14 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.13 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.12 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.10 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.9 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.8 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.7 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.6 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.5 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.4 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.3 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.2 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.1 lib/knife-spork/plugins/foodcritic.rb
knife-spork-1.0.0 lib/knife-spork/plugins/foodcritic.rb