Class: PuppetLint::RakeTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- PuppetLint::RakeTask
- Includes:
- Rake::DSL
- Defined in:
- lib/puppet-lint/tasks/puppet-lint.rb
Overview
Public: A Rake task that can be loaded and used with everything you need.
Examples
require 'puppet-lint'
PuppetLint::RakeTask.new
Constant Summary collapse
- DEFAULT_PATTERN =
'**/*.pp'.freeze
Instance Attribute Summary collapse
-
#disable_checks ⇒ Object
Returns the value of attribute disable_checks.
-
#error_level ⇒ Object
Returns the value of attribute error_level.
-
#fail_on_warnings ⇒ Object
Returns the value of attribute fail_on_warnings.
-
#fix ⇒ Object
Returns the value of attribute fix.
-
#ignore_paths ⇒ Object
Returns the value of attribute ignore_paths.
-
#log_format ⇒ Object
Returns the value of attribute log_format.
-
#name ⇒ Object
Returns the value of attribute name.
-
#only_checks ⇒ Object
Returns the value of attribute only_checks.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#relative ⇒ Object
Returns the value of attribute relative.
-
#show_ignored ⇒ Object
Returns the value of attribute show_ignored.
-
#with_context ⇒ Object
Returns the value of attribute with_context.
-
#with_filename ⇒ Object
Returns the value of attribute with_filename.
Instance Method Summary collapse
- #define(args) {|[self, args].slice(0, task_block.arity)| ... } ⇒ Object
-
#initialize(*args, &task_block) ⇒ RakeTask
constructor
Public: Initialise a new PuppetLint::RakeTask.
Constructor Details
#initialize(*args, &task_block) ⇒ RakeTask
Public: Initialise a new PuppetLint::RakeTask.
args - Not used.
Example
PuppetLint::RakeTask.new
rubocop:disable Lint/MissingSuper
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 42 def initialize(*args, &task_block) @name = args.shift || :lint @pattern = DEFAULT_PATTERN @with_filename = true @disable_checks = [] @only_checks = [] @ignore_paths = [] define(args, &task_block) end |
Instance Attribute Details
#disable_checks ⇒ Object
Returns the value of attribute disable_checks.
24 25 26 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 24 def disable_checks @disable_checks end |
#error_level ⇒ Object
Returns the value of attribute error_level.
27 28 29 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 27 def error_level @error_level end |
#fail_on_warnings ⇒ Object
Returns the value of attribute fail_on_warnings.
26 27 28 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 26 def fail_on_warnings @fail_on_warnings end |
#fix ⇒ Object
Returns the value of attribute fix.
30 31 32 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 30 def fix @fix end |
#ignore_paths ⇒ Object
Returns the value of attribute ignore_paths.
22 23 24 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 22 def ignore_paths @ignore_paths end |
#log_format ⇒ Object
Returns the value of attribute log_format.
28 29 30 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 28 def log_format @log_format end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 20 def name @name end |
#only_checks ⇒ Object
Returns the value of attribute only_checks.
25 26 27 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 25 def only_checks @only_checks end |
#pattern ⇒ Object
Returns the value of attribute pattern.
21 22 23 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 21 def pattern @pattern end |
#relative ⇒ Object
Returns the value of attribute relative.
32 33 34 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 32 def relative @relative end |
#show_ignored ⇒ Object
Returns the value of attribute show_ignored.
31 32 33 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 31 def show_ignored @show_ignored end |
#with_context ⇒ Object
Returns the value of attribute with_context.
29 30 31 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 29 def with_context @with_context end |
#with_filename ⇒ Object
Returns the value of attribute with_filename.
23 24 25 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 23 def with_filename @with_filename end |
Instance Method Details
#define(args) {|[self, args].slice(0, task_block.arity)| ... } ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/puppet-lint/tasks/puppet-lint.rb', line 53 def define(args, &task_block) desc 'Run puppet-lint' yield(*[self, args].slice(0, task_block.arity)) if task_block # clear any (auto-)pre-existing task Rake::Task[@name].clear if Rake::Task.task_defined?(@name) task @name do PuppetLint::OptParser.build if Array(@only_checks).any? enable_checks = Array(@only_checks).map(&:to_sym) PuppetLint.configuration.checks.each do |check| if enable_checks.include?(check) PuppetLint.configuration.send("enable_#{check}") else PuppetLint.configuration.send("disable_#{check}") end end end Array(@disable_checks).each do |check| PuppetLint.configuration.send("disable_#{check}") end ['with_filename', 'fail_on_warnings', 'error_level', 'log_format', 'with_context', 'fix', 'show_ignored', 'relative'].each do |config| value = instance_variable_get("@#{config}") PuppetLint.configuration.send("#{config}=".to_sym, value) unless value.nil? end if PuppetLint.configuration.ignore_paths && @ignore_paths.empty? @ignore_paths = PuppetLint.configuration.ignore_paths end if PuppetLint.configuration.pattern @pattern = PuppetLint.configuration.pattern end RakeFileUtils.send(:verbose, true) do linter = PuppetLint.new matched_files = FileList[@pattern] all_problems = [] matched_files = matched_files.exclude(*@ignore_paths) matched_files.to_a.each do |puppet_file| next unless File.file?(puppet_file) linter.file = puppet_file linter.run all_problems << linter.print_problems if PuppetLint.configuration.fix && linter.problems.none? { |e| e[:check] == :syntax } IO.write(puppet_file, linter.manifest) end end if PuppetLint.configuration.codeclimate_report_file PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) end abort if linter.errors? || ( linter.warnings? && PuppetLint.configuration.fail_on_warnings ) end end end |