voxpupuli-test 13.0.0 → 13.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 690ead9092069cf8aa0bb374a801ee321b72b835f867a52dfe1858fdb3d52390
4
- data.tar.gz: 35f237f3fb512ebf63fdfc6823dec401665e302c5ffc54016764e28848be3455
3
+ metadata.gz: faeae0f342ac61d23fe3ce32cf98619b893412832ac3092a02d3f02b09a4a0dd
4
+ data.tar.gz: d269e93057980c6f8de427184af40f2b644553fc671126951b48b860d65696f7
5
5
  SHA512:
6
- metadata.gz: be6ed41f5d3c8c4e533acb0b5d22f738e23aa5f9567ae58c6575546355f7b2d26381aa2c7cea65f1d08c0a060c13596de823f4ecbf5b28006b795f3f8a2b4d50
7
- data.tar.gz: b1d39e2e4c0777b3be6175124317cc2ca5149eb2f51dd7c2aa116c65344ffafe977cf33a82225f0eed6cb1f577abb6649ecd1a4ac245ed46ba83ce8d24f3a415
6
+ metadata.gz: aa94ef8506d9acdff6039fc6bc0106a094fea9b3508bd62089bd66b3463273597fb8057526fc747bf3d0522e0fb22ba1e10c666f560ac5fed8f2c17532bf4fb2
7
+ data.tar.gz: 4bf3580b0456dbb59b98a8cb7c0ecf7154efe83b13ac725bbf44a7c88efd06603ae0d1382536db6a52cd92e4aae4add7cd05354fd3c1fdde875621b8be73e726
data/README.md CHANGED
@@ -84,6 +84,29 @@ It has an exclude pattern for: `%r{^((modules|acceptance|\.?vendor|spec/fixtures
84
84
  We recommend using the GitHub style guide for markdown files, which includes no trailing whitespace.
85
85
  See [GitHub Markdown Style Guide](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)
86
86
 
87
+ ### `check:misplaced_files`
88
+
89
+ The rake task `check:misplaced_files` checks for misplaced files in the repository.
90
+
91
+ Files are considered misplaced if they don't belong in the directory tree they are under.
92
+ I.e. `functions/`, `manifests/`, and `types/` may only contain `.pp` files, `templates/` may only contain `.erb` and `.epp`, `data/` may only contain `.yml` and `.yaml`, and `lib/` may only contain `.rb`.
93
+
94
+ ### `check:utf8`
95
+
96
+ The rake task `check:utf8` checks that all files that will be parsed by Puppet are encoded in valid UTF-8 without a BOM.
97
+
98
+ The task validates all files under `data/`, `functions/`, `lib/`, `manifests/`, `templates/`, and `types/`.
99
+
100
+ ## Environment variables
101
+
102
+ ### `CODECLIMATE_REPORT_FILE`
103
+
104
+ Setting `CODECLIMATE_REPORT_FILE` to a file path will configure tasks that support it to output CodeClimate-style JSON reports into the given file.
105
+
106
+ The tasks that currently support this feature include `lint` and `rubocop`.
107
+
108
+ Note that if multiple tasks all attempt to output CodeClimate reports in a single rake call, then only the final task will be able store its report.
109
+
87
110
  ## Fact handling
88
111
 
89
112
  The recommended method is using [rspec-puppet-facts](https://github.com/mcanevet/rspec-puppet-facts) and is set up by default. This means the tests are writting as follows:
@@ -49,6 +49,50 @@ namespace :check do
49
49
  exit 1
50
50
  end
51
51
  end
52
+
53
+ desc 'Check that no misplaced files exist in module code/data'
54
+ task :misplaced_files do
55
+ misplaced = []
56
+ misplaced += Dir['data/**/*'].reject { |fn| !File.file?(fn) || fn.end_with?('.yaml') || fn.end_with?('.yml') }
57
+ misplaced += Dir['lib/**/*'].reject { |fn| !File.file?(fn) || fn.end_with?('.rb') }
58
+ misplaced += Dir['{functions,manifests,types}/**/*'].reject { |fn| !File.file?(fn) || fn.end_with?('.pp') }
59
+ misplaced += Dir['templates/**/*'].reject { |fn| !File.file?(fn) || fn.end_with?('.epp') || fn.end_with?('.erb') }
60
+
61
+ if misplaced.any?
62
+ misplaced.each { |filename| puts "#{filename} is misplaced" }
63
+ exit 1
64
+ end
65
+ end
66
+
67
+ desc 'Check that all module code and data are valid UTF-8 without BOM'
68
+ task :utf8 do
69
+ errors = []
70
+
71
+ Dir['{data,functions,lib,manifests,templates,types}/**/*'].each do |filename|
72
+ next unless File.file? filename
73
+
74
+ File.open(filename, 'r:utf-8') do |file|
75
+ data = file.readline
76
+
77
+ if !data.valid_encoding?
78
+ errors << "#{filename} can't be parsed as UTF-8"
79
+ elsif data.bytes[0..2] == [0xef, 0xbb, 0xbf]
80
+ errors << "#{filename} contains BOM"
81
+ elsif data.include? "\x00" # UTF-16 without BOM is technically valid UTF-8, but contains null-bytes
82
+ errors << "#{filename} contains null bytes"
83
+ elsif !file.eof?
84
+ redo
85
+ end
86
+ end
87
+ rescue StandardError => e
88
+ errors << "#{filename} failed to parse, #{e.class}: #{e}"
89
+ end
90
+
91
+ if errors.any?
92
+ errors.each { |error| puts error }
93
+ exit 1
94
+ end
95
+ end
52
96
  end
53
97
 
54
98
  desc 'Run static pre release checks'
@@ -9,4 +9,13 @@ RuboCop::RakeTask.new(:rubocop) do |task|
9
9
  if ENV['GITHUB_ACTIONS'] == 'true'
10
10
  task.formatters << 'github'
11
11
  end
12
+
13
+ if ENV['CODECLIMATE_REPORT_FILE']
14
+ # Ensure the default rubocop formatter still runs even when producing codeclimate report
15
+ require 'rubocop'
16
+ task.formatters << (RuboCop::ConfigStore.new.for_pwd.for_all_cops['DefaultFormatter'] || 'progress') if task.formatters.empty?
17
+
18
+ task.requires << File.join(__dir__, '../rubocop_formatters/codeclimate.rb')
19
+ task.options += ['--format', 'CodeclimateFormatter', '--out', ENV['CODECLIMATE_REPORT_FILE']]
20
+ end
12
21
  end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ # Simple codeclimate-style JSON formatter for RuboCop
6
+ class CodeclimateFormatter < RuboCop::Formatter::BaseFormatter
7
+ include RuboCop::PathUtil
8
+
9
+ SEVERITY_MAP = {
10
+ info: 'info',
11
+ refactor: 'minor',
12
+ convention: 'minor',
13
+ warning: 'major',
14
+ error: 'critical',
15
+ fatal: 'blocker',
16
+ }.freeze
17
+
18
+ attr_reader :output_array
19
+
20
+ def initialize(output, options = {})
21
+ super
22
+ @output_array = []
23
+ end
24
+
25
+ def file_finished(file, offenses)
26
+ @output_array += hashes_for_file(file, offenses)
27
+ end
28
+
29
+ def finished(_inspected_files)
30
+ output.write output_array.to_json
31
+ end
32
+
33
+ private
34
+
35
+ def hashes_for_file(file, offenses)
36
+ offenses.map do |offense|
37
+ category, name = offense.cop_name.split('/')
38
+ name, category = category, name if name.nil?
39
+
40
+ message = offense.message.dup
41
+ message.delete_prefix! offense.cop_name
42
+ message.delete_prefix! ':'
43
+ message.strip!
44
+
45
+ hash = {
46
+ type: :issue,
47
+ check_name: name,
48
+ description: message,
49
+ categories: [category || 'General'],
50
+ location: hash_for_location(file, offense),
51
+ severity: SEVERITY_MAP[offense.severity.name],
52
+ }
53
+ hash[:fingerprint] = Digest::SHA2.hexdigest([file, offense.cop_name, offense.line, offense.column].to_json)
54
+ hash
55
+ end
56
+ end
57
+
58
+ def hash_for_location(file, offense)
59
+ {
60
+ path: smart_path(file),
61
+ positions: {
62
+ begin: {
63
+ line: offense.line,
64
+ column: offense.real_column,
65
+ },
66
+ end: {
67
+ line: offense.last_line,
68
+ column: offense.last_column.zero? ? 1 : offense.last_column,
69
+ },
70
+ },
71
+ }
72
+ end
73
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voxpupuli-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.0.0
4
+ version: 13.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
@@ -118,7 +118,7 @@ dependencies:
118
118
  version: '0.1'
119
119
  - - "<"
120
120
  - !ruby/object:Gem::Version
121
- version: '2'
121
+ version: '3'
122
122
  type: :runtime
123
123
  prerelease: false
124
124
  version_requirements: !ruby/object:Gem::Requirement
@@ -128,7 +128,7 @@ dependencies:
128
128
  version: '0.1'
129
129
  - - "<"
130
130
  - !ruby/object:Gem::Version
131
- version: '2'
131
+ version: '3'
132
132
  - !ruby/object:Gem::Dependency
133
133
  name: puppet-syntax
134
134
  requirement: !ruby/object:Gem::Requirement
@@ -311,6 +311,7 @@ files:
311
311
  - lib/voxpupuli/test/rake/rubocop.rb
312
312
  - lib/voxpupuli/test/rake/spec.rb
313
313
  - lib/voxpupuli/test/rake/validate.rb
314
+ - lib/voxpupuli/test/rubocop_formatters/codeclimate.rb
314
315
  - lib/voxpupuli/test/spec_helper.rb
315
316
  - rubocop.yml
316
317
  homepage: http://github.com/voxpupuli/voxpupuli-test