diff --git a/README.md b/README.md index 59df6f10..9e1c35d8 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/puppet-lint/tasks/puppet-lint.rb b/lib/puppet-lint/tasks/puppet-lint.rb index 3b230698..4957a606 100644 --- a/lib/puppet-lint/tasks/puppet-lint.rb +++ b/lib/puppet-lint/tasks/puppet-lint.rb @@ -11,6 +11,22 @@ 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. @@ -18,20 +34,39 @@ class RakeTask < ::Rake::TaskLib # 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