Sha256: 4d40abd07181a0ea672d5eed9f1919d6835897226cc8b102c00a6948e2c1e8c4

Contents?: true

Size: 962 Bytes

Versions: 3

Compression:

Stored size: 962 Bytes

Contents

require 'puppet-ghostbuster/puppetdb'

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_classes) do
  def check
    return if path.match(%r{^\./(:?[^/]+/){2}?manifests/.+$}).nil?

    puppetdb = PuppetGhostbuster::PuppetDB.new

    class_indexes.each do |class_idx|
      title_token = class_idx[:name_token]
      title = title_token.value.split('::').map(&:capitalize).join('::')

      return if puppetdb.classes.include? title

      notify :warning, {
        message: "Class #{title} seems unused",
        line: title_token.line,
        column: title_token.column,
      }
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
puppet-ghostbuster-1.2.1 lib/puppet-lint/plugins/check_ghostbuster_classes.rb
puppet-ghostbuster-1.2.0 lib/puppet-lint/plugins/check_ghostbuster_classes.rb
puppet-ghostbuster-1.1.0 lib/puppet-lint/plugins/check_ghostbuster_classes.rb