puppet-ghostbuster 0.9.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +17 -0
  3. data/.github/workflows/release.yml +33 -0
  4. data/.github/workflows/test.yml +57 -0
  5. data/.gitignore +5 -4
  6. data/.rubocop.yml +8 -0
  7. data/.rubocop_todo.yml +173 -0
  8. data/CHANGELOG.md +226 -95
  9. data/Gemfile +13 -1
  10. data/README.md +20 -5
  11. data/Rakefile +31 -9
  12. data/lib/puppet-ghostbuster/puppetdb.rb +35 -9
  13. data/lib/puppet-ghostbuster/util.rb +19 -0
  14. data/lib/puppet-ghostbuster/version.rb +1 -1
  15. data/lib/puppet-lint/plugins/check_ghostbuster_classes.rb +4 -4
  16. data/lib/puppet-lint/plugins/check_ghostbuster_defines.rb +4 -5
  17. data/lib/puppet-lint/plugins/check_ghostbuster_facts.rb +21 -19
  18. data/lib/puppet-lint/plugins/check_ghostbuster_files.rb +11 -10
  19. data/lib/puppet-lint/plugins/check_ghostbuster_functions.rb +9 -8
  20. data/lib/puppet-lint/plugins/check_ghostbuster_hiera_files.rb +45 -33
  21. data/lib/puppet-lint/plugins/check_ghostbuster_templates.rb +14 -11
  22. data/lib/puppet-lint/plugins/check_ghostbuster_types.rb +4 -4
  23. data/puppet-ghostbuster.gemspec +21 -19
  24. data/spec/fixtures/hiera.yaml +17 -12
  25. data/spec/fixtures/modules/foo/lib/facter/asym.rb +8 -0
  26. data/spec/fixtures/modules/foo/lib/facter/bar.rb +2 -0
  27. data/spec/fixtures/modules/foo/lib/facter/baz.rb +2 -0
  28. data/spec/fixtures/modules/foo/lib/facter/foo.rb +2 -0
  29. data/spec/fixtures/modules/foo/lib/facter/multi.rb +2 -0
  30. data/spec/fixtures/modules/foo/lib/facter/quux.rb +2 -0
  31. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/bar.rb +8 -2
  32. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/baz.rb +8 -2
  33. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/foo.rb +8 -2
  34. data/spec/fixtures/modules/foo/lib/puppet/parser/functions/quux.rb +8 -2
  35. data/spec/fixtures/modules/foo/lib/puppet/type/bar.rb +2 -0
  36. data/spec/fixtures/modules/foo/lib/puppet/type/foo.rb +2 -0
  37. data/spec/puppet-lint/plugins/ghostbuster_classes_spec.rb +10 -9
  38. data/spec/puppet-lint/plugins/ghostbuster_defines_spec.rb +11 -11
  39. data/spec/puppet-lint/plugins/ghostbuster_facts_spec.rb +33 -20
  40. data/spec/puppet-lint/plugins/ghostbuster_files_spec.rb +25 -25
  41. data/spec/puppet-lint/plugins/ghostbuster_functions_spec.rb +16 -15
  42. data/spec/puppet-lint/plugins/ghostbuster_hiera_files_spec.rb +54 -30
  43. data/spec/puppet-lint/plugins/ghostbuster_templates_spec.rb +17 -16
  44. data/spec/puppet-lint/plugins/ghostbuster_types_spec.rb +10 -9
  45. data/spec/spec_helper.rb +34 -34
  46. metadata +78 -36
  47. data/.travis.yml +0 -20
@@ -8,7 +8,7 @@ class PuppetLint::Checks
8
8
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
9
9
  PuppetLint::Data.tokens = lexer.tokenise(content)
10
10
  PuppetLint::Data.parse_control_comments
11
- rescue
11
+ rescue StandardError
12
12
  PuppetLint::Data.tokens = []
13
13
  end
14
14
  end
@@ -27,9 +27,9 @@ PuppetLint.new_check(:ghostbuster_classes) do
27
27
  return if puppetdb.classes.include? title
28
28
 
29
29
  notify :warning, {
30
- :message => "Class #{title} seems unused",
31
- :line => title_token.line,
32
- :column => title_token.column,
30
+ message: "Class #{title} seems unused",
31
+ line: title_token.line,
32
+ column: title_token.column,
33
33
  }
34
34
  end
35
35
  end
@@ -8,7 +8,7 @@ class PuppetLint::Checks
8
8
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
9
9
  PuppetLint::Data.tokens = lexer.tokenise(content)
10
10
  PuppetLint::Data.parse_control_comments
11
- rescue
11
+ rescue StandardError
12
12
  PuppetLint::Data.tokens = []
13
13
  end
14
14
  end
@@ -27,11 +27,10 @@ PuppetLint.new_check(:ghostbuster_defines) do
27
27
  return if puppetdb.resources.include? type
28
28
 
29
29
  notify :warning, {
30
- :message => "Define #{type} seems unused",
31
- :line => title_token.line,
32
- :column => title_token.column,
30
+ message: "Define #{type} seems unused",
31
+ line: title_token.line,
32
+ column: title_token.column,
33
33
  }
34
34
  end
35
35
  end
36
36
  end
37
-
@@ -1,3 +1,5 @@
1
+ require 'puppet-ghostbuster/util'
2
+
1
3
  class PuppetLint::Checks
2
4
  def load_data(path, content)
3
5
  lexer = PuppetLint::Lexer.new
@@ -6,7 +8,7 @@ class PuppetLint::Checks
6
8
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
7
9
  PuppetLint::Data.tokens = lexer.tokenise(content)
8
10
  PuppetLint::Data.parse_control_comments
9
- rescue
11
+ rescue StandardError
10
12
  PuppetLint::Data.tokens = []
11
13
  end
12
14
  end
@@ -18,37 +20,37 @@ PuppetLint.new_check(:ghostbuster_facts) do
18
20
  end
19
21
 
20
22
  def templates
21
- Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
23
+ Dir.glob('./**/templates/**/*').select { |f| File.file? f }
22
24
  end
23
25
 
24
26
  def check
25
27
  m = path.match(%r{.*/([^/]+)/lib/facter/(.+)$})
26
28
  return if m.nil?
27
29
 
28
- File.readlines(path).grep(%r{Facter.add\(["']([^"']+)["']\)}).each do |line|
29
- fact_name = line.match(%r{Facter.add\(["']([^"']+)["']\)}).captures[0]
30
+ File.foreach(path) do |line|
31
+ if line =~ /Facter.add\(["':](?<fact>[^"'\)]+)["']?\)/
32
+ fact_name = Regexp.last_match(:fact)
30
33
 
31
- found = false
34
+ found = false
32
35
 
33
- manifests.each do |manifest|
34
- found = true if File.readlines(manifest).grep(%r{\$\{?::#{fact_name}\}?}).size > 0
35
- found = true if File.readlines(manifest).grep(%r{@#{fact_name}}).size > 0
36
- break if found
37
- end
36
+ manifests.each do |manifest|
37
+ found = true unless PuppetGhostbuster::Util.search_file(manifest, /(\$\{?::#{fact_name}\}?|@#{fact_name})/).nil?
38
+ break if found
39
+ end
38
40
 
39
- templates.each do |template|
40
- found = true if File.readlines(template).grep(%r{@#{fact_name}}).size > 0
41
- break if found
42
- end
41
+ templates.each do |template|
42
+ found = true unless PuppetGhostbuster::Util.search_file(template, /@#{fact_name}/).nil?
43
+ break if found
44
+ end
45
+
46
+ next if found
43
47
 
44
- unless found
45
48
  notify :warning, {
46
- :message => "Fact #{fact_name} seems unused",
47
- :line => 1,
48
- :column => 1,
49
+ message: "Fact #{fact_name} seems unused",
50
+ line: 1,
51
+ column: 1,
49
52
  }
50
53
  end
51
54
  end
52
-
53
55
  end
54
56
  end
@@ -1,4 +1,5 @@
1
1
  require 'puppet-ghostbuster/puppetdb'
2
+ require 'puppet-ghostbuster/util'
2
3
 
3
4
  class PuppetLint::Checks
4
5
  def load_data(path, content)
@@ -8,7 +9,7 @@ class PuppetLint::Checks
8
9
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
9
10
  PuppetLint::Data.tokens = lexer.tokenise(content)
10
11
  PuppetLint::Data.parse_control_comments
11
- rescue
12
+ rescue StandardError
12
13
  PuppetLint::Data.tokens = []
13
14
  end
14
15
  end
@@ -30,29 +31,29 @@ PuppetLint.new_check(:ghostbuster_files) do
30
31
  return if puppetdb.client.request('', query).data.size > 0
31
32
 
32
33
  dir_name = File.dirname(file_name)
33
- while dir_name != '.' do
34
+ while dir_name != '.'
34
35
  query = "resources[title] {
35
36
  (parameters.source = 'puppet:///modules/#{module_name}/#{dir_name}'
36
37
  or parameters.source = 'puppet:///modules/#{module_name}/#{dir_name}/')
37
38
  and parameters.recurse = true
38
39
  and nodes { deactivated is null } }"
39
40
  return if puppetdb.client.request('', query).data.size > 0
41
+
40
42
  dir_name = File.dirname(dir_name)
41
43
  end
42
44
 
43
45
  manifests.each do |manifest|
44
- return if File.readlines(manifest).grep(%r{["']#{module_name}/#{file_name}["']}).size > 0
45
- if match = manifest.match(%r{.*/([^/]+)/manifests/.+$})
46
- if match.captures[0] == module_name
47
- return if File.readlines(manifest).grep(/["']\$\{module_name\}\/#{file_name}["']/).size > 0
48
- end
46
+ return if PuppetGhostbuster::Util.search_file(manifest, %r{["']#{module_name}/#{file_name}["']})
47
+
48
+ if (match = manifest.match(%r{.*/([^/]+)/manifests/.+$})) && (match.captures[0] == module_name) && PuppetGhostbuster::Util.search_file(manifest, %r{["']\$\{module_name\}/#{file_name}["']})
49
+ return
49
50
  end
50
51
  end
51
52
 
52
53
  notify :warning, {
53
- :message => "File #{module_name}/#{file_name} seems unused",
54
- :line => 1,
55
- :column => 1,
54
+ message: "File #{module_name}/#{file_name} seems unused",
55
+ line: 1,
56
+ column: 1,
56
57
  }
57
58
  end
58
59
  end
@@ -1,3 +1,5 @@
1
+ require 'puppet-ghostbuster/util'
2
+
1
3
  class PuppetLint::Checks
2
4
  def load_data(path, content)
3
5
  lexer = PuppetLint::Lexer.new
@@ -6,7 +8,7 @@ class PuppetLint::Checks
6
8
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
7
9
  PuppetLint::Data.tokens = lexer.tokenise(content)
8
10
  PuppetLint::Data.parse_control_comments
9
- rescue
11
+ rescue StandardError
10
12
  PuppetLint::Data.tokens = []
11
13
  end
12
14
  end
@@ -18,7 +20,7 @@ PuppetLint.new_check(:ghostbuster_functions) do
18
20
  end
19
21
 
20
22
  def templates
21
- Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
23
+ Dir.glob('./**/templates/**/*').select { |f| File.file? f }
22
24
  end
23
25
 
24
26
  def check
@@ -28,18 +30,17 @@ PuppetLint.new_check(:ghostbuster_functions) do
28
30
  function_name = m.captures[0]
29
31
 
30
32
  manifests.each do |manifest|
31
- return if File.readlines(manifest).grep(%r{#{function_name}\(}).size > 0
33
+ return if PuppetGhostbuster::Util.search_file(manifest, "#{function_name}(")
32
34
  end
33
35
 
34
36
  templates.each do |template|
35
- return if File.readlines(template).grep(%r{scope.function_#{function_name}\(}).size > 0
36
- return if File.readlines(template).grep(%r{Puppet::Parser::Functions.function\(:#{function_name}}).size > 0
37
+ return if PuppetGhostbuster::Util.search_file(template, /(Puppet::Parser::Functions\.function\(:|scope\.function_)#{function_name}/)
37
38
  end
38
39
 
39
40
  notify :warning, {
40
- :message => "Function #{function_name} seems unused",
41
- :line => 1,
42
- :column => 1,
41
+ message: "Function #{function_name} seems unused",
42
+ line: 1,
43
+ column: 1,
43
44
  }
44
45
  end
45
46
  end
@@ -6,72 +6,84 @@ class PuppetLint::Checks
6
6
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
7
7
  PuppetLint::Data.tokens = lexer.tokenise(content)
8
8
  PuppetLint::Data.parse_control_comments
9
- rescue
9
+ rescue StandardError
10
10
  PuppetLint::Data.tokens = []
11
11
  end
12
12
  end
13
13
  end
14
14
 
15
15
  PuppetLint.new_check(:ghostbuster_hiera_files) do
16
+ def hiera
17
+ @hiera ||= YAML.load_file(ENV['HIERA_YAML_PATH'] || '/etc/puppetlabs/code/hiera.yaml')
18
+ end
19
+
20
+ def default_datadir
21
+ hiera.dig('defaults', 'datadir') || 'hieradata'
22
+ end
23
+
24
+ def path_in_datadirs?(path)
25
+ @data_dirs ||= hiera['hierarchy'].map { |h| (h['datadir'] || default_datadir).chomp('/') }.uniq
26
+ path.match?(%(./#{Regexp.union(@data_dirs)}/))
27
+ end
16
28
 
17
29
  def regexprs
18
- hiera_yaml_file = ENV['HIERA_YAML_PATH'] || '/etc/puppetlabs/code/hiera.yaml'
19
- hiera = YAML.load_file(hiera_yaml_file)
20
30
  regs = {}
21
- hiera[:hierarchy].each do |hierarchy|
22
- regex = hierarchy.gsub(/%\{(::)?(trusted|server_facts|facts)\.[^\}]+\}/, "(.+)").gsub(/%\{[^\}]+\}/, ".+")
23
- facts = hierarchy.match(regex).captures.map { |f| f[/%{(::)?(trusted|server_facts|facts)\.(.+)}/, 3] }
24
- regs[regex] = facts
31
+ hiera['hierarchy'].each do |hierarchy|
32
+ path_datadir = Regexp.escape((hierarchy['datadir'] || default_datadir).chomp('/'))
33
+ ([*hierarchy['path']] + [*hierarchy['paths']]).each do |level|
34
+ level = File.join(path_datadir, level)
35
+ regex = Regexp.new(level.gsub(/%\{(::)?(trusted|server_facts|facts)\.[^\}]+\}/, '(.+)').gsub(/%\{[^\}]+\}/, '.+'))
36
+ facts = level.match(regex).captures.map { |f| f[/%{(::)?(trusted|server_facts|facts)\.(.+)}/, 3] }
37
+ regs[regex] = facts
38
+ end
25
39
  end
26
40
  regs
27
41
  end
28
42
 
29
43
  def check
30
- return if path.match(%r{./hieradata/.*\.yaml}).nil?
44
+ return unless path_in_datadirs? path
31
45
 
32
46
  puppetdb = PuppetGhostbuster::PuppetDB.new
33
- _path = path.gsub("./hieradata/", "")
34
47
 
35
48
  regexprs.each do |k, v|
36
- m = _path.match(Regexp.new "#{k}\.yaml")
49
+ m = path.match(k)
37
50
  next if m.nil?
51
+
38
52
  return if m.captures.size == 0
39
53
 
40
54
  if m.captures.size > 1
41
55
  i = 0
42
- query = [:'and']
56
+ query = [:and]
43
57
  m.captures.map do |value|
44
- if v[i] == 'certname'
45
- query << [:'=', v[i], value]
46
- else
47
- query << [:'=', ['fact', v[i]], value]
48
- end
58
+ query << if v[i] == 'certname'
59
+ [:'=', v[i], value]
60
+ else
61
+ [:'=', ['fact', v[i]], value]
62
+ end
49
63
  i += 1
50
64
  end
65
+ elsif v[0] == 'certname'
66
+ query = [:'=', 'certname', m.captures[0]]
51
67
  else
52
- if v[0] == 'certname'
53
- query = [:'=', 'certname', m.captures[0]]
54
- else
55
- value = if m.captures[0] == 'true'
56
- true
57
- elsif m.captures[0] == 'false'
58
- false
59
- else
60
- m.captures[0]
61
- end
62
- query = [:'=', ['fact', v[0]], value]
63
- end
68
+ value = if m.captures[0] == 'true'
69
+ true
70
+ elsif m.captures[0] == 'false'
71
+ false
72
+ else
73
+ m.captures[0]
74
+ end
75
+ query = [:'=', ['fact', v[0]], value]
64
76
  end
65
77
 
66
- query = [:'and', query, [:'=', 'deactivated', nil]]
78
+ query = [:and, query, [:'=', 'deactivated', nil]]
67
79
 
68
- return if puppetdb.client.request('nodes', query ).data.size > 0
80
+ return if puppetdb.client.request('nodes', query).data.size > 0
69
81
  end
70
82
 
71
83
  notify :warning, {
72
- :message => "Hiera File #{_path} seems unused",
73
- :line => 1,
74
- :column => 1,
84
+ message: "Hiera File #{path} seems unused",
85
+ line: 1,
86
+ column: 1,
75
87
  }
76
88
  end
77
89
  end
@@ -1,3 +1,5 @@
1
+ require 'puppet-ghostbuster/util'
2
+
1
3
  class PuppetLint::Checks
2
4
  def load_data(path, content)
3
5
  lexer = PuppetLint::Lexer.new
@@ -6,7 +8,7 @@ class PuppetLint::Checks
6
8
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
7
9
  PuppetLint::Data.tokens = lexer.tokenise(content)
8
10
  PuppetLint::Data.parse_control_comments
9
- rescue
11
+ rescue StandardError
10
12
  PuppetLint::Data.tokens = []
11
13
  end
12
14
  end
@@ -18,7 +20,7 @@ PuppetLint.new_check(:ghostbuster_templates) do
18
20
  end
19
21
 
20
22
  def templates
21
- Dir.glob('./**/templates/**/*').select{ |f| File.file? f }
23
+ Dir.glob('./**/templates/**/*').select { |f| File.file? f }
22
24
  end
23
25
 
24
26
  def check
@@ -28,22 +30,23 @@ PuppetLint.new_check(:ghostbuster_templates) do
28
30
  module_name, template_name = m.captures
29
31
 
30
32
  manifests.each do |manifest|
31
- return if File.readlines(manifest).grep(%r{["']#{module_name}/#{template_name}["']}).size > 0
32
- if match = manifest.match(%r{.*/([^/]+)/manifests/.+$})
33
- if match.captures[0] == module_name
34
- return if File.readlines(manifest).grep(/["']\$\{module_name\}\/#{template_name}["']/).size > 0
35
- end
33
+ return if PuppetGhostbuster::Util.search_file(manifest, %r{["']#{module_name}/#{template_name}["']})
34
+
35
+ next unless match = manifest.match(%r{.*/([^/]+)/manifests/.+$})
36
+
37
+ if match.captures[0] == module_name && PuppetGhostbuster::Util.search_file(manifest, %r{["']\$\{module_name\}/#{template_name}["']})
38
+ return
36
39
  end
37
40
  end
38
41
 
39
42
  templates.each do |template|
40
- return if File.readlines(template).grep(%r{scope.function_template\(\['#{module_name}/#{template_name}'\]\)}).size > 0
43
+ return if PuppetGhostbuster::Util.search_file(template, "scope.function_template(['#{module_name}/#{template_name}'])")
41
44
  end
42
45
 
43
46
  notify :warning, {
44
- :message => "Template #{module_name}/#{template_name} seems unused",
45
- :line => 1,
46
- :column => 1,
47
+ message: "Template #{module_name}/#{template_name} seems unused",
48
+ line: 1,
49
+ column: 1,
47
50
  }
48
51
  end
49
52
  end
@@ -8,7 +8,7 @@ class PuppetLint::Checks
8
8
  PuppetLint::Data.manifest_lines = content.split("\n", -1)
9
9
  PuppetLint::Data.tokens = lexer.tokenise(content)
10
10
  PuppetLint::Data.parse_control_comments
11
- rescue
11
+ rescue StandardError
12
12
  PuppetLint::Data.tokens = []
13
13
  end
14
14
  end
@@ -29,9 +29,9 @@ PuppetLint.new_check(:ghostbuster_types) do
29
29
  return if puppetdb.resources.include? type_name.capitalize
30
30
 
31
31
  notify :warning, {
32
- :message => "Type #{type_name.capitalize} seems unused",
33
- :line => 1,
34
- :column => 1,
32
+ message: "Type #{type_name.capitalize} seems unused",
33
+ line: 1,
34
+ column: 1,
35
35
  }
36
36
  end
37
37
  end
@@ -1,29 +1,31 @@
1
- # -*- encoding: utf-8 -*-
2
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
- require "puppet-ghostbuster/version"
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('lib', __dir__)
4
+ require 'puppet-ghostbuster/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
- s.name = "puppet-ghostbuster"
7
+ s.name = 'puppet-ghostbuster'
7
8
  s.version = PuppetGhostbuster::VERSION
8
- s.authors = ["Camptocamp"]
9
- s.homepage = "http://github.com/camptocamp/puppet-ghostbuster"
10
- s.summary = "Dead code detector for Puppet"
11
- s.description = "Try and find dead code in Puppet receipts"
9
+ s.authors = ['Camptocamp', 'Vox Pupuli']
10
+ s.homepage = 'http://github.com/voxpupuli/puppet-ghostbuster'
11
+ s.summary = 'Dead code detector for Puppet'
12
+ s.description = 'Try and find dead code in Puppet receipts'
12
13
  s.licenses = 'Apache-2.0'
13
14
 
15
+ s.required_ruby_version = '>= 2.7'
16
+
14
17
  s.files = `git ls-files`.split("\n")
15
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
17
19
 
18
- s.add_development_dependency 'coveralls'
19
- s.add_development_dependency 'rake'
20
+ s.add_development_dependency 'coveralls', '>= 0.8', '< 0.9'
21
+ s.add_development_dependency 'jgrep', '>= 1.0.0', '< 2.0.0'
22
+ s.add_development_dependency 'rake', '>= 13.0.0', '< 14.0.0'
20
23
  s.add_development_dependency 'rspec', '~> 3.0'
21
- s.add_development_dependency 'rspec-its', '~> 1.0'
22
24
  s.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
23
- s.add_development_dependency 'github_changelog_generator'
24
- s.add_development_dependency 'jgrep'
25
- s.add_runtime_dependency 'json'
26
- s.add_runtime_dependency 'puppet'
27
- s.add_dependency 'puppet-lint', '>= 1.0', '< 3.0'
28
- s.add_runtime_dependency 'puppetdb-ruby', '>= 1.1.1'
25
+ s.add_development_dependency 'rspec-its', '~> 1.0'
26
+ s.add_development_dependency 'voxpupuli-rubocop', '~> 2.4.0'
27
+ s.add_runtime_dependency 'json', '>= 2.0', '< 3.0'
28
+ s.add_runtime_dependency 'puppet', '>= 6.0', '< 9.0'
29
+ s.add_dependency 'puppet-lint', '>= 1.0', '< 5.0'
30
+ s.add_runtime_dependency 'puppetdb-ruby', '~> 1.1', '>= 1.1.1'
29
31
  end
@@ -1,13 +1,18 @@
1
1
  ---
2
- :backends: yaml
3
- :yaml:
4
- :datadir: "/etc/puppetlabs/code/environments/%{environment}/hieradata"
5
- :hierarchy:
6
- - "nodes/%{::trusted.certname}"
7
- - "environment/%{server_facts.environment}"
8
- - "virtual/%{facts.is_virtual}"
9
- - "domain/%{::domain}"
10
- - "common"
11
- :logger: console
12
- :merge_behavior: native
13
- :deep_merge_options: {}
2
+ version: 5
3
+ defaults:
4
+ datadir: data
5
+ hierarchy:
6
+ - name: "Some other location"
7
+ datadir: private/
8
+ path: "nodes/%{trusted.certname}.eyaml"
9
+
10
+ - name: "Per-node data (yaml version)"
11
+ path: "nodes/%{trusted.certname}.yaml"
12
+
13
+ - name: "Other YAML hierarchy levels"
14
+ paths:
15
+ - "environment/%{server_facts.environment}.yaml"
16
+ - "virtual/%{facts.is_virtual}.yaml"
17
+ - "domain/%{domain}.yaml"
18
+ - "common.yaml"
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Fact is a symbol
4
+ Facter.add(:asym) do
5
+ setcode do
6
+ 'asym'
7
+ end
8
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Fact used in manifest
2
4
  Facter.add('bar') do
3
5
  setcode do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Fact used in template
2
4
  Facter.add('baz') do
3
5
  setcode do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Fact used in a string
2
4
  Facter.add('foo') do
3
5
  setcode do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Unused facts
2
4
  Facter.add('multi1') do
3
5
  setcode do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Fact used in inline_template
2
4
  Facter.add('quux') do
3
5
  setcode do
@@ -1,4 +1,10 @@
1
- module Puppet::Parser::Functions
2
- newfunction(:bar, :type => :rvalue) do |arguments|
1
+ # frozen_string_literal: true
2
+
3
+ module Puppet
4
+ module Parser
5
+ module Functions
6
+ newfunction(:bar, type: :rvalue) do |arguments|
7
+ end
8
+ end
3
9
  end
4
10
  end
@@ -1,4 +1,10 @@
1
- module Puppet::Parser::Functions
2
- newfunction(:baz, :type => :rvalue) do |arguments|
1
+ # frozen_string_literal: true
2
+
3
+ module Puppet
4
+ module Parser
5
+ module Functions
6
+ newfunction(:baz, type: :rvalue) do |arguments|
7
+ end
8
+ end
3
9
  end
4
10
  end
@@ -1,4 +1,10 @@
1
- module Puppet::Parser::Functions
2
- newfunction(:foo, :type => :rvalue) do |arguments|
1
+ # frozen_string_literal: true
2
+
3
+ module Puppet
4
+ module Parser
5
+ module Functions
6
+ newfunction(:foo, type: :rvalue) do |arguments|
7
+ end
8
+ end
3
9
  end
4
10
  end
@@ -1,4 +1,10 @@
1
- module Puppet::Parser::Functions
2
- newfunction(:quux, :type => :rvalue) do |arguments|
1
+ # frozen_string_literal: true
2
+
3
+ module Puppet
4
+ module Parser
5
+ module Functions
6
+ newfunction(:quux, type: :rvalue) do |arguments|
7
+ end
8
+ end
3
9
  end
4
10
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Puppet::Type.newtype(:bar) do
2
4
  end
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  Puppet::Type.newtype(:foo) do
2
4
  end
@@ -1,26 +1,27 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  describe 'ghostbuster_classes' do
4
- let(:path) { "./modules/foo/manifests/init.pp" }
6
+ let(:path) { './modules/foo/manifests/init.pp' }
5
7
 
6
8
  context 'with fix disabled' do
7
-
8
9
  context 'when class is used' do
9
- let(:code) { "class foo {}" }
10
+ let(:code) { 'class foo {}' }
10
11
 
11
- it 'should not detect any problem' do
12
- expect(problems).to have(0).problems
12
+ it 'does not detect any problem' do
13
+ expect(problems.size).to eq(0)
13
14
  end
14
15
  end
15
16
 
16
17
  context 'when class is not used' do
17
- let(:code) { "class bar {}" }
18
+ let(:code) { 'class bar {}' }
18
19
 
19
- it 'should detect one problem' do
20
- expect(problems).to have(1).problems
20
+ it 'detects one problem' do
21
+ expect(problems.size).to eq(1)
21
22
  end
22
23
 
23
- it 'should create a warning' do
24
+ it 'creates a warning' do
24
25
  expect(problems).to contain_warning('Class Bar seems unused')
25
26
  end
26
27
  end