class Pfm::Command::ValidatorCommands::ServerBuild

def lint_chef

def lint_chef
  base_path = 'chef'
  cookbooks_dir = 'cookbooks'
  # Loop through the base directory looking through all of the cookbooks
  # for unit tests
  Dir.entries(base_path).each do |dir|
    next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}"
    next if dir.to_s == 'vendor'
    Dir.entries("#{base_path}/#{dir}/#{cookbooks_dir}").each do |cookbook|
      next unless File.directory? "#{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}"
      # skip directories eg. '.' and '..'
      next if cookbook.to_s == '.' || cookbook.to_s == '..'
      # Run the syntax and semantics checkers
      msg("\nRunning Rubocop on #{cookbook} cookbook")
      # Copy in global .foodcritic file if set
      debug("copying #{SETTINGS['RUBOCOP_RULES_FILE']} to #{Dir.pwd}")
      system("cp #{SETTINGS['RUBOCOP_RULES_FILE']} #{Dir.pwd}") if File.exist? SETTINGS['RUBOCOP_RULES_FILE']
      gem_path = `bundle show rubocop-junit-formatter`.strip!
      system("rubocop \\
        --format html -o #{@artifacts_dir}/rubocop/#{cookbook}_rubocop_output.html \\
        -r #{gem_path}/lib/rubocop/formatter/junit_formatter.rb \\
        --format RuboCop::Formatter::JUnitFormatter -o #{@reports_dir}/rubocop/#{cookbook}_junit.xml \\
        #{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}") || @failure = true
      msg("Running Foodcritic on #{cookbook} cookbook")
      ENV['FOODCRITIC_JUNIT_OUTPUT_DIR'] = "#{@reports_dir}/foodcritic"
      ENV['FOODCRITIC_JUNIT_OUTPUT_FILE'] = "#{cookbook}_foodcritic_junit.xml"
      # Copy in global .foodcritic file if set
      debug("copying #{SETTINGS['FOODCRITIC_RULES_FILE']} to #{Dir.pwd}")
      system("cp #{SETTINGS['FOODCRITIC_RULES_FILE']} #{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook}") if File.exist? SETTINGS['FOODCRITIC_RULES_FILE']
      # Capure output but also fail if applicable
      system("foodcritic #{base_path}/#{dir}/#{cookbooks_dir}/#{cookbook} -C > #{cookbook}_foodcritic.out") || @failure = true
      system("foodcritic-junit < #{cookbook}_foodcritic.out")
    end
  end
end