To define a new check, you need to create a new PuppetLint::CheckPlugin
subclass with a check method and an optional fix method. The easiest way
to do this is with the following:
PuppetLint.new_check(:check_name) do
def check
# ...
end
endIn your check class (see above), you must define a check method that uses the
notify method (see below) to report problems in the manifest. You can use
any of the methods listed in the “What you can use” section below to inspect
the manifest.
For a more complete example of writing a check method please
read the tutorial.
In your check class (see above), you can define a fix method that will be
called on every problem submitted by the notify method in your check
method. Your fix method must take one parameter and will be passed the Hash
submitted with notify in your check method.
In your fix method, you should make your changes to the manifest by modifying
the tokens Array. If you need to back out of the fix method for whatever
reason, raise a PuppetLint::NoFix exception to skip over the problem.
For a more complete example of writing a fix method please read the
tutorial.
There are a number of methods you can use to access the manifest and file
information in your check and fix methods.
Returns the tokenised manifest as an Array of
PuppetLint::Lexer::Token objects.
Returns an Array of PuppetLint::Lexer::Token objects
that represent resource titles.
Returns an Array of Hashes with the positions of all the resource declarations within the tokenised manifest. Each Hash has the following Symbol keys:
tokens Array (see above) pointing
to the first token of the resource.tokens Array (see above) pointing
to the last token of the resourcetokens Array, from the :start to :end
positions.PuppetLint::Lexer::Token object for
resource type (e.g. file, exec, etc).PuppetLint::Lexer::Token objects for the parameter
names in the resource declaration.Returns an Array of Hashes with the positions of all the class definitions within the tokenised manifest. Each Hash has the following Symbol keys:
tokens Array (see above) pointing
to the first token of the class.tokens Array (see above) pointing
to the last token of the class.tokens Array, from the :start to :end
positions.tokens Array covering the class
parameters.:CLASSPuppetLint::Lexer::Token
object for the class name.PuppetLint::Lexer::Token
object for the name of the class that has been inherited (if applicable).Returns an Array of Hashes with the positions of all the defined type definitions within the tokenised manifest. Each Hash has the following Symbol keys:
tokens Array (see above) pointing
to the first token of the defined type.tokens Array (see above) pointing
to the last token of the defined type.tokens Array, from the :start to :end
positions.tokens Array covering the defined type
parameters.:DEFINEPuppetLint::Lexer::Token
object for the defined type name.Returns the expanded path to the manifest file that is being analysed.
Returns the path to the manifest file as passed to puppet-lint.
Returns the name of the manifest file that is being analysed.
Returns the contents of the manifest file being analysed as an Array of lines.
Reports a problem in the manifest. Takes two arguments: A Symbol type of
problem (:warning or :error) and a Hash of information about the problem.
The Hash must contain the following keys, but can contain any other values
that you would like to pass to your fix method.