Sha256: 24fe3fd2b1c43696379beebff96365ab21713600d0afa9ab88caaeaa775a7b27

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

class PuppetLint::Checks
  def load_data(path, content)
    lexer = PuppetLint::Lexer.new
    PuppetLint::Data.path = path
    begin
      PuppetLint::Data.manifest_lines = content.split("\n", -1)
      PuppetLint::Data.tokens = lexer.tokenise(content)
      PuppetLint::Data.parse_control_comments
    rescue
      PuppetLint::Data.tokens = []
    end
  end
end

PuppetLint.new_check(:ghostbuster_templates) do
  def manifests
    Dir.glob('./**/manifests/**/*.pp')
  end

  def templates
    Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
  end

  def check
    m = path.match(%r{.*/([^/]+)/templates/(.+)$})
    return if m.nil?

    module_name, template_name = m.captures

    manifests.each do |manifest|
      return if File.readlines(manifest).grep(%r{["']#{module_name}/#{template_name}["']}).size > 0
      if match = manifest.match(%r{.*/([^/]+)/manifests/.+$})
        if match.captures[0] == module_name
          return if File.readlines(manifest).grep(/["']\$\{module_name\}\/#{template_name}["']/).size > 0
        end
      end
    end

    templates.each do |template|
      return if File.readlines(template).grep(%r{scope.function_template\(\['#{module_name}/#{template_name}'\]\)}).size > 0
    end

    notify :warning, {
      :message => "Template #{module_name}/#{template_name} seems unused",
      :line    => 1,
      :column  => 1,
    }
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
puppet-ghostbuster-0.9.0 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.8.0 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.7.3 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.7.2 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.7.1 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.7.0 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.6.0 lib/puppet-lint/plugins/check_ghostbuster_templates.rb
puppet-ghostbuster-0.5.1 lib/puppet-lint/plugins/check_ghostbuster_templates.rb