Skip to content

Commit

Permalink
Merge pull request #326 from rodjek/issue-305
Browse files Browse the repository at this point in the history
Extend the rake task to support setting configuration options in the block
  • Loading branch information
timtim123456 committed Sep 22, 2014
2 parents 3aa4d6d + c7c36bb commit c08bf75
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 7 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ If you want to test your entire Puppet manifest directory, you can add

rake lint

If you want to modify the default behaviour of the rake task, you can modify
the PuppetLint configuration by defining the task yourself.

PuppetLint::RakeTask.new :lint do |config|
# Pattern of files to check, defaults to `**/*.pp`
config.pattern = 'modules'

# Pattern of files to ignore
config.ignore_paths = ['modules/apt', 'modules/stdlib']

# List of checks to disable
config.disable_checks = ['documentation', '80chars']

# Should puppet-lint prefix it's output with the file being checked,
# defaults to true
config.with_filename = false

# Should the task fail if there were any warnings, defaults to false
config.fail_on_warnings = true

# Format string for puppet-lint's output (see the puppet-lint help output
# for details
config.log_format = '%{filename} - %{message}'

# Print out the context for the problem, defaults to false
config.with_context = true

# Enable automatic fixing of problems, defaults to false
config.fix = true

# Show ignored problems in the output, defaults to false
config.show_ignored = true
end

## Implemented tests

At the moment, the following tests have been implemented:
Expand Down
49 changes: 42 additions & 7 deletions lib/puppet-lint/tasks/puppet-lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,62 @@ class PuppetLint
# require 'puppet-lint'
# PuppetLint::RakeTask.new
class RakeTask < ::Rake::TaskLib
include ::Rake::DSL if defined?(::Rake::DSL)

DEFAULT_PATTERN = '**/*.pp'

attr_accessor :name
attr_accessor :pattern
attr_accessor :ignore_paths
attr_accessor :with_filename
attr_accessor :disable_checks
attr_accessor :fail_on_warnings
attr_accessor :error_level
attr_accessor :log_format
attr_accessor :with_context
attr_accessor :fix
attr_accessor :show_ignored

# Public: Initialise a new PuppetLint::RakeTask.
#
# args - Not used.
#
# Example
#
# PuppetLint::RakeTask.new
def initialize(*args)
def initialize(*args, &task_block)
@name = args.shift || :lint
@pattern = DEFAULT_PATTERN
@with_filename = true
@disable_checks = []
@ignore_paths = []

define(args, &task_block)
end

def define(args, &task_block)
desc 'Run puppet-lint'

task :lint do
PuppetLint.configuration.with_filename = true
task_block.call(*[self, args].slice(0, task_block.arity)) if task_block

task @name do
PuppetLint::OptParser.build

Array(@disable_checks).each do |check|
PuppetLint.configuration.send("disable_#{check}")
end

%w{with_filename fail_on_warnings error_level log_format with_context fix show_ignored}.each do |config|
unless instance_variable_get("@#{config}").nil?
PuppetLint.configuration.send(config.to_sym, instance_variable_get("@#{config}"))
end
end

RakeFileUtils.send(:verbose, true) do
linter = PuppetLint.new
matched_files = FileList['**/*.pp']
matched_files = FileList[@pattern]

if ignore_paths = PuppetLint.configuration.ignore_paths
matched_files = matched_files.exclude(*ignore_paths)
end
matched_files = matched_files.exclude(*@ignore_paths)

matched_files.to_a.each do |puppet_file|
linter.file = puppet_file
Expand Down

0 comments on commit c08bf75

Please sign in to comment.