Class: PuppetSyntax::RakeTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/puppet-syntax/tasks/puppet-syntax.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ RakeTask

Returns a new instance of RakeTask.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
# File 'lib/puppet-syntax/tasks/puppet-syntax.rb', line 7

def initialize(*args)
  desc 'Syntax check Puppet manifests and templates'
  task :syntax => [
    'syntax:check_puppetlabs_spec_helper',
    'syntax:manifests',
    'syntax:templates',
    'syntax:hiera',
  ]

  namespace :syntax do
    task :check_puppetlabs_spec_helper do
      psh_present = Rake::Task[:syntax].actions.any? { |a|
        a.inspect.match(/puppetlabs_spec_helper\/rake_tasks\.rb:\d+/)
      }

      if psh_present
        warn <<-EOS
[WARNING] A conflicting :syntax rake task has been defined by
puppetlabs_spec_helper/rake_tasks. You should either disable this or upgrade
to puppetlabs_spec_helper >= 0.8.0 which now uses puppet-syntax.
        EOS
      end
    end

    desc 'Syntax check Puppet manifests'
    task :manifests do |t|
      if Puppet::PUPPETVERSION.to_i >= 4 and PuppetSyntax.future_parser
        info <<-EOS
[INFO] Puppet 4 has been detected and `future_parser` has been set to
'true'. The `future_parser setting will be ignored.
        EOS
      end
      $stderr.puts "---> #{t.name}"
      files = FileList["**/*.pp"]
      files.reject! { |f| File.directory?(f) }
      files = files.exclude(*PuppetSyntax.exclude_paths)

      c = PuppetSyntax::Manifests.new
      output, has_errors = c.check(files)
      print "#{output.join("\n")}\n" unless output.empty?
      fail if has_errors || ( output.any? && PuppetSyntax.fail_on_deprecation_notices )
    end

    desc 'Syntax check Puppet templates'
    task :templates do |t|
      $stderr.puts "---> #{t.name}"
      files = FileList["**/templates/**/*"]
      files.reject! { |f| File.directory?(f) }
      files = files.exclude(*PuppetSyntax.exclude_paths)

      c = PuppetSyntax::Templates.new
      errors = c.check(files)
      fail errors.join("\n") unless errors.empty?
    end

    desc 'Syntax check Hiera config files'
    task :hiera => [
      'syntax:hiera:yaml',
    ]

    namespace :hiera do
      task :yaml do |t|
        $stderr.puts "---> #{t.name}"
        files = FileList.new(PuppetSyntax.hieradata_paths)
        files.reject! { |f| File.directory?(f) }
        files = files.exclude(*PuppetSyntax.exclude_paths)

        c = PuppetSyntax::Hiera.new
        errors = c.check(files)
        fail errors.join("\n") unless errors.empty?
      end
    end
  end
end