class Danger::DangerPuppetLint

Shows linter errors and warnings from puppet_lint You'll need [puppet-lint](http://puppet-lint.com/) installed and generating a report file to use this plugin

@example Showing summary

puppet-lint ./ > puppet-lint.report
danger-puppet_lint.report 'puppet-lint.report'

@see IntrepidPursuits/danger-puppet_lint @tags puppet, lint, configuration

Attributes

project_root[RW]

The project root, which will be used to make the paths relative. Defaults to `pwd`. @return [String] project_root value

sticky_summary[RW]

Defines if the test summary will be sticky or not. Defaults to `false`. @return [Boolean] sticky

Public Instance Methods

report(file_path) click to toggle source

Reads a puppet-lint summary file and reports it.

@param [String] file_path Path for puppet-lint report. @return [void]

# File lib/puppet_lint/plugin.rb, line 40
def report(file_path)
  raise 'Summary file not found' unless File.file?(file_path)
  run_summary(file_path)
end

Private Instance Methods

format_violation(violation) click to toggle source

A method that returns a formatted string for a violation @return String

# File lib/puppet_lint/plugin.rb, line 75
def format_violation(violation)
  violation.to_s
end
run_summary(report_file) click to toggle source
# File lib/puppet_lint/plugin.rb, line 47
def run_summary(report_file)
  warning_count = 0
  error_count = 0

  # Read line-by-line to determine violations
  File.readlines(report_file).each do |line|
    if line.index('WARNING:').nil? == false
      warning_count += 1
      warn(format_violation(line), sticky: false)
    elsif line.index('ERROR:').nil? == false
      error_count += 1
      fail(format_violation(line), sticky: false)
    end
  end

  # Record the summary
  message(summary_message(warning_count, error_count), sticky: sticky_summary)
end
summary_message(warning_count, error_count) click to toggle source
# File lib/puppet_lint/plugin.rb, line 66
def summary_message(warning_count, error_count)
  violations = warning_count + error_count

  "Puppet-Lint Summary: Found #{violations} violations. #{warning_count} Warnings and #{error_count} Errors."
end