puppet-check 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2ce83eaa817c69d2ca4cd5219571bc0af2d0e125
4
- data.tar.gz: 34afb49f0e47a20d75417dd11d5f2d277192394b
3
+ metadata.gz: 5eed739fa10d5c5223812d0e88edf139d4c5e0e7
4
+ data.tar.gz: b6cc39fa5d43da1a090ca7be86315876285d94b7
5
5
  SHA512:
6
- metadata.gz: 1d5e0aae72d0fd85ac9332c2abbccb16d5000c458677ade54adac994a343037301f7abc123245a582ecbd1b151cd52f633264d43d1fe815895fa4f0af58ed602
7
- data.tar.gz: 3ea14379bdcd682feedbdf10a82c2939f175832c2794ebc9fb81d0e673703d8f354c63664a4cbc6ce31380829a306424033e1190b0489e29ac58581e17796d46
6
+ metadata.gz: c259d0803a2fae163241ef523e6c326b402be1d7363929adf857db87b2fc82b1f9af5dbe673a4eaf6ce0fee6ec4b3464f0931f5e000e97e3fa3e15fef913f926
7
+ data.tar.gz: 3159e4d695987cd9f4ccde352bb69a965fedc3204fdf7fbced757b93f9c777f49ef9408fc8189d71aebd78bbf7f9490c6a0382b43aec1b9a36c80186f1dae7ed
data/CHANGELOG.md CHANGED
@@ -1,18 +1,18 @@
1
1
  ### 1.4.0 (Roadmap)
2
- - rudimentary catalog compilation testing? (only for Puppet4)
3
- - minimum Puppet version increased from 3.4 to 3.7.
4
- - rakefile interface with puppet-lint, rubocop, reek
5
- - rspec puppet stubbing
6
- - infrataster and analogous docker task like thing ripienaar did?
7
- - some multithreading for speedup
2
+ - optional dep octocatalog-diff interface (minor)
3
+ - minimum Puppet version increased from 3.4 to 3.7 (minor)
4
+ - rakefile interface with puppet-lint, rubocop, reek (minor)
5
+ - rspec puppet stubbing (minor)
6
+ - acceptance testing with vagrant/docker+serverspec (minor)
7
+ - improved json and yaml output formats support (file arrays become file hashes and output results further handles formatting) (minor; this would be a big refactoring effort)
8
+ - split syntax and style checks to separate methods for style (patch)
9
+ - add additional hiera checks (patch)
8
10
 
9
- ### 1.3.1 (Roadmap)
10
- - split syntax and style checks to separate methods for speedup
11
- - more args, fewer self accessors
12
- - improved json and yaml output formats support (file arrays become file hashes and output results further handles formatting)
13
- - metadata.json checks for dependency upper bounds, dependencies/operatingsystem_support as array of hashes, and operatingsystem and operatingsystem_release within operatingsystem_support
14
- - do another reek and rubocop check
15
- - add additional hiera checks
11
+ ### 1.3.1
12
+ - For the git and mercurial methods of downloading external module dependencies as spec fixtures, the module is now updated if it is already present and previously retrieved with git or mercurial respectively. Previously, a fresh clone was always attempted.
13
+ - Additional syntax and style checks within the `operatingsystem_support`, `requirements`, and `dependencies` hashes in `metadata.json`.
14
+ - Reek is now required dependency for all Ruby versions and locked to 3.11 for Ruby 2.0.
15
+ - Slight code cleanup and optimization.
16
16
 
17
17
  ### 1.3.0
18
18
  - Minimum Ruby version increased from 1.9.3 to 2.0.0.
@@ -21,7 +21,7 @@
21
21
  - Support for outputting the results in YAML or JSON formats.
22
22
  - Additional style check for `metadata.json`.
23
23
  - Slight code cleanup and optimization.
24
- - Block hieradata checks from excuting on `hiera.yaml`.
24
+ - Block hieradata checks from executing on `hiera.yaml`.
25
25
 
26
26
  ### 1.2.1
27
27
  - Code and output cleanup.
data/README.md CHANGED
@@ -6,6 +6,7 @@
6
6
  - [CLI](#cli)
7
7
  - [Rake](#rake)
8
8
  - [Docker](#docker)
9
+ - [Vagrant](#vagrant)
9
10
  - [Exit Codes](#exit-codes)
10
11
  - [Optional Dependencies](#optional-dependencies)
11
12
  - [Contributing](#contributing)
@@ -112,14 +113,19 @@ The following files have unrecognized formats and therefore were not processed:
112
113
  - Puppetlabs Spec Helper has no CLI.
113
114
  - Puppetlabs Spec Helper intrinsically only executes spec tests against one module at a time.
114
115
  - Puppetlabs Spec Helper requires an additional config file for RSpec Puppet support.
116
+ - Puppetlabs Spec Helper does not update external module dependencies in a stateful/persistent workspace and fails gracefully instead.
117
+ - Puppetlabs Spec Helper requires extra configuration items to setup self-module RSpec testing.
115
118
 
116
119
  It is worth nothing that there is no current development objective for Puppet Check to achieve the same advanced level of robustness for spec testing that Puppetlabs Spec Helper enables. If you are performing standard spec testing on your Puppet code and data, then Puppet Check's spec testing is a fantastic lightweight and faster alternative to Puppetlabs Spec Helper. If you require advanced and intricate capabilities in your spec testing (e.g. direct interfacing to the `Puppet::Parser::Scope` API), then you will likely prefer Puppetlabs Spec Helper's spec testing in conjunction with Puppet Check's file validation.
117
120
 
118
121
  ## Usage
119
122
  Puppet Check requires `ruby >= 2.0.0`, `puppet >= 3.4`, and `puppet-lint >= 2.0.0`. All other dependencies should be fine with various versions. Puppet Check can be used either with a CLI or Rake tasks. Please note both interfaces will ignore any directories named `fixtures` or specified paths with that directory during file checks and spec tests.
120
123
 
124
+ #### Reek
125
+ Reek dropped support for Ruby 2.0 when it went to 4.0. Since dependencies by Ruby version are allowed in Gemfiles but not gemspecs, this means that PuppetCheck installed with `bundler` will automatically pick up the correct version of Reek for your Ruby version and install it. If you are installing PuppetCheck via `gem`, then you can install reek normally with `gem` with Ruby >= 2.1, but you will need to specify `gem install reek -v 3.11` if you are using Ruby 2.0.
126
+
121
127
  #### Important Note for Ruby 1.9.3 and PuppetCheck <= 1.2.1
122
- If you are using Ruby 1.9.3, there is an issue where `Hiera <= 3.2.0` has an unspecified version dependency on JSonPure. Since JSonPure 2.0.2 requires `ruby >= 2.0.0`, this breaks Hiera installs on Ruby 1.9.3, which breaks Puppet installs, which breaks PuppetCheck installs. Therefore, you will need to either restrict your installed version of JSonPure to something lower than 2.0.2 if you are using Ruby 1.9.3, or use `Hiera >= 3.2.1`.
128
+ If you are using Ruby 1.9.3 (and therefore also PuppetCheck <= 1.2.1), there is an issue where `Hiera <= 3.2.0` has an unspecified version dependency on JSonPure. Since JSonPure 2.0.2 requires `ruby >= 2.0.0`, this breaks Hiera installs on Ruby 1.9.3, which breaks Puppet installs, which breaks PuppetCheck installs. Therefore, you will need to either restrict your installed version of JSonPure to something lower than 2.0.2 if you are using Ruby 1.9.3, or use `Hiera >= 3.2.1`.
123
129
 
124
130
  ### CLI
125
131
  ```
@@ -137,7 +143,7 @@ The command line interface enables the ability to select the Puppet future parse
137
143
 
138
144
  Example:
139
145
  ```
140
- puppet-check -s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Metrics/LineLength,Style/Encoding path/to/code_and_data
146
+ puppet-check -s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Metrics/LineLength,Style/Encoding -o yaml path/to/code_and_data
141
147
  ```
142
148
 
143
149
  ### Rake
@@ -156,7 +162,7 @@ You can add style checks to and select the future parser for the `rake puppetche
156
162
  ```ruby
157
163
  PuppetCheck.style_check = true
158
164
  PuppetCheck.future_parser = true
159
- PuppetCheck.output_format = yaml
165
+ PuppetCheck.output_format = 'yaml'
160
166
  ```
161
167
 
162
168
  Please note that `rspec` does not support yaml output and therefore would still use the default 'progress' formatter even if `yaml` is specified as the format option to Puppet Check.
@@ -208,6 +214,8 @@ Example:
208
214
  ]
209
215
  ```
210
216
 
217
+ Note that `args` will be ignored during `git pull` and `hg pull/hg update` when the modules are updated instead of freshly cloned.
218
+
211
219
  #### puppetcheck:beaker
212
220
  The spec tests will be executed against everything that matches the pattern `**/acceptance`. Any of these directories inside of a `fixtures` directory will be ignored. This means everything in the current path that appears to be a Puppet module acceptance test for your module (not dependencies) will be regarded as such and executed during this rake task.
213
221
 
@@ -236,15 +244,40 @@ ENTRYPOINT ["rake", "puppetcheck"]
236
244
 
237
245
  You can also build your own general container for testing various Puppet situations by removing the last three lines. You can then test each module, directory environment, etc. on top of that container by merely adding and modifying the final three lines to a Dockerfile that uses the container you built from the first four lines. This is recommended usage due to being very efficient and stable.
238
246
 
247
+ ### Vagrant
248
+
249
+ As an alternative to Docker, you can also use Vagrant for quick and disposable testing, but it is not as portable as Docker for these testing purposes. Below is an example Vagrantfile for this purpose.
250
+
251
+ ```ruby
252
+ Vagrant.configure(2) do |config|
253
+ # a reliable and small box at the moment
254
+ config.vm.box = 'fedora/23'
255
+
256
+ config.vm.provision 'shell', inline: <<-SHELL
257
+ # cd to 'sync' if this is recent Vagrant; cd to '/vagrant' if this is older Vagrant
258
+ cd sync || cd /vagrant
259
+ # you need ruby and any other extra dependencies that come from packages; in this example we install git to use it for downloading external module dependencies
260
+ sudo dnf install ruby rubygems git -y
261
+ # you need puppet-check and any other extra dependencies that come from gems; in this example we install reek because the ruby ABI is 2.2 and then rspec-puppet and rake for extra testing
262
+ sudo gem install --no-rdoc --no-ri puppet-check reek rspec-puppet rake
263
+ # this is needed for the ruby json parser to not flip out on fresh os installs for some reason (change encoding value as necessary)
264
+ export LANG='en_US.UTF-8'
265
+ # execute your tests; in this example we are executing the full suite of tests
266
+ rake puppetcheck
267
+ SHELL
268
+ end
269
+ ```
270
+
271
+ To overcome the lack of convenient portability, you could try spinning up the Vagrant instance at the top level of your Puppet code and data and then descend into directories to execute tests as necessary. Cleverness or patience will be necessary if you decide to use Vagrant for testing and desire portability.
272
+
239
273
  ### Exit Codes
240
274
  - 0: PuppetCheck exited with no internal exceptions or errors in your Puppet code and data.
241
275
  - 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes) or failed spec test.
242
276
  - 2: PuppetCheck exited with one or more errors in your Puppet code and data.
243
277
 
244
278
  ### Optional dependencies
245
- - **reek**: will automatically (with `bundler`, otherwise manually) be installed as a dependency and checks enabled during style checks if your Ruby version is `>= 2.1.0`.
246
279
  - **rake**: install this if you want to use Puppet Check with `rake` tasks in addition to the CLI.
247
- - **rspec**: install this if you want to use Puppet Check to execute the spec tests for your ruby files during `rake`.
280
+ - **rspec**: install this if you want to use Puppet Check to execute the spec tests for your Ruby files during `rake`.
248
281
  - **rspec-puppet**: install this if you want to use Puppet Check to execute the spec tests for your Puppet files during `rake`.
249
282
  - **beaker**: install this if you want to use Puppet Check to execute the acceptance tests during `rake`.
250
283
  - **git**: install this if you want to use Puppet Check to download external module dependencies with `git` commands during RSpec Puppet testing.
@@ -21,7 +21,7 @@ class PuppetCheck::CLI
21
21
 
22
22
  # base options
23
23
  opts.on('--version', 'Display the current version.') do
24
- puts 'puppet-check 1.3.0'
24
+ puts 'puppet-check 1.3.1'
25
25
  exit 0
26
26
  end
27
27
 
@@ -50,9 +50,11 @@ class DataParser
50
50
  errors.push("Required field '#{key}' not found.") unless parsed.key?(key)
51
51
  end
52
52
 
53
- # check for duplicate dependencies and requirements
53
+ # check for duplicate dependencies and requirements, and that both are an array of hashes if they exist
54
54
  %w(requirements dependencies).each do |key|
55
55
  next unless parsed.key?(key)
56
+ next errors.push("Field '#{key}' is not an array of hashes.") unless (parsed[key].is_a? Array) && (parsed[key].empty? || (parsed[key][0].is_a? Hash))
57
+
56
58
  names = []
57
59
  parsed[key].each do |req_dep|
58
60
  name = req_dep['name']
@@ -72,8 +74,37 @@ class DataParser
72
74
  next PuppetCheck.error_files.push("#{file}:\n#{errors.join("\n")}") unless errors.empty?
73
75
 
74
76
  # check for warnings
75
- # check for operatingsystem_support
76
- warnings.push('Recommended field \'operatingsystem_support\' not found.') unless parsed.key?('operatingsystem_support')
77
+ # check for operatingsystem_support hash array
78
+ if parsed.key?('operatingsystem_support')
79
+ # check if operatingsystem_support array is actually empty
80
+ if !(parsed['operatingsystem_support'].is_a? Array) || parsed['operatingsystem_support'].empty? || (!parsed['operatingsystem_support'].empty? && !(parsed['operatingsystem_support'][0].is_a? Hash))
81
+ warnings.push('Recommended field \'operatingsystem\' not found.')
82
+ warnings.push('Recommended field \'operatingsystemrelease\' not found.')
83
+ else
84
+ # check for operatingsystem string
85
+ if parsed['operatingsystem_support'][0].key?('operatingsystem')
86
+ warnings.push('Field \'operatingsystem\' is not a string.') unless parsed['operatingsystem_support'][0]['operatingsystem'].is_a? String
87
+ else
88
+ warnings.push('Recommended field \'operatingsystem\' not found.')
89
+ end
90
+ # check for operatingsystemrelease string array
91
+ if parsed['operatingsystem_support'][0].key?('operatingsystemrelease')
92
+ warnings.push('Field \'operatingsystemrelease\' is not a string array.') unless parsed['operatingsystem_support'][0]['operatingsystemrelease'][0].is_a? String
93
+ else
94
+ warnings.push('Recommended field \'operatingsystemrelease\' not found.')
95
+ end
96
+ end
97
+ else
98
+ warnings.push('Recommended field \'operatingsystem_support\' not found.')
99
+ end
100
+
101
+ # check for requirement and dependency upper bounds
102
+ %w(requirements dependencies).each do |key|
103
+ next if parsed[key].empty?
104
+ parsed[key].each do |req_dep|
105
+ warnings.push("'#{req_dep['name']}' is missing an upper bound.") unless req_dep['version_requirement'].include?('<')
106
+ end
107
+ end
77
108
 
78
109
  # check for spdx license (rubygems/util/licenses for rubygems >= 2.5 in the far future)
79
110
  if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
@@ -16,17 +16,13 @@ class OutputResults
16
16
  print "\n\033[32mThe following files have no errors or warnings:\033[0m\n-- "
17
17
  puts PuppetCheck.clean_files.join("\n-- ")
18
18
  end
19
- unless PuppetCheck.ignored_files.empty?
20
- print "\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- "
21
- puts PuppetCheck.ignored_files.join("\n-- ")
22
- end
19
+ return if PuppetCheck.ignored_files.empty?
20
+ print "\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- "
21
+ puts PuppetCheck.ignored_files.join("\n-- ")
23
22
  end
24
23
 
25
24
  # output the results as yaml or json
26
25
  def self.markup
27
- require 'yaml'
28
- require 'json'
29
-
30
26
  # generate output hash
31
27
  hash = {}
32
28
  hash['errors'] = PuppetCheck.error_files unless PuppetCheck.error_files.empty?
@@ -36,8 +32,10 @@ class OutputResults
36
32
 
37
33
  # convert hash to markup language
38
34
  if PuppetCheck.output_format == 'yaml'
35
+ require 'yaml'
39
36
  puts Psych.dump(hash, indentation: 2)
40
37
  elsif PuppetCheck.output_format == 'json'
38
+ require 'json'
41
39
  puts JSON.pretty_generate(hash)
42
40
  else
43
41
  raise "puppet-check: Unsupported output format '#{PuppetCheck.output_format}' was specified."
@@ -4,12 +4,12 @@ require_relative '../puppet-check'
4
4
  # executes diagnostics on puppet files
5
5
  class PuppetParser
6
6
  # checks puppet (.pp)
7
- def self.manifest(files)
7
+ def self.manifest(files, future, style, pl_args)
8
8
  require 'puppet/face'
9
9
 
10
10
  # prepare the Puppet settings for the error checking
11
11
  Puppet.initialize_settings unless Puppet.settings.app_defaults_initialized?
12
- Puppet[:parser] = 'future' if PuppetCheck.future_parser && (Puppet::PUPPETVERSION.to_i < 4)
12
+ Puppet[:parser] = 'future' if future && (Puppet::PUPPETVERSION.to_i < 4)
13
13
 
14
14
  files.each do |file|
15
15
  # setup error logging and collection
@@ -29,15 +29,15 @@ class PuppetParser
29
29
  Puppet::Util::Log.close_all
30
30
 
31
31
  # check puppet style
32
- if PuppetCheck.style_check
32
+ if style
33
33
  require 'puppet-lint'
34
34
  require 'puppet-lint/optparser'
35
35
 
36
36
  # check for invalid arguments to PuppetLint
37
37
  begin
38
- PuppetLint::OptParser.build.parse!(PuppetCheck.puppetlint_args.clone)
38
+ PuppetLint::OptParser.build.parse!(pl_args.clone)
39
39
  rescue OptionParser::InvalidOption
40
- raise "puppet-lint: invalid option supplied among #{PuppetCheck.puppetlint_args.join(' ')}"
40
+ raise "puppet-lint: invalid option supplied among #{pl_args.join(' ')}"
41
41
  end
42
42
 
43
43
  # prepare the PuppetLint object for style checks
@@ -61,7 +61,7 @@ class PuppetParser
61
61
 
62
62
  files.each do |file|
63
63
  # puppet before version 4 cannot check template syntax
64
- next PuppetCheck.ignored_files.push("#{file}: ignored due to Puppet < 4.0.0") if Puppet::PUPPETVERSION.to_i < 4
64
+ next PuppetCheck.ignored_files.push("#{file}: ignored due to Puppet < 4") if Puppet::PUPPETVERSION.to_i < 4
65
65
 
66
66
  # check puppet template syntax
67
67
  begin
@@ -4,6 +4,7 @@ class RSpecPuppetSupport
4
4
  # 'puppetcheck:spec' task invokes 'run'
5
5
  # 'run' invokes 'file_setup' always and 'dependency_setup' if metadata.json exists
6
6
  # 'dependency_setup' invokes 'git/forge/hg' if dependencies exist and git/forge/hg is download option
7
+ # 'git/forge/hg' downloads module fixture appropriately
7
8
 
8
9
  # prepare the spec fixtures directory for rspec-puppet testing
9
10
  def self.run
@@ -43,9 +44,8 @@ class RSpecPuppetSupport
43
44
  end
44
45
 
45
46
  # create spec_helper if missing
46
- unless File.file?('spec/spec_helper.rb')
47
- File.open('spec/spec_helper.rb', 'w') { |file| file.puts "require 'rspec-puppet/spec_helper'\n" }
48
- end
47
+ return if File.file?('spec/spec_helper.rb')
48
+ File.open('spec/spec_helper.rb', 'w') { |file| file.puts "require 'rspec-puppet/spec_helper'\n" }
49
49
  end
50
50
 
51
51
  # setup the module dependencies for rspec-puppet testing
@@ -56,25 +56,27 @@ class RSpecPuppetSupport
56
56
  parsed = JSON.parse(File.read('metadata.json'))
57
57
 
58
58
  # grab dependencies if they exist
59
- unless parsed['dependencies'].empty?
60
- parsed['dependencies'].each do |dependency_hash|
61
- # determine how the user wants to download the module dependency
62
- if dependency_hash.key?('git')
63
- git(dependency_hash['git'], dependency_hash['args'])
64
- elsif dependency_hash.key?('forge')
65
- forge(dependency_hash['forge'], dependency_hash['args'])
66
- elsif dependency_hash.key?('hg')
67
- hg(dependency_hash['hg'], dependency_hash['args'])
68
- else
69
- warn "#{dependency_hash['name']} has an unspecified, or specified but unsupported, download method."
70
- end
59
+ return if parsed['dependencies'].empty?
60
+ parsed['dependencies'].each do |dependency_hash|
61
+ # determine how the user wants to download the module dependency
62
+ if dependency_hash.key?('git')
63
+ git(dependency_hash['git'], dependency_hash['args'])
64
+ elsif dependency_hash.key?('forge')
65
+ forge(dependency_hash['forge'], dependency_hash['args'])
66
+ elsif dependency_hash.key?('hg')
67
+ hg(dependency_hash['hg'], dependency_hash['args'])
68
+ else
69
+ warn "#{dependency_hash['name']} has an unspecified, or specified but unsupported, download method."
71
70
  end
72
71
  end
73
72
  end
74
73
 
75
74
  # download external module dependency with git
76
75
  def self.git(git_url, args = '')
77
- system("git -C spec/fixtures/modules/ clone #{args} #{git_url}")
76
+ # establish path to clone module to
77
+ path = "spec/fixtures/modules/#{File.basename(git_url, '.git')}"
78
+ # is the module present and already cloned with git? do a pull; otherwise, do a clone
79
+ File.directory?("#{path}/.git") ? system("git -C #{path} pull") : system("git clone #{args} #{git_url} #{path}")
78
80
  end
79
81
 
80
82
  # download external module dependency with forge
@@ -84,6 +86,9 @@ class RSpecPuppetSupport
84
86
 
85
87
  # download external module dependency with hg
86
88
  def self.hg(hg_url, args = '')
87
- system("hg --cwd spec/fixtures/modules/ clone #{args} #{hg_url}")
89
+ # establish path to clone module to
90
+ path = "spec/fixtures/modules/#{File.basename(hg_url)}"
91
+ # is the module present and already cloned with hg? do a pull and update; otherwise do a clone
92
+ File.directory?("#{path}/.hg") ? system("hg --cwd #{path} pull; hg --cwd #{path} update") : system("hg clone #{args} #{hg_url} #{path}")
88
93
  end
89
94
  end
@@ -4,7 +4,7 @@ require_relative 'utils'
4
4
  # executes diagnostics on ruby files
5
5
  class RubyParser
6
6
  # checks ruby (.rb)
7
- def self.ruby(files)
7
+ def self.ruby(files, style, rc_args)
8
8
  files.each do |file|
9
9
  # check ruby syntax
10
10
  begin
@@ -14,20 +14,18 @@ class RubyParser
14
14
  PuppetCheck.error_files.push("#{file}:\n#{err}")
15
15
  else
16
16
  # check ruby style
17
- if PuppetCheck.style_check
17
+ if style
18
18
  require 'rubocop'
19
19
 
20
20
  # check RuboCop and collect warnings
21
- rubocop_warnings = Utils.capture_stdout { RuboCop::CLI.new.run(PuppetCheck.rubocop_args + ['--format', 'emacs', file]) }
21
+ rubocop_warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--format', 'emacs', file]) }
22
22
  warnings = rubocop_warnings == '' ? '' : rubocop_warnings.split("#{File.absolute_path(file)}:").join('')
23
23
 
24
24
  # check Reek and collect warnings
25
- if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
26
- require 'reek'
27
- require 'reek/cli/application'
28
- reek_warnings = Utils.capture_stdout { Reek::CLI::Application.new([file]).execute }
29
- warnings += reek_warnings.split("\n")[1..-1].map(&:strip).join("\n") unless reek_warnings == ''
30
- end
25
+ require 'reek'
26
+ require 'reek/cli/application'
27
+ reek_warnings = Utils.capture_stdout { Reek::CLI::Application.new([file]).execute }
28
+ warnings += reek_warnings.split("\n")[1..-1].map(&:strip).join("\n") unless reek_warnings == ''
31
29
 
32
30
  # return warnings
33
31
  next PuppetCheck.warning_files.push("#{file}:\n#{warnings.strip}") unless warnings == ''
@@ -61,7 +59,7 @@ class RubyParser
61
59
  end
62
60
 
63
61
  # checks librarian puppet (Puppetfile/Modulefile) and misc ruby (Rakefile/Gemfile)
64
- def self.librarian(files)
62
+ def self.librarian(files, style, rc_args)
65
63
  files.each do |file|
66
64
  # check librarian puppet syntax
67
65
  begin
@@ -71,14 +69,13 @@ class RubyParser
71
69
  PuppetCheck.error_files.push("#{file}:\n#{err}")
72
70
  # check librarian puppet style
73
71
  else
74
- if PuppetCheck.style_check
72
+ if style
75
73
  require 'rubocop'
76
74
 
77
75
  # check Rubocop
78
- rubocop_args = PuppetCheck.rubocop_args.clone
79
76
  # RuboCop is grumpy about non-snake_case filenames so disable the Style/FileName check
80
- rubocop_args.include?('--except') ? rubocop_args[rubocop_args.index('--except') + 1] = "#{rubocop_args[rubocop_args.index('--except') + 1]},Style/FileName" : rubocop_args.concat(['--except', 'Style/FileName'])
81
- warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rubocop_args + ['--format', 'emacs', file]) }
77
+ rc_args.include?('--except') ? rc_args[rc_args.index('--except') + 1] = "#{rc_args[rc_args.index('--except') + 1]},Style/FileName" : rc_args.concat(['--except', 'Style/FileName'])
78
+ warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--format', 'emacs', file]) }
82
79
 
83
80
  # collect style warnings
84
81
  next PuppetCheck.warning_files.push("#{file}:\n#{warnings.split("#{File.absolute_path(file)}:").join('')}") unless warnings.empty?
data/lib/puppet-check.rb CHANGED
@@ -33,7 +33,7 @@ class PuppetCheck
33
33
  files = self.class.parse_paths(paths)
34
34
 
35
35
  # parse the files
36
- execute_parsers(files)
36
+ execute_parsers(files, self.class.future_parser, self.class.style_check, self.class.puppetlint_args, self.class.rubocop_args)
37
37
 
38
38
  # output the diagnostic results
39
39
  PuppetCheck.output_format == 'text' ? OutputResults.text : OutputResults.markup
@@ -64,12 +64,12 @@ class PuppetCheck
64
64
  end
65
65
 
66
66
  # categorize and pass the files out to the parsers to determine their status
67
- def execute_parsers(files)
68
- PuppetParser.manifest(files.select { |file| File.extname(file) == '.pp' })
67
+ def execute_parsers(files, future, style, pl_args, rc_args)
68
+ PuppetParser.manifest(files.select { |file| File.extname(file) == '.pp' }, future, style, pl_args)
69
69
  files.reject! { |file| File.extname(file) == '.pp' }
70
70
  PuppetParser.template(files.select { |file| File.extname(file) == '.epp' })
71
71
  files.reject! { |file| File.extname(file) == '.epp' }
72
- RubyParser.ruby(files.select { |file| File.extname(file) == '.rb' })
72
+ RubyParser.ruby(files.select { |file| File.extname(file) == '.rb' }, style, rc_args)
73
73
  files.reject! { |file| File.extname(file) == '.rb' }
74
74
  RubyParser.template(files.select { |file| File.extname(file) == '.erb' })
75
75
  files.reject! { |file| File.extname(file) == '.erb' }
@@ -77,7 +77,7 @@ class PuppetCheck
77
77
  files.reject! { |file| File.extname(file) =~ /\.ya?ml$/ }
78
78
  DataParser.json(files.select { |file| File.extname(file) == '.json' })
79
79
  files.reject! { |file| File.extname(file) == '.json' }
80
- RubyParser.librarian(files.select { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ })
80
+ RubyParser.librarian(files.select { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }, style, rc_args)
81
81
  files.reject! { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
82
82
  files.each { |file| self.class.ignored_files.push(file.to_s) }
83
83
  end
@@ -29,7 +29,5 @@
29
29
  }
30
30
  ],
31
31
  "description": "Standard Library for Puppet Modules",
32
- "dependencies": [
33
-
34
- ]
32
+ "dependencies": []
35
33
  }
@@ -10,7 +10,7 @@
10
10
  "requirements": [
11
11
  {
12
12
  "name": "pe",
13
- "version_requirement": ">= 3.0.0 < 2015.4.0"
13
+ "version_requirement": ">= 3.0.0"
14
14
  },
15
15
  {
16
16
  "name": "puppet",
@@ -18,7 +18,5 @@
18
18
  }
19
19
  ],
20
20
  "description": "Standard Library for Puppet Modules",
21
- "dependencies": [
22
-
23
- ]
21
+ "dependencies": []
24
22
  }
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "puppetlabs-stdlib",
3
+ "version": "4.11.0",
4
+ "author": "puppetlabs",
5
+ "summary": "Standard library of resources for Puppet modules.",
6
+ "license": "Apache-2.0",
7
+ "source": "https://github.com/puppetlabs/puppetlabs-stdlib",
8
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
9
+ "issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
10
+ "operatingsystem_support": [],
11
+ "requirements": [
12
+ {
13
+ "name": "pe",
14
+ "version_requirement": ">= 3.0.0 < 2016.4"
15
+ },
16
+ {
17
+ "name": "puppet",
18
+ "version_requirement": ">=2.7.20 <5.0.0"
19
+ }
20
+ ],
21
+ "description": "Standard Library for Puppet Modules",
22
+ "dependencies": [
23
+ { "name": "puppetlabs/one", "version_requirement": ">= 3.2.0 < 5.0.0" },
24
+ { "name": "puppetlabs/two", "version_requirement": ">= 0.0.4" }
25
+ ]
26
+ }
@@ -11,5 +11,6 @@
11
11
  {"name": "puppetlabs/nothing", "version_requirement": ">=1.1.1 < 2.2.2"},
12
12
  {"name": "puppetlabs/nothing", "version_requirement": ">=1.1.1 < 2.2.2"}
13
13
  ],
14
+ "requirements": ["not an array of hashes"],
14
15
  "checksum": "foo"
15
16
  }
@@ -38,14 +38,20 @@ describe DataParser do
38
38
  end
39
39
  it 'puts a bad metadata json file in the error files array' do
40
40
  DataParser.json([fixtures_dir + 'metadata_syntax/metadata.json'])
41
- expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}metadata_syntax/metadata.json:\nRequired field.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds})
41
+ expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}metadata_syntax/metadata.json:\nRequired field.*\nField 'requirements'.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds})
42
42
  expect(PuppetCheck.warning_files).to eql([])
43
43
  expect(PuppetCheck.clean_files).to eql([])
44
44
  end
45
45
  it 'puts a bad style metadata json file in the warning files array' do
46
46
  DataParser.json([fixtures_dir + 'metadata_style/metadata.json'])
47
47
  expect(PuppetCheck.error_files).to eql([])
48
- expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}metadata_style/metadata.json:\n.*operatingsystem_support.*\nLicense identifier})
48
+ expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}metadata_style/metadata.json:\n.*operatingsystem_support.*\n'pe' is missing an upper bound.\nLicense identifier})
49
+ expect(PuppetCheck.clean_files).to eql([])
50
+ end
51
+ it 'puts another bad style metadata json file in the warning files array' do
52
+ DataParser.json([fixtures_dir + 'metadata_style_two/metadata.json'])
53
+ expect(PuppetCheck.error_files).to eql([])
54
+ expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}metadata_style_two/metadata.json:\n.*operatingsystem.*\n.*operatingsystemrelease.*\n'puppetlabs/two' is missing an upper bound})
49
55
  expect(PuppetCheck.clean_files).to eql([])
50
56
  end
51
57
  it 'puts a good json file in the clean files array' do
@@ -6,52 +6,42 @@ describe PuppetParser do
6
6
  PuppetCheck.error_files = []
7
7
  PuppetCheck.warning_files = []
8
8
  PuppetCheck.clean_files = []
9
- PuppetCheck.future_parser = false
10
- PuppetCheck.style_check = false
11
- PuppetCheck.puppetlint_args = []
12
9
  end
13
10
 
14
11
  context '.manifest' do
15
12
  it 'puts a bad syntax Puppet manifest in the error files array' do
16
- PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'])
13
+ PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'], false, false, [])
17
14
  # expect(subject.instance_variable_get(:@error_files)[0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:.*syntax error})
18
15
  expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
19
16
  expect(PuppetCheck.warning_files).to eql([])
20
17
  expect(PuppetCheck.clean_files).to eql([])
21
18
  end
22
19
  it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
23
- PuppetCheck.style_check = true
24
- PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'])
20
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'], false, true, [])
25
21
  expect(PuppetCheck.error_files).to eql([])
26
22
  expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}manifests/style_parser.pp:\nUnrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing})
27
23
  expect(PuppetCheck.clean_files).to eql([])
28
24
  end
29
25
  it 'puts a bad lint style Puppet manifest in the warning files array' do
30
- PuppetCheck.style_check = true
31
- PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'])
26
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, [])
32
27
  expect(PuppetCheck.error_files).to eql([])
33
28
  expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
34
29
  expect(PuppetCheck.clean_files).to eql([])
35
30
  end
36
31
  it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
37
- PuppetCheck.style_check = true
38
- PuppetCheck.puppetlint_args = ['--no-double_quoted_strings-check', '--no-arrow_alignment-check']
39
- PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'])
32
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
40
33
  expect(PuppetCheck.error_files).to eql([])
41
34
  expect(PuppetCheck.warning_files).to eql([])
42
35
  expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
43
36
  end
44
37
  it 'puts a good Puppet manifest in the clean files array' do
45
- PuppetCheck.style_check = true
46
- PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'])
38
+ PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'], false, true, [])
47
39
  expect(PuppetCheck.error_files).to eql([])
48
40
  expect(PuppetCheck.warning_files).to eql([])
49
41
  expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}manifests/good.pp"])
50
42
  end
51
43
  it 'throws a well specified error for an invalid PuppetLint argument' do
52
- PuppetCheck.style_check = true
53
- PuppetCheck.puppetlint_args = ['--non-existent', '--does-not-exist']
54
- expect { PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
44
+ expect { PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
55
45
  end
56
46
  end
57
47
 
@@ -6,45 +6,29 @@ describe RubyParser do
6
6
  PuppetCheck.error_files = []
7
7
  PuppetCheck.warning_files = []
8
8
  PuppetCheck.clean_files = []
9
- PuppetCheck.style_check = false
10
- PuppetCheck.rubocop_args = []
11
9
  end
12
10
 
13
11
  context '.ruby' do
14
12
  it 'puts a bad syntax ruby file in the error files array' do
15
- RubyParser.ruby([fixtures_dir + 'lib/syntax.rb'])
13
+ RubyParser.ruby([fixtures_dir + 'lib/syntax.rb'], false, [])
16
14
  expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}lib/syntax.rb:\n.*syntax error})
17
15
  expect(PuppetCheck.warning_files).to eql([])
18
16
  expect(PuppetCheck.clean_files).to eql([])
19
17
  end
20
- if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.1.0')
21
- it 'puts a bad style ruby file in the warning files array' do
22
- PuppetCheck.style_check = true
23
- RubyParser.ruby([fixtures_dir + 'lib/style.rb'])
24
- expect(PuppetCheck.error_files).to eql([])
25
- expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
26
- expect(PuppetCheck.clean_files).to eql([])
27
- end
28
- else
29
- it 'puts a bad style ruby file in the warning files array' do
30
- PuppetCheck.style_check = true
31
- RubyParser.ruby([fixtures_dir + 'lib/style.rb'])
32
- expect(PuppetCheck.error_files).to eql([])
33
- expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single})
34
- expect(PuppetCheck.clean_files).to eql([])
35
- end
18
+ it 'puts a bad style ruby file in the warning files array' do
19
+ RubyParser.ruby([fixtures_dir + 'lib/style.rb'], true, [])
20
+ expect(PuppetCheck.error_files).to eql([])
21
+ expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
22
+ expect(PuppetCheck.clean_files).to eql([])
36
23
  end
37
24
  it 'puts a bad style ruby file in the clean files array when rubocop_args ignores its warnings' do
38
- PuppetCheck.style_check = true
39
- PuppetCheck.rubocop_args = ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals']
40
- RubyParser.ruby([fixtures_dir + 'lib/rubocop_style.rb'])
25
+ RubyParser.ruby([fixtures_dir + 'lib/rubocop_style.rb'], true, ['--except', 'Lint/UselessAssignment,Style/HashSyntax,Style/GlobalVars,Style/StringLiterals'])
41
26
  expect(PuppetCheck.error_files).to eql([])
42
27
  expect(PuppetCheck.warning_files).to eql([])
43
28
  expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}lib/rubocop_style.rb"])
44
29
  end
45
30
  it 'puts a good ruby file in the clean files array' do
46
- PuppetCheck.style_check = true
47
- RubyParser.ruby([fixtures_dir + 'lib/good.rb'])
31
+ RubyParser.ruby([fixtures_dir + 'lib/good.rb'], true, [])
48
32
  expect(PuppetCheck.error_files).to eql([])
49
33
  expect(PuppetCheck.warning_files).to eql([])
50
34
  expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}lib/good.rb"])
@@ -80,29 +64,25 @@ describe RubyParser do
80
64
 
81
65
  context '.librarian' do
82
66
  it 'puts a bad syntax librarian Puppet file in the error files array' do
83
- RubyParser.librarian([fixtures_dir + 'librarian_syntax/Puppetfile'])
67
+ RubyParser.librarian([fixtures_dir + 'librarian_syntax/Puppetfile'], false, [])
84
68
  expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}librarian_syntax/Puppetfile:\n.*syntax error})
85
69
  expect(PuppetCheck.warning_files).to eql([])
86
70
  expect(PuppetCheck.clean_files).to eql([])
87
71
  end
88
72
  it 'puts a bad style librarian Puppet file in the warning files array' do
89
- PuppetCheck.style_check = true
90
- RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'])
73
+ RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, [])
91
74
  expect(PuppetCheck.error_files).to eql([])
92
75
  expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the parameters.*\n.*Use the new})
93
76
  expect(PuppetCheck.clean_files).to eql([])
94
77
  end
95
78
  it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
96
- PuppetCheck.style_check = true
97
- PuppetCheck.rubocop_args = ['--except', 'Style/AlignParameters,Style/HashSyntax']
98
- RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'])
79
+ RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, ['--except', 'Style/AlignParameters,Style/HashSyntax'])
99
80
  expect(PuppetCheck.error_files).to eql([])
100
81
  expect(PuppetCheck.warning_files).to eql([])
101
82
  expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
102
83
  end
103
84
  it 'puts a good librarian Puppet file in the clean files array' do
104
- PuppetCheck.style_check = true
105
- RubyParser.librarian([fixtures_dir + 'librarian_good/Puppetfile'])
85
+ RubyParser.librarian([fixtures_dir + 'librarian_good/Puppetfile'], true, [])
106
86
  expect(PuppetCheck.error_files).to eql([])
107
87
  expect(PuppetCheck.warning_files).to eql([])
108
88
  expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}librarian_good/Puppetfile"])
@@ -40,7 +40,7 @@ describe PuppetCheck do
40
40
 
41
41
  it 'correctly parses one directory and returns all of its files' do
42
42
  dir.each { |file| expect(File.file?(file)).to be true }
43
- expect(dir.length).to eql(28)
43
+ expect(dir.length).to eql(29)
44
44
  end
45
45
 
46
46
  it 'correctly parses multiple directories and returns all of their files' do
@@ -13,7 +13,7 @@ describe PuppetCheck do
13
13
  expect { cli }.not_to raise_exception
14
14
 
15
15
  expect(PuppetCheck.error_files.length).to eql(8)
16
- expect(PuppetCheck.warning_files.length).to eql(8)
16
+ expect(PuppetCheck.warning_files.length).to eql(9)
17
17
  expect(PuppetCheck.clean_files.length).to eql(11)
18
18
  expect(PuppetCheck.ignored_files.length).to eql(1)
19
19
 
@@ -38,7 +38,7 @@ describe PuppetCheck do
38
38
  expect { tasks }.not_to raise_exception
39
39
 
40
40
  expect(PuppetCheck.error_files.length).to eql(8)
41
- expect(PuppetCheck.warning_files.length).to eql(8)
41
+ expect(PuppetCheck.warning_files.length).to eql(9)
42
42
  expect(PuppetCheck.clean_files.length).to eql(11)
43
43
  expect(PuppetCheck.ignored_files.length).to eql(1)
44
44
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schuchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2016-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -148,6 +148,7 @@ files:
148
148
  - spec/fixtures/metadata.json
149
149
  - spec/fixtures/metadata_good/metadata.json
150
150
  - spec/fixtures/metadata_style/metadata.json
151
+ - spec/fixtures/metadata_style_two/metadata.json
151
152
  - spec/fixtures/metadata_syntax/metadata.json
152
153
  - spec/fixtures/spec/facter/facter_spec.rb
153
154
  - spec/fixtures/spec/fixtures/do_not_parse_me
@@ -214,6 +215,7 @@ test_files:
214
215
  - spec/fixtures/metadata.json
215
216
  - spec/fixtures/metadata_good/metadata.json
216
217
  - spec/fixtures/metadata_style/metadata.json
218
+ - spec/fixtures/metadata_style_two/metadata.json
217
219
  - spec/fixtures/metadata_syntax/metadata.json
218
220
  - spec/fixtures/spec/facter/facter_spec.rb
219
221
  - spec/fixtures/spec/fixtures/do_not_parse_me