puppet-lint-halyard 1.1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +3 -0
  5. data/LICENSE +20 -0
  6. data/README.md +210 -0
  7. data/Rakefile +14 -0
  8. data/bin/puppet-lint +7 -0
  9. data/lib/puppet-lint.rb +214 -0
  10. data/lib/puppet-lint/bin.rb +79 -0
  11. data/lib/puppet-lint/checkplugin.rb +176 -0
  12. data/lib/puppet-lint/checks.rb +91 -0
  13. data/lib/puppet-lint/configuration.rb +153 -0
  14. data/lib/puppet-lint/data.rb +521 -0
  15. data/lib/puppet-lint/lexer.rb +373 -0
  16. data/lib/puppet-lint/lexer/token.rb +101 -0
  17. data/lib/puppet-lint/monkeypatches.rb +2 -0
  18. data/lib/puppet-lint/monkeypatches/string_percent.rb +52 -0
  19. data/lib/puppet-lint/monkeypatches/string_prepend.rb +13 -0
  20. data/lib/puppet-lint/optparser.rb +118 -0
  21. data/lib/puppet-lint/plugins.rb +74 -0
  22. data/lib/puppet-lint/plugins/check_classes.rb +285 -0
  23. data/lib/puppet-lint/plugins/check_comments.rb +55 -0
  24. data/lib/puppet-lint/plugins/check_conditionals.rb +65 -0
  25. data/lib/puppet-lint/plugins/check_documentation.rb +31 -0
  26. data/lib/puppet-lint/plugins/check_nodes.rb +29 -0
  27. data/lib/puppet-lint/plugins/check_resources.rb +194 -0
  28. data/lib/puppet-lint/plugins/check_strings.rb +174 -0
  29. data/lib/puppet-lint/plugins/check_variables.rb +19 -0
  30. data/lib/puppet-lint/plugins/check_whitespace.rb +170 -0
  31. data/lib/puppet-lint/tasks/puppet-lint.rb +91 -0
  32. data/lib/puppet-lint/version.rb +3 -0
  33. data/puppet-lint.gemspec +24 -0
  34. data/spec/fixtures/test/manifests/fail.pp +2 -0
  35. data/spec/fixtures/test/manifests/ignore.pp +1 -0
  36. data/spec/fixtures/test/manifests/ignore_multiple_block.pp +6 -0
  37. data/spec/fixtures/test/manifests/ignore_multiple_line.pp +2 -0
  38. data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
  39. data/spec/fixtures/test/manifests/init.pp +3 -0
  40. data/spec/fixtures/test/manifests/malformed.pp +1 -0
  41. data/spec/fixtures/test/manifests/url_interpolation.pp +12 -0
  42. data/spec/fixtures/test/manifests/warning.pp +2 -0
  43. data/spec/puppet-lint/bin_spec.rb +326 -0
  44. data/spec/puppet-lint/configuration_spec.rb +56 -0
  45. data/spec/puppet-lint/ignore_overrides_spec.rb +109 -0
  46. data/spec/puppet-lint/lexer/token_spec.rb +18 -0
  47. data/spec/puppet-lint/lexer_spec.rb +783 -0
  48. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +105 -0
  49. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +35 -0
  50. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +33 -0
  51. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +45 -0
  52. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +76 -0
  53. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +73 -0
  54. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +25 -0
  55. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +196 -0
  56. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +45 -0
  57. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +84 -0
  58. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +98 -0
  59. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +36 -0
  60. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +52 -0
  61. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +146 -0
  62. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +100 -0
  63. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +55 -0
  64. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +89 -0
  65. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +113 -0
  66. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +45 -0
  67. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +216 -0
  68. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +199 -0
  69. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +114 -0
  70. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +62 -0
  71. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +129 -0
  72. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +17 -0
  73. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +73 -0
  74. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +37 -0
  75. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +21 -0
  76. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +54 -0
  77. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +524 -0
  78. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +45 -0
  79. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +101 -0
  80. data/spec/puppet-lint_spec.rb +20 -0
  81. data/spec/spec_helper.rb +129 -0
  82. metadata +229 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1c66a5c73ddd9227394aef946e8b7e6cf4f1aa4b
4
+ data.tar.gz: 938f29ee0193abd17d7c5d51a3246dda256f0794
5
+ SHA512:
6
+ metadata.gz: 01e8bfbc7bcac54e8b2dfe1ccb90a43c8de217e68f59e6dc05f858c8c0973a0fe760213837a1eccd23bfff75e9adaf61dfc37491d26f2b3d4c841c3e04a99799
7
+ data.tar.gz: d0ff8057db3909321c61d55b7b36381ade0c5f2bf4acc32909e338d5cb1ee670fe5d8810f314e5e248a71806cffdccff3efd46ab69ff912c7b99f7ed4afbb5cd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle/
3
+ .rbenv-version
4
+ .ruby-version
5
+ Gemfile.lock
6
+ vendor/gems
7
+ coverage/
8
+ *.swp
9
+ /_site/
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ before_install: gem update --system 2.1.11
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ notifications:
9
+ email:
10
+ - tim@github.com
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tim Sharpe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,210 @@
1
+ # Puppet-lint
2
+
3
+ The goal of this project is to implement as many of the recommended Puppet
4
+ style guidelines from the [Puppet Labs style
5
+ guide](http://docs.puppetlabs.com/guides/style_guide.html) as practical. It is not meant to validate syntax. Please use `puppet parser validate` for that.
6
+
7
+ ## Changes from upstream
8
+
9
+ * Released as puppet-lint-halyard
10
+ * Adjust rakefile to simplify publishing
11
+
12
+ ## Installation
13
+
14
+ gem install puppet-lint-halyard
15
+
16
+ ## Testing your manifests
17
+
18
+ ### By hand
19
+
20
+ You can test a single manifest file by running
21
+
22
+ puppet-lint <path to file>
23
+
24
+ ### Rake task
25
+
26
+ If you want to test your entire Puppet manifest directory, you can add
27
+ `require 'puppet-lint/tasks/puppet-lint'` to your Rakefile and then run
28
+
29
+ rake lint
30
+
31
+ If you want to modify the default behaviour of the rake task, you can modify
32
+ the PuppetLint configuration by defining the task yourself.
33
+
34
+ PuppetLint::RakeTask.new :lint do |config|
35
+ # Pattern of files to check, defaults to `**/*.pp`
36
+ config.pattern = 'modules'
37
+
38
+ # Pattern of files to ignore
39
+ config.ignore_paths = ['modules/apt', 'modules/stdlib']
40
+
41
+ # List of checks to disable
42
+ config.disable_checks = ['documentation', '80chars']
43
+
44
+ # Should puppet-lint prefix it's output with the file being checked,
45
+ # defaults to true
46
+ config.with_filename = false
47
+
48
+ # Should the task fail if there were any warnings, defaults to false
49
+ config.fail_on_warnings = true
50
+
51
+ # Format string for puppet-lint's output (see the puppet-lint help output
52
+ # for details
53
+ config.log_format = '%{filename} - %{message}'
54
+
55
+ # Print out the context for the problem, defaults to false
56
+ config.with_context = true
57
+
58
+ # Enable automatic fixing of problems, defaults to false
59
+ config.fix = true
60
+
61
+ # Show ignored problems in the output, defaults to false
62
+ config.show_ignored = true
63
+
64
+ # Compare module layout relative to the module root
65
+ config.relative = true
66
+ end
67
+
68
+ ## Implemented tests
69
+
70
+ At the moment, the following tests have been implemented:
71
+
72
+ ### Spacing, Indentation & Whitespace
73
+
74
+ * Must use two-space soft tabs.
75
+ * Must not use literal tab characters.
76
+ * Must not contain trailing white space.
77
+ * Should not exceed an 80 character line width
78
+ * An exception has been made for `source => 'puppet://...'` lines as
79
+ splitting these over multiple lines decreases the readability of the
80
+ manifests.
81
+ * Should align arrows (`=>`) within blocks of attributes.
82
+
83
+ ### Quoting
84
+
85
+ * All strings that do not contain variables should be enclosed in single
86
+ quotes.
87
+ * An exception has been made for double quoted strings containing \n or \t.
88
+ * All strings that contain variables must be enclosed in double quotes.
89
+ * All variables should be enclosed in braces when interpolated in a string.
90
+ * Variables standing by themselves should not be quoted.
91
+
92
+ ### Resources
93
+
94
+ * All resource titles should be quoted.
95
+ * An exception has been made for resource titles that consist of only
96
+ a variable standing by itself.
97
+ * If a resource declaration includes an `ensure` attribute, it should be the
98
+ first attribute specified.
99
+ * Symbolic links should be declared by using an ensure value of `link` and
100
+ explicitly specifying a value for the `target` attribute.
101
+ * File modes should be represented as a 4 digit string enclosed in single
102
+ quotes or use symbolic file modes.
103
+
104
+ ### Conditionals
105
+
106
+ * You should not intermingle conditionals inside resource declarations (i.e.
107
+ selectors inside resources).
108
+ * Case statements should have a default case.
109
+
110
+ ### Classes
111
+
112
+ * Relationship declarations with the chaining syntax should only be used in
113
+ the 'left to right' direction.
114
+ * Classes should not be defined inside a class.
115
+ * Defines should not be defined inside a class.
116
+ * Classes should not inherit between namespaces.
117
+ * Required parameters in class & defined type definitions should be listed
118
+ before optional parameters.
119
+ * When using top-scope variables, including facts, Puppet modules should
120
+ explicitly specify the empty namespace.
121
+
122
+ ## Disabling checks
123
+
124
+ ### puppet-lint
125
+
126
+ You can disable any of the checks when running the `puppet-lint` command by
127
+ adding a `--no-<check name>-check` flag to the command. For example, if you
128
+ wanted to skip the 80 character check, you would run
129
+
130
+ ```
131
+ puppet-lint --no-80chars-check /path/to/my/manifest.pp
132
+ ```
133
+
134
+ puppet-lint will also check for a `.puppet-lint.rc` file in the current
135
+ directory and your home directory and read in flags from there, so if you
136
+ wanted to always skip the hard tab character check, you could create
137
+ `~/.puppet-lint.rc` containing
138
+
139
+ ```
140
+ --no-hard_tabs-check
141
+ ```
142
+
143
+ For a list of all the flags just type:
144
+
145
+ ```
146
+ puppet-lint --help
147
+ ```
148
+
149
+ ### Rake task
150
+
151
+ You can also disable checks when running puppet-lint through the supplied Rake
152
+ task. Simply add the following line after the `require` statement in your
153
+ `Rakefile`.
154
+
155
+ ``` ruby
156
+ PuppetLint.configuration.send("disable_<check name>")
157
+ ```
158
+
159
+ So, to disable the 80 character check, you would add:
160
+
161
+ ``` ruby
162
+ PuppetLint.configuration.send("disable_80chars")
163
+ ```
164
+
165
+ The Rake task also supports ignoring certain paths
166
+ from being linted:
167
+
168
+ ``` ruby
169
+ PuppetLint.configuration.ignore_paths = ["vendor/**/*.pp"]
170
+ ```
171
+
172
+ ## Reporting bugs or incorrect results
173
+
174
+ If you find a bug in puppet-lint or its results, please create an issue in the
175
+ [repo issues tracker](https://github.com/rodjek/puppet-lint/issues/). Bonus
176
+ points will be awarded if you also include a patch that fixes the issue.
177
+
178
+ ## Thank You
179
+
180
+ Many thanks to the following people for contributing to puppet-lint
181
+
182
+ * James Turnbull (@kartar)
183
+ * Jan Vansteenkiste (@vStone)
184
+ * Julian Simpson (@simpsonjulian)
185
+ * S. Zachariah Sprackett (@zsprackett)
186
+
187
+ As well as the many people who have reported the issues they've had!
188
+
189
+ ## License
190
+
191
+ Copyright (c) 2011 Tim Sharpe
192
+
193
+ Permission is hereby granted, free of charge, to any person obtaining
194
+ a copy of this software and associated documentation files (the
195
+ "Software"), to deal in the Software without restriction, including
196
+ without limitation the rights to use, copy, modify, merge, publish,
197
+ distribute, sublicense, and/or sell copies of the Software, and to
198
+ permit persons to whom the Software is furnished to do so, subject to
199
+ the following conditions:
200
+
201
+ The above copyright notice and this permission notice shall be
202
+ included in all copies or substantial portions of the Software.
203
+
204
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
205
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
206
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
207
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
208
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
209
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
210
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ desc 'Run tests'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ desc 'Run Rubocop on the gem'
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
10
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
11
+ task.fail_on_error = true
12
+ end
13
+
14
+ task default: [:spec, :build, :install]
data/bin/puppet-lint ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ require 'puppet-lint'
6
+
7
+ exit PuppetLint::Bin.new(ARGV).run
@@ -0,0 +1,214 @@
1
+ require 'set'
2
+ require 'puppet-lint/version'
3
+ require 'puppet-lint/lexer'
4
+ require 'puppet-lint/configuration'
5
+ require 'puppet-lint/data'
6
+ require 'puppet-lint/checks'
7
+ require 'puppet-lint/bin'
8
+ require 'puppet-lint/monkeypatches'
9
+
10
+ class PuppetLint::NoCodeError < StandardError; end
11
+ class PuppetLint::NoFix < StandardError; end
12
+
13
+ # Public: The public interface to puppet-lint.
14
+ class PuppetLint
15
+ # Public: Gets/Sets the String manifest code to be checked.
16
+ attr_accessor :code
17
+
18
+ # Public: Gets the String manifest with the errors fixed.
19
+ attr_reader :manifest
20
+
21
+ # Public: Returns an Array of Hashes describing the problems found in the
22
+ # manifest.
23
+ #
24
+ # Each Hash will contain *at least*:
25
+ # :check - The Symbol name of the check that generated the problem.
26
+ # :kind - The Symbol kind of the problem (:error, :warning, or
27
+ # :fixed).
28
+ # :line - The Integer line number of the location of the problem in
29
+ # the manifest.
30
+ # :column - The Integer column number of the location of the problem in
31
+ # the manifest.
32
+ # :message - The String message describing the problem that was found.
33
+ attr_reader :problems
34
+
35
+ # Public: Gets/Sets the String path to the manifest to be checked.
36
+ attr_accessor :path
37
+
38
+ # Public: Returns a Hash of linter statistics
39
+ #
40
+ # :error - An Integer count of errors found in the manifest.
41
+ # :warning - An Integer count of warnings found in the manifest.
42
+ # :fixed - An Integer count of problems found in the manifest that were
43
+ # automatically fixed.
44
+ attr_reader :statistics
45
+
46
+ # Public: Initialise a new PuppetLint object.
47
+ def initialize
48
+ @code = nil
49
+ @statistics = {:error => 0, :warning => 0, :fixed => 0, :ignored => 0}
50
+ @manifest = ''
51
+ end
52
+
53
+ # Public: Access PuppetLint's configuration from outside the class.
54
+ #
55
+ # Returns a PuppetLint::Configuration object.
56
+ def self.configuration
57
+ @configuration ||= PuppetLint::Configuration.new
58
+ end
59
+
60
+ # Public: Access PuppetLint's configuration from inside the class.
61
+ #
62
+ # Returns a PuppetLint::Configuration object.
63
+ def configuration
64
+ self.class.configuration
65
+ end
66
+
67
+ # Public: Set the path of the manifest file to be tested and read the
68
+ # contents of the file.
69
+ #
70
+ # Returns nothing.
71
+ def file=(path)
72
+ if File.exist? path
73
+ @path = path
74
+ @code = File.read(path)
75
+ end
76
+ end
77
+
78
+ # Internal: Retrieve the format string to be used when writing problems to
79
+ # STDOUT. If the user has not specified a custom log format, build one for
80
+ # them.
81
+ #
82
+ # Returns a format String to be used with String#%.
83
+ def log_format
84
+ if configuration.log_format == ''
85
+ ## recreate previous old log format as far as thats possible.
86
+ format = '%{KIND}: %{message} on line %{line}'
87
+ if configuration.with_filename
88
+ format.prepend '%{path} - '
89
+ end
90
+ configuration.log_format = format
91
+ end
92
+ return configuration.log_format
93
+ end
94
+
95
+ # Internal: Format a problem message and print it to STDOUT.
96
+ #
97
+ # message - A Hash containing all the information about a problem.
98
+ #
99
+ # Returns nothing.
100
+ def format_message(message)
101
+ format = log_format
102
+ puts format % message
103
+ if message[:kind] == :ignored && !message[:reason].nil?
104
+ puts " #{message[:reason]}"
105
+ end
106
+ end
107
+
108
+ # Internal: Print out the line of the manifest on which the problem was found
109
+ # as well as a marker pointing to the location on the line.
110
+ #
111
+ # message - A Hash containing all the information about a problem.
112
+ #
113
+ # Returns nothing.
114
+ def print_context(message)
115
+ return if message[:check] == 'documentation'
116
+ return if message[:kind] == :fixed
117
+ line = PuppetLint::Data.manifest_lines[message[:line] - 1]
118
+ offset = line.index(/\S/) || 1
119
+ puts "\n #{line.strip}"
120
+ printf "%#{message[:column] + 2 - offset}s\n\n", '^'
121
+ end
122
+
123
+ # Internal: Print the reported problems with a manifest to stdout.
124
+ #
125
+ # problems - An Array of problem Hashes as returned by
126
+ # PuppetLint::Checks#run.
127
+ #
128
+ # Returns nothing.
129
+ def report(problems)
130
+ problems.each do |message|
131
+ next if message[:kind] == :ignored && !PuppetLint.configuration.show_ignored
132
+
133
+ message[:KIND] = message[:kind].to_s.upcase
134
+ message[:linenumber] = message[:line]
135
+
136
+ if message[:kind] == :fixed || [message[:kind], :all].include?(configuration.error_level)
137
+ format_message message
138
+ print_context(message) if configuration.with_context
139
+ end
140
+ end
141
+ end
142
+
143
+ # Public: Determine if PuppetLint found any errors in the manifest.
144
+ #
145
+ # Returns true if errors were found, otherwise returns false.
146
+ def errors?
147
+ @statistics[:error] != 0
148
+ end
149
+
150
+ # Public: Determine if PuppetLint found any warnings in the manifest.
151
+ #
152
+ # Returns true if warnings were found, otherwise returns false.
153
+ def warnings?
154
+ @statistics[:warning] != 0
155
+ end
156
+
157
+ # Public: Run the loaded manifest code through the lint checks and print the
158
+ # results of the checks to stdout.
159
+ #
160
+ # Returns nothing.
161
+ # Raises PuppetLint::NoCodeError if no manifest code has been loaded.
162
+ def run
163
+ if @code.nil?
164
+ raise PuppetLint::NoCodeError
165
+ end
166
+
167
+ if @code.empty?
168
+ @problems = []
169
+ @manifest = []
170
+ return
171
+ end
172
+
173
+ linter = PuppetLint::Checks.new
174
+ @problems = linter.run(@path, @code)
175
+ @problems.each { |problem| @statistics[problem[:kind]] += 1 }
176
+
177
+ @manifest = linter.manifest if PuppetLint.configuration.fix
178
+ end
179
+
180
+ # Public: Print any problems that were found out to stdout.
181
+ #
182
+ # Returns nothing.
183
+ def print_problems
184
+ report @problems
185
+ end
186
+
187
+ # Public: Define a new check.
188
+ #
189
+ # name - A unique name for the check as a Symbol.
190
+ # block - The check logic. This must contain a `check` method and optionally
191
+ # a `fix` method.
192
+ #
193
+ # Returns nothing.
194
+ #
195
+ # Examples
196
+ #
197
+ # PuppetLint.new_check(:foo) do
198
+ # def check
199
+ # end
200
+ # end
201
+ def self.new_check(name, &block)
202
+ class_name = name.to_s.split('_').map(&:capitalize).join
203
+ klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
204
+ klass.const_set('NAME', name)
205
+ klass.class_exec(&block)
206
+ PuppetLint.configuration.add_check(name, klass)
207
+ PuppetLint::Data.ignore_overrides[name] ||= {}
208
+ end
209
+ end
210
+
211
+ # Default configuration options
212
+ PuppetLint.configuration.defaults
213
+
214
+ require 'puppet-lint/plugins'