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

new() click to toggle source

Internal: Initialise a new PuppetLint::CheckPlugin.

# File lib/puppet-lint/checkplugin.rb, line 12
def initialize
  @problems = []
end

Public Instance Methods

fix_problems() click to toggle source

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.reject { |problem| problem[:kind] == :ignored || problem[:check] == :syntax }.each do |problem|
    next unless respond_to?(:fix)

    begin
      fix(problem)
      problem[:kind] = :fixed
    rescue PuppetLint::NoFix
      # noop
    end
  end

  @problems
end
run() click to toggle source

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|
    next if problem[:check] == :syntax
    next unless PuppetLint::Data.ignore_overrides[problem[:check]].key?(problem[:line])

    problem[:kind] = :ignored
    problem[:reason] = PuppetLint::Data.ignore_overrides[problem[:check]][problem[:line]]
  end

  @problems
end

Private Instance Methods

add_token(index, token) click to toggle source
# File lib/puppet-lint/checkplugin.rb, line 61
def add_token(index, token)
  PuppetLint::Data.insert(index, token)
end
array_indexes() click to toggle source

Public: Provides positional information for any array 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 112
def array_indexes
  PuppetLint::Data.array_indexes
end
class_indexes() click to toggle source

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 88
def class_indexes
  PuppetLint::Data.class_indexes
end
default_info() click to toggle source

Internal: Prepare default problem report information.

Returns a Hash of default problem information.

# File lib/puppet-lint/checkplugin.rb, line 180
def default_info
  @default_info ||= {
    check: self.class.const_get(:NAME),
    fullpath: fullpath,
    path: path,
    filename: filename
  }
end
defaults_indexes() click to toggle source

Public: Provides positional information for any default 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 128
def defaults_indexes
  PuppetLint::Data.defaults_indexes
end
defined_type_indexes() click to toggle source

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 96
def defined_type_indexes
  PuppetLint::Data.defined_type_indexes
end
filename() click to toggle source

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 159
def filename
  PuppetLint::Data.filename
end
formatting_tokens() click to toggle source

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 166
def formatting_tokens
  PuppetLint::Data.formatting_tokens
end
fullpath() click to toggle source

Public: Provides the expanded path of the file being analysed to check plugins.

Returns the String path.

# File lib/puppet-lint/checkplugin.rb, line 144
def fullpath
  PuppetLint::Data.fullpath
end
function_indexes() click to toggle source

Public: Provides positional information for any function definition in the tokens array to the check plugins.

Returns an Array of Hashes containing the position information.

# File lib/puppet-lint/checkplugin.rb, line 136
def function_indexes
  PuppetLint::Data.function_indexes
end
hash_indexes() click to toggle source

Public: Provides positional information for any hash 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 120
def hash_indexes
  PuppetLint::Data.hash_indexes
end
manifest_lines() click to toggle source

Public: Provides a list of manifest lines to the check plugins.

Returns an Array of manifest lines.

# File lib/puppet-lint/checkplugin.rb, line 173
def manifest_lines
  PuppetLint::Data.manifest_lines
end
node_indexes() click to toggle source

Public: Provides positional information for any node 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 104
def node_indexes
  PuppetLint::Data.node_indexes
end
notify(kind, problem) click to toggle source

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.
:description  - The description of the check that detected the problem.
:help_uri     - The help web page of the check that detected the problem.

Returns nothing.

# File lib/puppet-lint/checkplugin.rb, line 201
def notify(kind, problem)
  problem[:kind] = kind
  problem.merge!(default_info) { |_key, v1, _v2| v1 }

  raise ArgumentError, 'unknown value passed for kind' unless [:warning, :error, :fixed].include?(kind)

  [:message, :line, :column, :check].each do |attr|
    raise ArgumentError, "problem hash must contain #{attr.inspect}" unless problem.key?(attr)
  end

  @problems << problem
end
path() click to toggle source

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 152
def path
  PuppetLint::Data.path
end
remove_token(token) click to toggle source
# File lib/puppet-lint/checkplugin.rb, line 65
def remove_token(token)
  PuppetLint::Data.delete(token)
end
resource_indexes() click to toggle source

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 80
def resource_indexes
  PuppetLint::Data.resource_indexes
end
title_tokens() click to toggle source

Public: Provides the resource titles to the check plugins.

Returns an Array of PuppetLint::Lexer::Token objects.

# File lib/puppet-lint/checkplugin.rb, line 72
def title_tokens
  PuppetLint::Data.title_tokens
end
tokens() click to toggle source

Public: Provides the tokenised manifest to the check plugins.

Returns an Array of PuppetLint::Lexer::Token objects.

# File lib/puppet-lint/checkplugin.rb, line 57
def tokens
  PuppetLint::Data.tokens
end