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.



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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/puppet-syntax/tasks/puppet-syntax.rb', line 25

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
        $stderr.puts "[WARNING] A conflicting :syntax rake task has been defined by\npuppetlabs_spec_helper/rake_tasks. You should either disable this or upgrade\nto puppetlabs_spec_helper >= 0.8.0 which now uses puppet-syntax.\n        EOS\n      end\n    end\n\n    desc 'Syntax check Puppet manifests'\n    task :manifests do |t|\n      if Puppet.version.to_i >= 4 and PuppetSyntax.future_parser\n        $stderr.puts <<-EOS\n[INFO] Puppet 4 has been detected and `future_parser` has been set to\n'true'. The `future_parser setting will be ignored.\n        EOS\n      end\n      if Puppet::Util::Package.versioncmp(Puppet.version, '4.3.0') < 0 and PuppetSyntax.app_management\n        $stderr.puts <<-EOS\n[WARNING] Puppet `app_management` has been detected but the Puppet\nversion is less then 4.3.  The `app_management` setting will be ignored.\n        EOS\n      end\n\n      $stderr.puts \"---> \#{t.name}\"\n\n      c = PuppetSyntax::Manifests.new\n      output, has_errors = c.check(filelist_manifests)\n      print \"\#{output.join(\"\\n\")}\\n\" unless output.empty?\n      fail if has_errors || ( output.any? && PuppetSyntax.fail_on_deprecation_notices )\n    end\n\n    desc 'Syntax check Puppet templates'\n    task :templates do |t|\n      $stderr.puts \"---> \#{t.name}\"\n\n      c = PuppetSyntax::Templates.new\n      errors = c.check(filelist_templates)\n      fail errors.join(\"\\n\") unless errors.empty?\n    end\n\n    desc 'Syntax check Hiera config files'\n    task :hiera => [\n      'syntax:hiera:yaml',\n    ]\n\n    namespace :hiera do\n      task :yaml do |t|\n        $stderr.puts \"---> \#{t.name}\"\n        c = PuppetSyntax::Hiera.new\n        errors = c.check(filelist_hiera_yaml)\n        fail errors.join(\"\\n\") unless errors.empty?\n      end\n    end\n  end\nend\n"

Instance Method Details

#filelist(paths) ⇒ Object



7
8
9
10
11
# File 'lib/puppet-syntax/tasks/puppet-syntax.rb', line 7

def filelist(paths)
  files = FileList[paths]
  files.reject! { |f| File.directory?(f) }
  files.exclude(*PuppetSyntax.exclude_paths)
end

#filelist_hiera_yamlObject



21
22
23
# File 'lib/puppet-syntax/tasks/puppet-syntax.rb', line 21

def filelist_hiera_yaml
  filelist(PuppetSyntax.hieradata_paths)
end

#filelist_manifestsObject



13
14
15
# File 'lib/puppet-syntax/tasks/puppet-syntax.rb', line 13

def filelist_manifests
  filelist("**/*.pp")
end

#filelist_templatesObject



17
18
19
# File 'lib/puppet-syntax/tasks/puppet-syntax.rb', line 17

def filelist_templates
  filelist(["**/templates/**/*.erb", "**/templates/**/*.epp"])
end