puppet-check 2.0.0 → 2.2.0

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
  SHA256:
3
- metadata.gz: 9d2defe55b01e90b73fc2cb3dfc12b9004fbe02b73fc751b736529e454c0c92b
4
- data.tar.gz: 96bce3d495f0a5778d5475659ba3fbf6360290ef565666478933cd867babc34d
3
+ metadata.gz: b1e591abda5a49b0731073d14831000016b08d72b505ab3d22a287029fa1243f
4
+ data.tar.gz: 96bceb6ef51e82582984ab0c88f96591d30c26650e174a0215133af0723c9526
5
5
  SHA512:
6
- metadata.gz: 52037386f7f9168822a8cc14da2455d3a6a2f38cc3686ef7edbed65bee382a07159328c9ca3e1472c97d533e0966b431b921d78380bec684489e7528ec443694
7
- data.tar.gz: 859c21981164a0e002c6e8faeec55b285aa65d7cd953b838415873d482f7a32acf4ede39049329eb9435f435a7a96b741749a7501e1a0cfd045c43444f5cbc94
6
+ metadata.gz: 805ef299109715901160e9f4c4894ff05f31140c8234ed867273434e85b525e4c91e0e5fd7e6f96fb23352a3b801afa006b31cb4a93515c76182725b510a57f8
7
+ data.tar.gz: 2fc8340befd7b6c5f9662038aeea6614858ed1a2bd92f0d76c797fe42b316fed9d080e38cd8f4203d16240c365086bc1165c89102f3ee4e496dae6f1cf75b9bd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ### 2.2.0
2
+ - Add Enable Pending Cops to base RuboCop configuration.
3
+ - Support checking plans.
4
+ - Fix Puppet >= 6.5 error message capture when line/col info.
5
+ - Minimum Ruby version increased to 2.6.
6
+ - Minimum Puppet version increased to 5.4.
7
+
8
+ ### 2.1.0
9
+ - Minimum supported version of Puppet bumped to 5.0.
10
+ - Minimum Ruby version bumped to 2.4.
11
+ - Official support for Puppet 7, Rubocop 1, and Reek 6.
12
+ - Fix Puppet message string transform conditionals.
13
+
14
+ ### 2.0.1
15
+ - Check for existence of executables for dependency module retrieval.
16
+ - Beta support for Puppet 7, Rubocop 1, and Reek 6.
17
+
1
18
  ### 2.0.0
2
19
  - Bump minimum version of Puppet to 4.0.0 and remove < 4 support code.
3
20
  - Official support for Puppet 6.
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # Puppet Check
2
- [![Build Status](https://travis-ci.org/mschuchard/puppet-check.svg?branch=master)](https://travis-ci.org/mschuchard/puppet-check)
2
+ [![Build Status](https://travis-ci.com/mschuchard/puppet-check.svg?branch=master)](https://travis-ci.com/mschuchard/puppet-check)
3
+ [![CircleCI](https://circleci.com/gh/mschuchard/puppet-check.svg?style=svg)](https://circleci.com/gh/mschuchard/puppet-check)
3
4
 
4
5
  - [Description](#description)
5
6
  - [Usage](#usage)
@@ -124,8 +125,11 @@ The following files have unrecognized formats and therefore were not processed:
124
125
  ### What About Puppet Development Kit?
125
126
  The fairly recent release of the Puppet Development Kit (PDK) will hopefully eventually bring about the capability to test and validate your Puppet code and data in a streamlined, efficient, comprehensive, and accurate fashion comparable to Puppet Check. Unfortunately, the PDK has not yet achieved feature or efficiency parity with Puppet Check. The goal is for the PDK to one day replace Puppet Check and for Puppet Check to enter maintenance mode, but for now Puppet Check is still needed to lead Puppet testing.
126
127
 
128
+ ### What About PDK now?
129
+ As of version 2.4.0 of the PDK, the PDK has essentially more or less achieved feature parity with Puppet Check. Although the PDK is not as efficient (including especially that Puppet Check executes significantly faster), it is still supported by Puppetlabs. Therefore, if you need an efficient and comprehensive Puppet validation solution, then you can still utilize Puppet Check, but the PDK is a recommended alternative for the future.
130
+
127
131
  ## Usage
128
- Please see the [Gemspec](puppet-check.gemspec) for dependency information. All other dependencies should be fine with various versions. Puppet Check can be used with a CLI, Rake tasks, or API, from your system, rbenv, rvm, Docker, or Vagrant. Please note all interfaces (API by default, but can be modified) will ignore any directories named `fixtures` or specified paths with that directory during file checks and spec tests.
132
+ Please see the [Gemspec](puppet-check.gemspec) for dependency information. All other dependencies should be fine with various versions. Puppet Check can be used with a CLI, Rake tasks, or API, from your system, rbenv, rvm, Docker, or Vagrant. Please note all interfaces (API by default, but can be modified) will ignore any directories named `fixtures`, or specified paths with that directory during file checks and spec tests.
129
133
 
130
134
  ### CLI
131
135
  ```
@@ -277,45 +281,24 @@ task.pattern = Dir.glob('**/{classes,defines,facter,functions,hosts,puppet,unit,
277
281
 
278
282
  ### Docker
279
283
 
280
- You can also use Puppet Check inside of Docker for quick, portable, and disposable testing. Below is an example Dockerfile for this purpose:
281
-
282
- ```dockerfile
283
- # a reliable and small container at the moment
284
- FROM ubuntu:18.04
285
- # 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
286
- RUN apt-get update && apt-get install ruby git -y
287
- # 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.3 and then rspec-puppet and rake for extra testing
288
- RUN gem install --no-document puppet-check reek rspec-puppet rake
289
- # this is needed for the ruby json parser to not flip out on fresh os installs for some reason (change encoding value as necessary)
290
- ENV LANG en_US.UTF-8
291
- # create the directory for your module, directory environment, etc. and change directory into it
292
- WORKDIR /module_name_or_directory_environment_name
293
- # copy the module, directory environment, etc. contents into the corresponding directory inside the container; alternative, bind a volume mount for your module(s) into the container at runtime
294
- COPY / .
295
- # execute your tests; in this example we are executing the full suite of tests
296
- ENTRYPOINT ["rake", "puppetcheck"]
297
- ```
298
-
299
- 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.
300
-
301
- As an alternative to copying Puppet code and data into the image for testing, it is also recommended to bind volume mount the container to the directory with your Puppet code and data.
284
+ A supported [Docker image](https://hub.docker.com/r/matthewschuchard/puppet-check) of Puppet-Check is now available from the public Docker Hub registry. Please consult the repository documentation for further usage information.
302
285
 
303
286
  ### Vagrant
304
287
 
305
- 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.
288
+ 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.
306
289
 
307
290
  ```ruby
308
291
  Vagrant.configure(2) do |config|
309
292
  # a reliable and small box at the moment
310
- config.vm.box = 'fedora/26-cloud-base'
293
+ config.vm.box = 'fedora/35-cloud-base'
311
294
 
312
295
  config.vm.provision 'shell', inline: <<-SHELL
313
296
  # cd to '/vagrant'
314
297
  cd /vagrant
315
298
  # 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
316
299
  sudo dnf install ruby rubygems git -y
317
- # 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
318
- sudo gem install --no-document puppet-check reek rspec-puppet rake
300
+ # you need puppet-check and any other extra dependencies that come from gems; in this example we install rspec-puppet and rake for extra testing
301
+ sudo gem install --no-document puppet-check rspec-puppet rake
319
302
  # this is needed for the ruby json parser to not flip out on fresh os installs for some reason (change encoding value as necessary)
320
303
  export LANG='en_US.UTF-8'
321
304
  # execute your tests; in this example we are executing the full suite of tests
@@ -329,7 +312,7 @@ To overcome the lack of convenient portability, you could try spinning up the Va
329
312
  ### Exit Codes
330
313
  - 0: PuppetCheck exited with no internal exceptions or errors in your code and data.
331
314
  - 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes) or failed spec test(s).
332
- - 2: PuppetCheck exited with one or more errors in your code and data. Alternatively, PuppetCheck exited with one or more warnings in your code and data and you specified to fail on warnings.
315
+ - 2: PuppetCheck exited with one or more errors in your code and data. Alternatively, PuppetCheck exited with one or more warnings in your code and data, and you specified to fail on warnings.
333
316
 
334
317
  ### Optional Dependencies
335
318
  - **rake** (gem): install this if you want to use Puppet Check with `rake` tasks in addition to the CLI.
@@ -1,5 +1,5 @@
1
1
  require 'optparse'
2
- require_relative '../puppet-check'
2
+ require_relative '../puppet_check'
3
3
 
4
4
  # the command line interface for PuppetCheck
5
5
  class PuppetCheck::CLI
@@ -27,7 +27,7 @@ class PuppetCheck::CLI
27
27
 
28
28
  # base options
29
29
  opts.on('--version', 'Display the current version.') do
30
- puts 'puppet-check 2.0.0'
30
+ puts 'puppet-check 2.2.0'
31
31
  exit 0
32
32
  end
33
33
 
@@ -1,4 +1,4 @@
1
- require_relative '../puppet-check'
1
+ require_relative '../puppet_check'
2
2
 
3
3
  # executes diagnostics on data files
4
4
  class DataParser
@@ -8,19 +8,17 @@ class DataParser
8
8
 
9
9
  files.each do |file|
10
10
  # check yaml syntax
11
- begin
12
- parsed = YAML.load_file(file)
13
- rescue StandardError => err
14
- PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}")
15
- else
16
- warnings = []
11
+ parsed = YAML.load_file(file)
12
+ rescue StandardError => err
13
+ PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}")
14
+ else
15
+ warnings = []
17
16
 
18
- # perform some rudimentary hiera checks if data exists and is hieradata
19
- warnings = hiera(parsed, file) if parsed && (File.basename(file) != 'hiera.yaml')
17
+ # perform some rudimentary hiera checks if data exists and is hieradata
18
+ warnings = hiera(parsed, file) if parsed && (File.basename(file) != 'hiera.yaml')
20
19
 
21
- next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
22
- PuppetCheck.settings[:clean_files].push(file.to_s)
23
- end
20
+ next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
21
+ PuppetCheck.settings[:clean_files].push(file.to_s)
24
22
  end
25
23
  end
26
24
 
@@ -118,8 +116,8 @@ class DataParser
118
116
  next warnings.push("'#{req_dep['name']}' is missing an upper bound.") unless req_dep['version_requirement'].include?('<')
119
117
 
120
118
  # check for semantic versioning
121
- if key == 'dependencies'
122
- warnings.push("'#{req_dep['name']}' has non-semantic versioning in its 'version_requirement' key.") unless req_dep['version_requirement'] =~ /\d+\.\d+\.\d+.*\d+\.\d+\.\d+/
119
+ if key == 'dependencies' && req_dep['version_requirement'] !~ /\d+\.\d+\.\d+.*\d+\.\d+\.\d+/
120
+ warnings.push("'#{req_dep['name']}' has non-semantic versioning in its 'version_requirement' key.")
123
121
  end
124
122
  end
125
123
  end
@@ -177,16 +175,16 @@ class DataParser
177
175
  end
178
176
  end
179
177
  # check that parameters is a hash
180
- if parsed.key?('parameters')
181
- warnings.push('parameters value is not a Hash') unless parsed['parameters'].is_a?(Hash)
178
+ if parsed.key?('parameters') && !parsed['parameters'].is_a?(Hash)
179
+ warnings.push('parameters value is not a Hash')
182
180
  end
183
181
  # check that puppet_task_version is an integer
184
- if parsed.key?('puppet_task_version')
185
- warnings.push('puppet_task_version value is not an Integer') unless parsed['puppet_task_version'].is_a?(Integer)
182
+ if parsed.key?('puppet_task_version') && !parsed['puppet_task_version'].is_a?(Integer)
183
+ warnings.push('puppet_task_version value is not an Integer')
186
184
  end
187
185
  # check that supports_noop is a boolean
188
- if parsed.key?('supports_noop')
189
- warnings.push('supports_noop value is not a Boolean') unless parsed['supports_noop'].is_a?(TrueClass) || parsed['supports_noop'].is_a?(FalseClass)
186
+ if parsed.key?('supports_noop') && !(parsed['supports_noop'].is_a?(TrueClass) || parsed['supports_noop'].is_a?(FalseClass))
187
+ warnings.push('supports_noop value is not a Boolean')
190
188
  end
191
189
  # assume this is hieradata and ensure it is non-empty
192
190
  elsif parsed
@@ -205,7 +203,7 @@ class DataParser
205
203
  warnings = []
206
204
 
207
205
  # disregard nil/undef value data check if default values (common)
208
- unless file =~ /^common/
206
+ unless /^common/.match?(file)
209
207
  data.each do |key, value|
210
208
  # check for nil values in the data (nil keys are fine)
211
209
  if (value.is_a?(Hash) && value.values.any?(&:nil?)) || value.nil?
@@ -1,4 +1,4 @@
1
- require_relative '../puppet-check'
1
+ require_relative '../puppet_check'
2
2
 
3
3
  # class to handle outputting diagnostic results in desired format
4
4
  class OutputResults
@@ -22,7 +22,7 @@ class OutputResults
22
22
  end
23
23
 
24
24
  # output the results as yaml or json
25
- def self.markup(settings)
25
+ def self.markup(format)
26
26
  # generate output hash
27
27
  hash = {}
28
28
  hash['errors'] = PuppetCheck.settings[:error_files] unless PuppetCheck.settings[:error_files].empty?
@@ -31,14 +31,15 @@ class OutputResults
31
31
  hash['ignored'] = PuppetCheck.settings[:ignored_files] unless PuppetCheck.settings[:ignored_files].empty?
32
32
 
33
33
  # convert hash to markup language
34
- if settings[:output_format] == 'yaml'
34
+ case format
35
+ when 'yaml'
35
36
  require 'yaml'
36
37
  puts Psych.dump(hash, indentation: 2)
37
- elsif settings[:output_format] == 'json'
38
+ when 'json'
38
39
  require 'json'
39
40
  puts JSON.pretty_generate(hash)
40
41
  else
41
- raise "puppet-check: Unsupported output format '#{settings[:output_format]}' was specified."
42
+ raise "puppet-check: Unsupported output format '#{format}' was specified."
42
43
  end
43
44
  end
44
45
  end
@@ -1,5 +1,5 @@
1
1
  require 'puppet'
2
- require_relative '../puppet-check'
2
+ require_relative '../puppet_check'
3
3
 
4
4
  # executes diagnostics on puppet files
5
5
  class PuppetParser
@@ -17,35 +17,29 @@ class PuppetParser
17
17
 
18
18
  # check puppet syntax
19
19
  begin
20
+ # initialize message
21
+ message = ''
22
+ # specify tasks attribute for parser validation if this looks like a plan or not
23
+ Puppet[:tasks] = file.match?(%r{plans/\w+\.pp$}) ? true : false
20
24
  # in puppet >= 6.5 the return of this method is a hash with the error
21
25
  new_error = Puppet::Face[:parser, :current].validate(file)
22
26
  # puppet 6.5 output format is now a hash from the face api
23
- if Puppet::PUPPETVERSION.to_f >= 6.5 && new_error != {}
24
- next PuppetCheck.settings[:error_files].push("#{file}:\n#{new_error.values.map(&:to_s).join("\n").gsub(/ \(file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')}")
27
+ if Gem::Version.new(Puppet::PUPPETVERSION) >= Gem::Version.new('6.5.0') && new_error != {}
28
+ message = new_error.values.map(&:to_s).join("\n").gsub(/ \(file: #{File.absolute_path(file)}(, |\))/, '').gsub('Could not parse for environment *root*: ', '')
25
29
  end
26
30
  # this is the actual error that we need to rescue Puppet::Face from
27
31
  rescue SystemExit
28
32
  # puppet 5.4-6.4 has a new validator output format and eof errors have fake dir env info
29
- if Puppet::PUPPETVERSION.to_f >= 5.4 && Puppet::PUPPETVERSION.to_f < 6.5
30
- next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')}")
31
- # puppet 5.0-5.2 can only do one error per line and outputs fake dir env info
32
- elsif Puppet::PUPPETVERSION.to_f >= 5.0 && Puppet::PUPPETVERSION.to_f < 5.3
33
- next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '').gsub(/Could not parse.*: /, '')}")
34
- end
35
- # puppet < 5 and 5.3 parser output style
36
- next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}")
33
+ message = errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')
37
34
  end
35
+ # output message
36
+ next PuppetCheck.settings[:error_files].push("#{file}:\n#{message}") unless message.empty?
38
37
 
39
38
  # initialize warnings with output from the parser if it exists, since the output is warnings if Puppet::Face did not trigger a SystemExit
40
39
  warnings = "#{file}:"
41
40
  unless errors.empty?
42
- # puppet 5.4-5.x has a new validator output format
43
- warnings << if Puppet::PUPPETVERSION.to_f >= 5.4
44
- "\n#{errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '')}"
45
- # puppet <= 5.3 validator output format
46
- else
47
- "\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
48
- end
41
+ # puppet >= 5.4 has a new validator output format
42
+ warnings << "\n#{errors.map(&:to_s).join("\n").gsub("file: #{File.absolute_path(file)}, ", '')}"
49
43
  end
50
44
  Puppet::Util::Log.close_all
51
45
 
@@ -82,14 +76,12 @@ class PuppetParser
82
76
 
83
77
  files.each do |file|
84
78
  # check puppet template syntax
85
- begin
86
- # credits to gds-operations/puppet-syntax for the parser function call
87
- Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new.parse_file(file)
88
- rescue StandardError => err
89
- PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.gsub("#{file}:", '')}")
90
- else
91
- PuppetCheck.settings[:clean_files].push(file.to_s)
92
- end
79
+ # credits to gds-operations/puppet-syntax for the parser function call
80
+ Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new.parse_file(file)
81
+ rescue StandardError => err
82
+ PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.gsub("#{file}:", '')}")
83
+ else
84
+ PuppetCheck.settings[:clean_files].push(file.to_s)
93
85
  end
94
86
  end
95
87
  end
@@ -3,7 +3,7 @@ class RSpecPuppetSupport
3
3
  # code diagram:
4
4
  # 'puppetcheck:spec' task invokes 'run'
5
5
  # 'run' invokes 'file_setup' always and 'dependency_setup' if metadata.json exists
6
- # 'dependency_setup' invokes 'git/forge/hg' if dependencies exist and git/forge/hg is download option
6
+ # 'dependency_setup' invokes 'git/forge/svn/hg' if dependencies exist and git/forge/svn/hg is download option
7
7
  # 'git/forge/svn/hg' downloads module fixture appropriately
8
8
 
9
9
  # prepare the spec fixtures directory for rspec-puppet testing
@@ -15,10 +15,10 @@ class RSpecPuppetSupport
15
15
  # setup fixtures for rspec-puppet testing
16
16
  specdirs.each do |specdir|
17
17
  # skip to next specdir if it does not seem like a puppet module
18
- next unless File.directory?(specdir + '/../manifests')
18
+ next unless File.directory?("#{specdir}/../manifests")
19
19
 
20
20
  # change to module directory
21
- Dir.chdir(specdir + '/..')
21
+ Dir.chdir("#{specdir}/..")
22
22
 
23
23
  # grab the module name from the directory name of the module to pass to file_setup
24
24
  file_setup(File.basename(Dir.pwd))
@@ -90,7 +90,11 @@ class RSpecPuppetSupport
90
90
  # establish path to clone module to
91
91
  path = "spec/fixtures/modules/#{File.basename(git_url, '.git')}"
92
92
  # is the module present and already cloned with git? do a pull; otherwise, do a clone
93
- File.directory?("#{path}/.git") ? spawn("git -C #{path} pull") : spawn("git clone #{args} #{git_url} #{path}")
93
+ begin
94
+ File.directory?("#{path}/.git") ? spawn("git -C #{path} pull") : spawn("git clone #{args} #{git_url} #{path}")
95
+ rescue Errno::ENOENT
96
+ warn 'git is not installed and cannot be used to retrieve dependency modules'
97
+ end
94
98
  end
95
99
 
96
100
  # download external module dependency with forge
@@ -107,7 +111,11 @@ class RSpecPuppetSupport
107
111
  # establish path to checkout module to
108
112
  path = "spec/fixtures/modules/#{File.basename(svn_url)}"
109
113
  # is the module present and already checked out with svn? do an update; otherwise, do a checkout
110
- File.directory?("#{path}/.svn") ? spawn("svn update #{path}") : spawn("svn co #{args} #{svn_url} #{path}")
114
+ begin
115
+ File.directory?("#{path}/.svn") ? spawn("svn update #{path}") : spawn("svn co #{args} #{svn_url} #{path}")
116
+ rescue Errno::ENOENT
117
+ warn 'subversion is not installed and cannot be used to retrieve dependency modules'
118
+ end
111
119
  end
112
120
 
113
121
  # download external module dependency with hg
@@ -116,6 +124,10 @@ class RSpecPuppetSupport
116
124
  # establish path to clone module to
117
125
  path = "spec/fixtures/modules/#{File.basename(hg_url)}"
118
126
  # is the module present and already cloned with hg? do a pull and update; otherwise do a clone
119
- File.directory?("#{path}/.hg") ? spawn("hg --cwd #{path} pull; hg --cwd #{path} update") : spawn("hg clone #{args} #{hg_url} #{path}")
127
+ begin
128
+ File.directory?("#{path}/.hg") ? spawn("hg --cwd #{path} pull; hg --cwd #{path} update") : spawn("hg clone #{args} #{hg_url} #{path}")
129
+ rescue Errno::ENOENT
130
+ warn 'mercurial is not installed and cannot be used to retrieve dependency modules'
131
+ end
120
132
  end
121
133
  end
@@ -1,4 +1,4 @@
1
- require_relative '../puppet-check'
1
+ require_relative '../puppet_check'
2
2
  require_relative 'utils'
3
3
 
4
4
  # executes diagnostics on ruby files
@@ -7,31 +7,29 @@ class RubyParser
7
7
  def self.ruby(files, style, rc_args)
8
8
  files.each do |file|
9
9
  # check ruby syntax
10
- begin
11
- # prevents ruby code from actually executing
12
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}", file) }
13
- rescue ScriptError, StandardError => err
14
- PuppetCheck.settings[:error_files].push("#{file}:\n#{err}")
15
- else
16
- # check ruby style
17
- if style
18
- require 'rubocop'
10
+ # prevents ruby code from actually executing
11
+ catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}", file) }
12
+ rescue ScriptError, StandardError => err
13
+ PuppetCheck.settings[:error_files].push("#{file}:\n#{err}")
14
+ else
15
+ # check ruby style
16
+ if style
17
+ require 'rubocop'
19
18
 
20
- # check RuboCop and collect warnings
21
- rubocop_warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--require', 'rubocop-performance', '--format', 'emacs', file]) }
22
- warnings = rubocop_warnings == '' ? '' : rubocop_warnings.split("#{File.absolute_path(file)}:").join('')
19
+ # check RuboCop and collect warnings
20
+ rubocop_warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--enable-pending-cops', '--require', 'rubocop-performance', '--format', 'emacs', file]) }
21
+ warnings = rubocop_warnings == '' ? '' : rubocop_warnings.split("#{File.absolute_path(file)}:").join('')
23
22
 
24
- # check Reek and collect warnings
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 == ''
23
+ # check Reek and collect warnings
24
+ require 'reek'
25
+ require 'reek/cli/application'
26
+ reek_warnings = Utils.capture_stdout { Reek::CLI::Application.new([file]).execute }
27
+ warnings << reek_warnings.split("\n")[1..].map(&:strip).join("\n") unless reek_warnings == ''
29
28
 
30
- # return warnings
31
- next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.strip}") unless warnings == ''
32
- end
33
- PuppetCheck.settings[:clean_files].push(file.to_s)
29
+ # return warnings
30
+ next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.strip}") unless warnings == ''
34
31
  end
32
+ PuppetCheck.settings[:clean_files].push(file.to_s)
35
33
  end
36
34
  end
37
35
 
@@ -43,8 +41,9 @@ class RubyParser
43
41
  # check ruby template syntax
44
42
  begin
45
43
  # need to eventually have this associated with a different binding during each iteration
46
- warnings = Utils.capture_stderr { ERB.new(File.read(file), nil, '-').result }
47
- # ERB.new(File.read(file), nil, '-').result(RubyParser.new.bind)
44
+ # older usage throws extra warning and mixes with valid warnings confusingly
45
+ warnings = Utils.capture_stderr { ERB.new(File.read(file), trim_mode: '-').result }
46
+ # ERB.new(File.read(file), trim_mode: '-').result(RubyParser.new.bind)
48
47
  rescue NameError, TypeError
49
48
  # empty out warnings since it would contain an error if this pass triggers
50
49
  warnings = ''
@@ -62,30 +61,27 @@ class RubyParser
62
61
  # efficient var assignment prior to iterator
63
62
  if style
64
63
  require 'rubocop'
65
- # cop named differently depending upon version
66
- filename_cop = RuboCop::Version::STRING.to_f >= 0.5 ? 'Naming/FileName' : 'Style/FileName'
64
+
67
65
  # RuboCop is grumpy about non-snake_case filenames so disable the FileName check
68
- rc_args.include?('--except') ? rc_args[rc_args.index('--except') + 1] = "#{rc_args[rc_args.index('--except') + 1]},#{filename_cop}" : rc_args.concat(['--except', filename_cop])
66
+ rc_args.include?('--except') ? rc_args[rc_args.index('--except') + 1] = "#{rc_args[rc_args.index('--except') + 1]},Naming/FileName" : rc_args.concat(['--except', 'Naming/FileName'])
69
67
  end
70
68
 
71
69
  files.each do |file|
72
70
  # check librarian puppet syntax
73
- begin
74
- # prevents ruby code from actually executing
75
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}", file) }
76
- rescue SyntaxError, LoadError, ArgumentError => err
77
- PuppetCheck.settings[:error_files].push("#{file}:\n#{err}")
78
- # check librarian puppet style
79
- else
80
- if style
81
- # check Rubocop
82
- warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--require', 'rubocop-performance', '--format', 'emacs', file]) }
71
+ # prevents ruby code from actually executing
72
+ catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}", file) }
73
+ rescue SyntaxError, LoadError, ArgumentError => err
74
+ PuppetCheck.settings[:error_files].push("#{file}:\n#{err}")
75
+ # check librarian puppet style
76
+ else
77
+ if style
78
+ # check Rubocop
79
+ warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--enable-pending-cops', '--require', 'rubocop-performance', '--format', 'emacs', file]) }
83
80
 
84
- # collect style warnings
85
- next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.split("#{File.absolute_path(file)}:").join('')}") unless warnings.empty?
86
- end
87
- PuppetCheck.settings[:clean_files].push(file.to_s)
81
+ # collect style warnings
82
+ next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.split("#{File.absolute_path(file)}:").join('')}") unless warnings.empty?
88
83
  end
84
+ PuppetCheck.settings[:clean_files].push(file.to_s)
89
85
  end
90
86
  end
91
87
 
@@ -3,7 +3,7 @@ begin
3
3
  rescue LoadError
4
4
  raise 'Rake is not installed and you are attempting to execute Rake tasks with Puppet Check. Please install Rake before continuing.'
5
5
  end
6
- require_relative '../puppet-check'
6
+ require_relative '../puppet_check'
7
7
 
8
8
  # the rake interface for PuppetCheck
9
9
  class PuppetCheck::Tasks < ::Rake::TaskLib
@@ -28,7 +28,7 @@ class PuppetCheck
28
28
  execute_parsers(files, settings)
29
29
 
30
30
  # output the diagnostic results
31
- settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup(settings)
31
+ settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup(settings[:output_format])
32
32
 
33
33
  # progress to regression checks if no errors in file checks
34
34
  if self.class.settings[:error_files].empty? && (!settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
@@ -0,0 +1,3 @@
1
+ plan my_plan::good_plan(
2
+ TargetSpec $servers
3
+ ) {}
@@ -0,0 +1,6 @@
1
+ plan my_plan::style_plan(
2
+ TargetSpec $servers
3
+ ) {
4
+ $foo = 'bar'
5
+ $bar = "$bar baz"
6
+ }
@@ -0,0 +1,5 @@
1
+ plan my_plan::syntax_plan(
2
+ TargetSpec $servers
3
+ ) {
4
+ get_targets($servers).each |Target $server| {)
5
+ }
@@ -4,13 +4,13 @@ module OctocatalogDiff
4
4
  class Config
5
5
  def self.config
6
6
  settings = {}
7
- octocatalog_diff_dir = File.dirname(__FILE__) + '/'
7
+ octocatalog_diff_dir = "#{File.dirname(__FILE__)}/"
8
8
 
9
- settings[:hiera_config] = octocatalog_diff_dir + 'hiera.yaml'
10
- settings[:hiera_path] = octocatalog_diff_dir + 'hieradata'
11
- settings[:fact_file] = octocatalog_diff_dir + 'facts.yaml'
12
- settings[:puppet_binary] = if File.directory?('/home/travis')
13
- octocatalog_diff_dir + '../../bin/puppet'
9
+ settings[:hiera_config] = "#{octocatalog_diff_dir}hiera.yaml"
10
+ settings[:hiera_path] = "#{octocatalog_diff_dir}hieradata"
11
+ settings[:fact_file] = "#{octocatalog_diff_dir}facts.yaml"
12
+ settings[:puppet_binary] = if ENV['TRAVIS'] == 'true'
13
+ "#{octocatalog_diff_dir}../../bin/puppet"
14
14
  else
15
15
  '/usr/local/bin/puppet'
16
16
  end