class PuppetLint::CheckPlugin
Public: A class that contains and provides information for the puppet-lint checks.
This class should not be used directly, but instead should be inherited.
Examples
class PuppetLint::Plugin::CheckFoo < PuppetLint::CheckPlugin end
Public Class Methods
Internal: Initialise a new PuppetLint::CheckPlugin.
# File lib/puppet-lint/checkplugin.rb, line 12 def initialize @problems = [] end
Public Instance Methods
Internal: Fix any problems the check plugin has detected.
Returns an Array of problem Hashes.
# File lib/puppet-lint/checkplugin.rb, line 37 def fix_problems @problems.each do |problem| if self.respond_to?(:fix) begin fix(problem) rescue PuppetLint::NoFix # noop else problem[:kind] = :fixed end end end @problems end
Internal: Check the manifest for problems and filter out any problems that should be ignored.
Returns an Array of problem Hashes.
# File lib/puppet-lint/checkplugin.rb, line 20 def run check @problems.each do |problem| if PuppetLint::Data.ignore_overrides[problem[:check]].has_key?(problem[:line]) problem[:kind] = :ignored problem[:reason] = PuppetLint::Data.ignore_overrides[problem[:check]][problem[:line]] next end end @problems end
Private Instance Methods
Public: Provides positional information for any class definitions in the tokens array to the check plugins.
Returns an Array of Hashes containing the position information.
# File lib/puppet-lint/checkplugin.rb, line 81 def class_indexes PuppetLint::Data.class_indexes end
Internal: Prepare default problem report information.
Returns a Hash of default problem information.
# File lib/puppet-lint/checkplugin.rb, line 133 def default_info @default_info ||= { :check => self.class.const_get('NAME'), :fullpath => fullpath, :path => path, :filename => filename, } end
Public: Provides positional information for any defined type definitions in the tokens array to the check plugins.
Returns an Array of Hashes containing the position information.
# File lib/puppet-lint/checkplugin.rb, line 89 def defined_type_indexes PuppetLint::Data.defined_type_indexes end
Public: Provides the name of the file being analysed to the check plugins.
Returns the String file name.
# File lib/puppet-lint/checkplugin.rb, line 112 def filename PuppetLint::Data.filename end
Public: Provides a list of formatting tokens to the check plugins.
Returns an Array of Symbol token types.
# File lib/puppet-lint/checkplugin.rb, line 119 def formatting_tokens PuppetLint::Data.formatting_tokens end
Public: Provides the expanded path of the file being analysed to check plugins.
Returns the String path.
# File lib/puppet-lint/checkplugin.rb, line 97 def fullpath PuppetLint::Data.fullpath end
Public: Provides a list of manifest lines to the check plugins.
Returns an Array of manifest lines.
# File lib/puppet-lint/checkplugin.rb, line 126 def manifest_lines PuppetLint::Data.manifest_lines end
Public: Report a problem with the manifest being checked.
kind - The Symbol problem type (:warning or :error). problem - A Hash containing the attributes of the problem
:message - The String message describing the problem. :line - The Integer line number of the location of the problem. :column - The Integer column number of the location of the problem. :check - The Symbol name of the check that detected the problem.
Returns nothing.
# File lib/puppet-lint/checkplugin.rb, line 152 def notify(kind, problem) problem[:kind] = kind problem.merge!(default_info) { |key, v1, v2| v1 } unless [:warning, :error, :fixed].include? kind raise ArgumentError, "unknown value passed for kind" end [:message, :line, :column, :check].each do |attr| unless problem.has_key? attr raise ArgumentError, "problem hash must contain #{attr.inspect}" end end @problems << problem end
Public: Provides the path of the file being analysed as it was provided to puppet-lint to the check plugins.
Returns the String path.
# File lib/puppet-lint/checkplugin.rb, line 105 def path PuppetLint::Data.path end
Public: Provides positional information for any resource declarations in the tokens array to the check plugins.
Returns an Array of Hashes containing the position information.
# File lib/puppet-lint/checkplugin.rb, line 73 def resource_indexes PuppetLint::Data.resource_indexes end
Public: Provides the resource titles to the check plugins.
Returns an Array of PuppetLint::Lexer::Token objects.
# File lib/puppet-lint/checkplugin.rb, line 65 def title_tokens PuppetLint::Data.title_tokens end
Public: Provides the tokenised manifest to the check plugins.
Returns an Array of PuppetLint::Lexer::Token objects.
# File lib/puppet-lint/checkplugin.rb, line 58 def tokens PuppetLint::Data.tokens end