Sha256: d19dfe18f840b73b1fb60ff2e3bbb4cae196a5b5521610d3fd5ff8409bf30fca

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 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 StandardError
      PuppetLint::Data.tokens = []
    end
  end
end

PuppetLint.new_check(:ghostbuster_functions) 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{.*/[^/]+/lib/puppet/parser/functions/(.+)\.rb$})
    return if m.nil?

    function_name = m.captures[0]

    manifests.each do |manifest|
      return if File.readlines(manifest).grep(/#{function_name}\(/).size > 0
    end

    templates.each do |template|
      return if File.readlines(template).grep(/scope.function_#{function_name}\(/).size > 0
      return if File.readlines(template).grep(/Puppet::Parser::Functions.function\(:#{function_name}/).size > 0
    end

    notify :warning, {
      message: "Function #{function_name} seems unused",
      line: 1,
      column: 1,
    }
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
puppet-ghostbuster-1.1.0 lib/puppet-lint/plugins/check_ghostbuster_functions.rb