metadata-json-lint 3.0.3 → 4.0.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: 601496e157ed6f6f3f6faee2a68a5b6ec6b725a869adcca63fd61b7631435085
4
- data.tar.gz: 887d30fa3c8dbf9d629f64d851a4ee4ee314a66b48f920d96d1bd3ba2ee46bc2
3
+ metadata.gz: 1327a043726b715003e697e9024bda80b0134896e7fb2b97f9de14ee8b28e8b7
4
+ data.tar.gz: ff6e85957f67e2d1b2a37f2a9383640867bf7bf4f04cc1ed5bc10ed7b9c738fb
5
5
  SHA512:
6
- metadata.gz: d869ce3a305ddbb91e4dcf602c33174ed7d8dc734ddc05419b09ac808f87ddbbac64b56be10bd945e3442c6eaab1dea5200170a84f239069abeba63d0900f1d3
7
- data.tar.gz: 36a47058aad6c5af739315ca3968b0ac71858d31988383751045b9a0cdfb1832f995b94fedc7b289cbd55017319a73dd5a52545a488c4046a7f20664a649961c
6
+ metadata.gz: 841c877388db1e132ba061ef657f21f63b5f10b68255b96a673b1a79a5d4052327a54cc696a99c850addb4f8c830dab139c9891ae35ecf7444e83d53e8d86cc2
7
+ data.tar.gz: caf5db87f9dd3fa2a33fb75b36992f6447ec80c335c0757246d6c9be7d22019581464ee6bc65f26549f162f6cc3ac9efb6ee9f3cbe546af5465f414882179e1c
@@ -10,7 +10,7 @@ jobs:
10
10
  runs-on: ubuntu-latest
11
11
  if: github.repository_owner == 'voxpupuli'
12
12
  steps:
13
- - uses: actions/checkout@v3
13
+ - uses: actions/checkout@v4
14
14
  - name: Install Ruby 3.0
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
@@ -18,7 +18,7 @@ jobs:
18
18
  env:
19
19
  BUNDLE_WITHOUT: release
20
20
  - name: Build gem
21
- run: gem build *.gemspec
21
+ run: gem build --strict --verbose *.gemspec
22
22
  - name: Publish gem to rubygems.org
23
23
  run: gem push *.gem
24
24
  env:
@@ -10,22 +10,34 @@ env:
10
10
  BUNDLE_WITHOUT: release
11
11
 
12
12
  jobs:
13
+ rubocop:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Install Ruby ${{ matrix.ruby }}
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: "3.0"
21
+ bundler-cache: true
22
+ - name: Run Rubocop
23
+ run: bundle exec rake rubocop
13
24
  rspec:
14
25
  runs-on: ubuntu-latest
15
26
  strategy:
16
27
  matrix:
17
28
  include:
18
- - ruby: "2.4"
19
- - ruby: "2.5"
20
- - ruby: "2.6"
21
29
  - ruby: "2.7"
22
30
  - ruby: "3.0"
31
+ - ruby: "3.1"
23
32
  coverage: "yes"
33
+ - ruby: "3.2"
24
34
  env:
25
35
  COVERAGE: ${{ matrix.coverage }}
36
+ # https://github.com/rubygems/rubygems/issues/5234#issuecomment-1003773622
37
+ RUBYOPT: '--disable-did_you_mean'
26
38
  name: RSpec - Ruby ${{ matrix.ruby }}
27
39
  steps:
28
- - uses: actions/checkout@v3
40
+ - uses: actions/checkout@v4
29
41
  - name: Install Ruby ${{ matrix.ruby }}
30
42
  uses: ruby/setup-ruby@v1
31
43
  with:
@@ -34,4 +46,13 @@ jobs:
34
46
  - name: spec tests
35
47
  run: bundle exec rake test
36
48
  - name: Verify gem builds
37
- run: gem build *.gemspec
49
+ run: gem build --strict --verbose *.gemspec
50
+
51
+ tests:
52
+ needs:
53
+ - rubocop
54
+ - rspec
55
+ runs-on: ubuntu-latest
56
+ name: Test suite
57
+ steps:
58
+ - run: echo Test suite completed
data/.rubocop.yml CHANGED
@@ -1,35 +1,5 @@
1
+ ---
1
2
  inherit_from: .rubocop_todo.yml
2
3
 
3
- # we still support ruby 1.8
4
- Style/HashSyntax:
5
- Enabled: false
6
-
7
- #Metric cops are rarely useful
8
- Metrics/AbcSize:
9
- Enabled: false
10
-
11
- Metrics/CyclomaticComplexity:
12
- Enabled: false
13
-
14
- Metrics/LineLength:
15
- Enabled: false
16
-
17
- Metrics/MethodLength:
18
- Enabled: false
19
-
20
- Metrics/BlockLength:
21
- Exclude:
22
- - spec/**/*_spec.rb
23
- - ./*.gemspec
24
-
25
- Metrics/PerceivedComplexity:
26
- Enabled: false
27
-
28
- Metrics/ModuleLength:
29
- Max: 185
30
-
31
- Style/TrailingCommaInHashLiteral:
32
- EnforcedStyleForMultiline: consistent_comma
33
-
34
- Style/AccessModifierDeclarations:
35
- Enabled: false
4
+ inherit_gem:
5
+ voxpupuli-rubocop: rubocop.yml
data/.rubocop_todo.yml CHANGED
@@ -1,18 +1,74 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2015-10-08 14:05:42 -0700 using RuboCop version 0.34.2.
3
+ # on 2023-09-15 14:22:01 UTC using RuboCop version 1.54.2.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
9
+ # Offense count: 2
10
10
  Lint/RescueException:
11
11
  Exclude:
12
12
  - 'lib/metadata_json_lint.rb'
13
13
 
14
14
  # Offense count: 1
15
- # Configuration parameters: Exclude.
15
+ # Configuration parameters: Prefixes, AllowedPatterns.
16
+ # Prefixes: when, with, without
17
+ RSpec/ContextWording:
18
+ Exclude:
19
+ - 'spec/metadata_json_lint_spec.rb'
20
+
21
+ # Offense count: 2
22
+ # This cop supports unsafe autocorrection (--autocorrect-all).
23
+ # Configuration parameters: SkipBlocks, EnforcedStyle.
24
+ # SupportedStyles: described_class, explicit
25
+ RSpec/DescribedClass:
26
+ Exclude:
27
+ - 'spec/version_requirement_spec.rb'
28
+
29
+ # Offense count: 2
30
+ # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
31
+ # Include: **/*_spec*rb*, **/spec/**/*
32
+ RSpec/FilePath:
33
+ Exclude:
34
+ - 'spec/schema_spec.rb'
35
+ - 'spec/version_requirement_spec.rb'
36
+
37
+ # Offense count: 2
38
+ # Configuration parameters: .
39
+ # SupportedStyles: have_received, receive
40
+ RSpec/MessageSpies:
41
+ EnforcedStyle: receive
42
+
43
+ # Offense count: 2
44
+ RSpec/MultipleExpectations:
45
+ Max: 2
46
+
47
+ # Offense count: 7
48
+ # Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
49
+ # SupportedStyles: always, named_only
50
+ RSpec/NamedSubject:
51
+ Exclude:
52
+ - 'spec/schema_spec.rb'
53
+
54
+ # Offense count: 1
55
+ # Configuration parameters: AllowedConstants.
16
56
  Style/Documentation:
17
57
  Exclude:
58
+ - 'spec/**/*'
59
+ - 'test/**/*'
18
60
  - 'lib/metadata_json_lint.rb'
61
+
62
+ # Offense count: 36
63
+ # This cop supports unsafe autocorrection (--autocorrect-all).
64
+ # Configuration parameters: EnforcedStyle.
65
+ # SupportedStyles: always, always_true, never
66
+ Style/FrozenStringLiteralComment:
67
+ Enabled: false
68
+
69
+ # Offense count: 6
70
+ # This cop supports safe autocorrection (--autocorrect).
71
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
72
+ # URISchemes: http, https
73
+ Layout/LineLength:
74
+ Max: 153
data/CHANGELOG.md CHANGED
@@ -1,13 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.0.0](https://github.com/voxpupuli/metadata-json-lint/tree/4.0.0) (2023-09-15)
4
+
5
+ [Full Changelog](https://github.com/voxpupuli/metadata-json-lint/compare/3.0.3...4.0.0)
6
+
7
+ **Breaking changes:**
8
+
9
+ - Drop Ruby 2.5/2.6 & switch to voxpupuli-rubocop [\#137](https://github.com/voxpupuli/metadata-json-lint/pull/137) ([bastelfreak](https://github.com/bastelfreak))
10
+ - Drop Ruby =\< 2.4 support [\#125](https://github.com/voxpupuli/metadata-json-lint/pull/125) ([bastelfreak](https://github.com/bastelfreak))
11
+
12
+ **Implemented enhancements:**
13
+
14
+ - CI: Build gems with strictness and verbosity & Add upper version limits to gemspec [\#135](https://github.com/voxpupuli/metadata-json-lint/pull/135) ([bastelfreak](https://github.com/bastelfreak))
15
+ - Add Ruby 3.1/3.2 support [\#133](https://github.com/voxpupuli/metadata-json-lint/pull/133) ([bastelfreak](https://github.com/bastelfreak))
16
+
17
+ **Merged pull requests:**
18
+
19
+ - Update voxpupuli-rubocop requirement from ~\> 1.2 to ~\> 2.0 [\#139](https://github.com/voxpupuli/metadata-json-lint/pull/139) ([dependabot[bot]](https://github.com/apps/dependabot))
20
+ - Make semantic\_puppet a hard dependency [\#136](https://github.com/voxpupuli/metadata-json-lint/pull/136) ([bastelfreak](https://github.com/bastelfreak))
21
+ - Drop pry development dependency [\#134](https://github.com/voxpupuli/metadata-json-lint/pull/134) ([bastelfreak](https://github.com/bastelfreak))
22
+ - GCG: Add faraday-retry dep [\#132](https://github.com/voxpupuli/metadata-json-lint/pull/132) ([bastelfreak](https://github.com/bastelfreak))
23
+ - Add dummy CI job we can depend on [\#131](https://github.com/voxpupuli/metadata-json-lint/pull/131) ([bastelfreak](https://github.com/bastelfreak))
24
+
3
25
  ## [3.0.3](https://github.com/voxpupuli/metadata-json-lint/tree/3.0.3) (2023-04-24)
4
26
 
5
27
  [Full Changelog](https://github.com/voxpupuli/metadata-json-lint/compare/3.0.2...3.0.3)
6
28
 
29
+ **Fixed bugs:**
30
+
31
+ - gemspec: drop deprecated `date` attribute [\#129](https://github.com/voxpupuli/metadata-json-lint/pull/129) ([bastelfreak](https://github.com/bastelfreak))
32
+
7
33
  **Merged pull requests:**
8
34
 
9
- - Allow json-schema 4.x [\#122](https://github.com/voxpupuli/metadata-json-lint/pull/122)
10
- - gemspec: drop deprecated date attribute [\#129](https://github.com/voxpupuli/metadata-json-lint/pull/129)
35
+ - Allow json-schema 4.x [\#128](https://github.com/voxpupuli/metadata-json-lint/pull/128) ([chelnak](https://github.com/chelnak))
11
36
 
12
37
  ## [3.0.2](https://github.com/voxpupuli/metadata-json-lint/tree/3.0.2) (2022-05-03)
13
38
 
data/Gemfile CHANGED
@@ -3,10 +3,11 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :release do
6
- gem 'github_changelog_generator', :require => false
6
+ gem 'faraday-retry', require: false
7
+ gem 'github_changelog_generator', require: false
7
8
  end
8
9
 
9
10
  group :coverage, optional: ENV['COVERAGE'] != 'yes' do
10
- gem 'codecov', :require => false
11
- gem 'simplecov-console', :require => false
11
+ gem 'codecov', require: false
12
+ gem 'simplecov-console', require: false
12
13
  end
data/Rakefile CHANGED
@@ -1,17 +1,16 @@
1
1
  desc 'Run all tests'
2
- task :test => %i[rubocop spec test:acceptance]
2
+ task test: %i[spec test:acceptance]
3
3
 
4
- require 'rubocop/rake_task'
5
- RuboCop::RakeTask.new(:rubocop) do |task|
6
- # These make the rubocop experience maybe slightly less terrible
7
- task.options = ['-D', '-S', '-E']
8
-
9
- # Use Rubocop's Github Actions formatter if possible
10
- if ENV['GITHUB_ACTIONS'] == 'true'
11
- rubocop_spec = Gem::Specification.find_by_name('rubocop')
12
- if Gem::Version.new(rubocop_spec.version) >= Gem::Version.new('1.2')
13
- task.formatters << 'github'
14
- end
4
+ begin
5
+ require 'rubocop/rake_task'
6
+ rescue LoadError
7
+ # RuboCop is an optional group
8
+ else
9
+ RuboCop::RakeTask.new(:rubocop) do |task|
10
+ # These make the rubocop experience maybe slightly less terrible
11
+ task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
12
+ # Use Rubocop's Github Actions formatter if possible
13
+ task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
15
14
  end
16
15
  end
17
16
 
@@ -28,10 +27,11 @@ RSpec::Core::RakeTask.new(:spec)
28
27
  begin
29
28
  require 'rubygems'
30
29
  require 'github_changelog_generator/task'
31
- rescue LoadError # rubocop:disable Lint/HandleExceptions
30
+ rescue LoadError
31
+ # github_changelog_generator is in the optional `release` group
32
32
  else
33
33
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
34
- config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog]
34
+ config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog github_actions]
35
35
  config.user = 'voxpupuli'
36
36
  config.project = 'metadata-json-lint'
37
37
  gem_version = Gem::Specification.load("#{config.project}.gemspec").version
@@ -5,7 +5,5 @@ require 'json'
5
5
 
6
6
  desc 'Run metadata-json-lint'
7
7
  task :metadata_lint do
8
- if File.exist?('metadata.json')
9
- abort unless MetadataJsonLint.parse('metadata.json')
10
- end
8
+ abort if File.exist?('metadata.json') && !MetadataJsonLint.parse('metadata.json')
11
9
  end
@@ -4,8 +4,7 @@ module MetadataJsonLint
4
4
  # Provides validation of metadata.json against a JSON schema document
5
5
  # maintained in this class. Provides a good first pass over the metadata with
6
6
  # type checking and basic format/length validations.
7
- #
8
- # rubocop:disable Metrics/ClassLength # schema data structure is quite large
7
+ ## schema data structure is quite large
9
8
  class Schema
10
9
  # Based on https://docs.puppet.com/puppet/latest/modules_metadata.html
11
10
  #
@@ -159,9 +158,9 @@ module MetadataJsonLint
159
158
  raise JSON::Schema::CustomFormatError, "must be a valid semantic version: #{e.message}"
160
159
  end
161
160
  elsif value.match(semver_full_regex).nil?
162
- raise JSON::Schema::CustomFormatError, "must be a valid semantic version: Unable to parse '#{value}' as a semantic version identifier"
161
+ raise JSON::Schema::CustomFormatError,
162
+ "must be a valid semantic version: Unable to parse '#{value}' as a semantic version identifier"
163
163
  end
164
164
  end
165
165
  end
166
166
  end
167
- # rubocop:enable Metrics/ClassLength
@@ -7,7 +7,10 @@ module MetadataJsonLint
7
7
 
8
8
  if defined?(SemanticPuppet::VersionRange)
9
9
  @range = SemanticPuppet::VersionRange.parse(requirement)
10
- raise ArgumentError, "Range matches no versions: \"#{requirement}\"" if @range == SemanticPuppet::VersionRange::EMPTY_RANGE
10
+ if @range == SemanticPuppet::VersionRange::EMPTY_RANGE
11
+ raise ArgumentError,
12
+ "Range matches no versions: \"#{requirement}\""
13
+ end
11
14
  elsif requirement.match(/\A[a-z0-9*.\-^~><=|\t ]*\Z/i).nil?
12
15
  raise ArgumentError, "Unparsable version range: \"#{requirement}\""
13
16
  end
@@ -1,9 +1,7 @@
1
1
  require 'json'
2
2
  require 'spdx-licenses'
3
3
  require 'optparse'
4
-
5
- require 'metadata-json-lint/semantic_puppet_loader'
6
- MetadataJsonLint::SemanticPuppetLoader.try_load
4
+ require 'semantic_puppet'
7
5
 
8
6
  require 'metadata-json-lint/schema'
9
7
  require 'metadata-json-lint/version_requirement'
@@ -17,7 +15,7 @@ module MetadataJsonLint
17
15
  :strict_license,
18
16
  :strict_dependencies,
19
17
  :strict_puppet_version,
20
- :format
18
+ :format,
21
19
  ).new(
22
20
  true, # fail_on_warnings
23
21
  true, # strict_license
@@ -32,11 +30,13 @@ module MetadataJsonLint
32
30
  OptionParser.new do |opts|
33
31
  opts.banner = 'Usage: metadata-json-lint [options] [metadata.json]'
34
32
 
35
- opts.on('--[no-]strict-dependencies', "Fail on open-ended module version dependencies. Defaults to '#{options[:strict_dependencies]}'.") do |v|
33
+ opts.on('--[no-]strict-dependencies',
34
+ "Fail on open-ended module version dependencies. Defaults to '#{options[:strict_dependencies]}'.") do |v|
36
35
  options[:strict_dependencies] = v
37
36
  end
38
37
 
39
- opts.on('--[no-]strict-license', "Don't fail on strict license check. Defaults to '#{options[:strict_license]}'.") do |v|
38
+ opts.on('--[no-]strict-license',
39
+ "Don't fail on strict license check. Defaults to '#{options[:strict_license]}'.") do |v|
40
40
  options[:strict_license] = v
41
41
  end
42
42
 
@@ -44,11 +44,13 @@ module MetadataJsonLint
44
44
  options[:fail_on_warnings] = v
45
45
  end
46
46
 
47
- opts.on('--[no-]strict-puppet-version', "Fail on strict Puppet Version check based on current supported Puppet versions. Defaults to '#{options[:strict_puppet_version]}'.") do |v|
47
+ opts.on('--[no-]strict-puppet-version',
48
+ "Fail on strict Puppet Version check based on current supported Puppet versions. Defaults to '#{options[:strict_puppet_version]}'.") do |v|
48
49
  options[:strict_puppet_version] = v
49
50
  end
50
51
 
51
- opts.on('-f', '--format FORMAT', %i[text json], 'The format in which results will be output (text, json)') do |format|
52
+ opts.on('-f', '--format FORMAT', %i[text json],
53
+ 'The format in which results will be output (text, json)') do |format|
52
54
  options[:format] = format
53
55
  end
54
56
  end.parse!
@@ -90,7 +92,7 @@ module MetadataJsonLint
90
92
  # Validate basic structure against JSON schema
91
93
  schema_errors = Schema.new.validate(parsed)
92
94
  schema_errors.each do |err|
93
- error (err[:field] == 'root' ? :required_fields : err[:field]), err[:message]
95
+ error ((err[:field] == 'root') ? :required_fields : err[:field]), err[:message]
94
96
  end
95
97
 
96
98
  validate_dependencies!(parsed['dependencies']) if parsed['dependencies']
@@ -99,9 +101,7 @@ module MetadataJsonLint
99
101
  # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
100
102
  deprecated_fields = %w[types checksum]
101
103
  deprecated_fields.each do |field|
102
- unless parsed[field].nil?
103
- error :deprecated_fields, "Deprecated field '#{field}' found in metadata.json."
104
- end
104
+ error :deprecated_fields, "Deprecated field '#{field}' found in metadata.json." unless parsed[field].nil?
105
105
  end
106
106
 
107
107
  # The nested 'requirements' name of 'pe' is deprecated as well.
@@ -121,16 +121,14 @@ module MetadataJsonLint
121
121
 
122
122
  case options[:format]
123
123
  when :json
124
- puts JSON.fast_generate(:result => result, :warnings => @warnings, :errors => @errors)
124
+ puts JSON.fast_generate(result: result, warnings: @warnings, errors: @errors)
125
125
  else
126
126
  @warnings.each { |warn| puts "(WARN) #{warn}" }
127
127
  @errors.each { |err| puts "(ERROR) #{err}" }
128
128
  puts result
129
129
  end
130
130
 
131
- if !@errors.empty? || (!@warnings.empty? && (options[:fail_on_warnings] == true))
132
- return false
133
- end
131
+ return false if !@errors.empty? || (!@warnings.empty? && (options[:fail_on_warnings] == true))
134
132
  end
135
133
 
136
134
  true
@@ -153,9 +151,7 @@ module MetadataJsonLint
153
151
  return unless requirements.is_a?(Array)
154
152
 
155
153
  requirements.each do |requirement|
156
- if requirement['name'] == 'pe'
157
- warn :requirements, "The 'pe' requirement is no longer supported by the Forge."
158
- end
154
+ warn :requirements, "The 'pe' requirement is no longer supported by the Forge." if requirement['name'] == 'pe'
159
155
 
160
156
  begin
161
157
  puppet_req = VersionRequirement.new(requirement.fetch('version_requirement', ''))
@@ -164,7 +160,7 @@ module MetadataJsonLint
164
160
  error :requirements, "Invalid 'version_requirement' field in metadata.json: #{e}"
165
161
  end
166
162
 
167
- validate_puppet_ver!(puppet_req) unless puppet_req.instance_variable_get('@requirement').nil?
163
+ validate_puppet_ver!(puppet_req) unless puppet_req.instance_variable_get(:@requirement).nil?
168
164
  end
169
165
 
170
166
  validate_requirements_unique(requirements)
@@ -181,17 +177,16 @@ module MetadataJsonLint
181
177
  end
182
178
 
183
179
  return unless requirement.mixed_syntax?
180
+
184
181
  warn(:requirement, 'Mixing "x" or "*" version syntax with operators is not recommended in ' \
185
- "metadata.json, use one style in the puppet version: #{requirement.instance_variable_get('@requirement')}")
182
+ "metadata.json, use one style in the puppet version: #{requirement.instance_variable_get(:@requirement)}")
186
183
  end
187
184
  module_function :validate_puppet_ver!
188
185
 
189
186
  def validate_dependencies!(deps)
190
187
  dep_names = []
191
188
  deps.each do |dep|
192
- if dep_names.include?(dep['name'])
193
- warn :dependencies, "Duplicate dependencies on #{dep['name']}"
194
- end
189
+ warn :dependencies, "Duplicate dependencies on #{dep['name']}" if dep_names.include?(dep['name'])
195
190
  dep_names << dep['name']
196
191
 
197
192
  begin
@@ -208,7 +203,7 @@ module MetadataJsonLint
208
203
  # See https://tickets.puppetlabs.com/browse/PUP-2781
209
204
  if dep.key?('version_range')
210
205
  warn :dependencies, "Dependency #{dep['name']} has a 'version_range' attribute " \
211
- 'which is no longer used by the forge.'
206
+ 'which is no longer used by the forge.'
212
207
  end
213
208
  end
214
209
  end
@@ -219,7 +214,7 @@ module MetadataJsonLint
219
214
  # From: https://docs.puppet.com/puppet/latest/reference/modules_metadata.html#best-practice-set-an-upper-bound-for-dependencies
220
215
  if options[:strict_dependencies] && requirement.open_ended?
221
216
  msg = "Dependency #{dep['name']} has an open " \
222
- "ended dependency version requirement #{dep['version_requirement']}"
217
+ "ended dependency version requirement #{dep['version_requirement']}"
223
218
  warn(:dependencies, msg)
224
219
  end
225
220
 
@@ -227,15 +222,16 @@ module MetadataJsonLint
227
222
  # From: https://docs.puppet.com/puppet/latest/modules_metadata.html#version-specifiers
228
223
  # Supported in Puppet 5 and higher, but the syntax is unclear and incompatible with older versions
229
224
  return unless requirement.mixed_syntax?
225
+
230
226
  warn(:dependencies, 'Mixing "x" or "*" version syntax with operators is not recommended in ' \
231
- "metadata.json, use one style in the #{dep['name']} dependency: #{dep['version_requirement']}")
227
+ "metadata.json, use one style in the #{dep['name']} dependency: #{dep['version_requirement']}")
232
228
  end
233
229
  module_function :validate_version_requirement!
234
230
 
235
231
  def format_error(check, msg)
236
232
  case options[:format]
237
233
  when :json
238
- { :check => check, :msg => msg }
234
+ { check: check, msg: msg }
239
235
  else
240
236
  "#{check}: #{msg}"
241
237
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'metadata-json-lint'
3
- s.version = '3.0.3'
3
+ s.version = '4.0.0'
4
4
  s.summary = 'metadata-json-lint /path/to/metadata.json'
5
5
  s.description = 'Utility to verify Puppet metadata.json files'
6
6
  s.authors = ['Vox Pupuli']
@@ -8,17 +8,16 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.files = `git ls-files -z`.split("\x0")
10
10
  s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
11
- s.test_files = s.files.grep(%r{^(tests|spec)/})
12
11
 
13
12
  s.homepage = 'https://github.com/voxpupuli/metadata-json-lint'
14
13
  s.license = 'Apache-2.0'
15
14
 
16
- s.required_ruby_version = '>= 2.1.0'
15
+ s.required_ruby_version = '>= 2.7.0'
16
+
17
17
  s.add_runtime_dependency 'json-schema', '>= 2.8', '< 5.0'
18
+ s.add_runtime_dependency 'semantic_puppet', '~> 1.0'
18
19
  s.add_runtime_dependency 'spdx-licenses', '~> 1.0'
19
- s.add_development_dependency 'pry'
20
- s.add_development_dependency 'rake'
21
- s.add_development_dependency 'rspec'
22
- s.add_development_dependency 'rubocop', '~> 0.57.2'
23
- s.add_development_dependency 'semantic_puppet'
20
+ s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
21
+ s.add_development_dependency 'rspec', '~> 3.12'
22
+ s.add_development_dependency 'voxpupuli-rubocop', '~> 2.0'
24
23
  end
@@ -11,12 +11,13 @@ describe MetadataJsonLint do
11
11
  context 'with pe' do
12
12
  let :requirements do
13
13
  [
14
- { 'name' => 'pe' }
14
+ { 'name' => 'pe' },
15
15
  ]
16
16
  end
17
17
 
18
18
  it do
19
- expect(described_class).to receive('warn').with(:requirements, "The 'pe' requirement is no longer supported by the Forge.")
19
+ expect(described_class).to receive('warn').with(:requirements,
20
+ "The 'pe' requirement is no longer supported by the Forge.")
20
21
  expect { described_class.validate_requirements!(requirements) }.not_to raise_error
21
22
  end
22
23
  end
@@ -24,12 +25,13 @@ describe MetadataJsonLint do
24
25
  context 'with invalid requirement' do
25
26
  let :requirements do
26
27
  [
27
- { 'name' => 'puppet', 'version_requirement' => 'a' }
28
+ { 'name' => 'puppet', 'version_requirement' => 'a' },
28
29
  ]
29
30
  end
30
31
 
31
32
  it do
32
- expect(described_class).to receive('error').with(:requirements, "Invalid 'version_requirement' field in metadata.json: Unparsable version range: \"a\"")
33
+ expect(described_class).to receive('error').with(:requirements,
34
+ "Invalid 'version_requirement' field in metadata.json: Unparsable version range: \"a\"")
33
35
  expect { described_class.validate_requirements!(requirements) }.not_to raise_error
34
36
  end
35
37
  end
data/spec/schema_spec.rb CHANGED
@@ -4,10 +4,13 @@ describe MetadataJsonLint::Schema do
4
4
  end
5
5
 
6
6
  describe '#validate' do
7
- let(:minimal) { { author: '', dependencies: [], license: 'A', name: 'a-a', source: '', summary: '', version: '1.0.0' } }
7
+ let(:minimal) do
8
+ { author: '', dependencies: [], license: 'A', name: 'a-a', source: '', summary: '', version: '1.0.0' }
9
+ end
8
10
 
9
11
  context 'with empty hash' do
10
12
  subject { described_class.new.validate({}) }
13
+
11
14
  it { is_expected.to be_a(Array) }
12
15
  it { expect(subject.size).to eq(7) }
13
16
  it { is_expected.to include(field: 'root', message: "The file did not contain a required property of 'author'") }
@@ -15,24 +18,39 @@ describe MetadataJsonLint::Schema do
15
18
 
16
19
  context 'with minimal entries' do
17
20
  subject { described_class.new.validate(minimal) }
21
+
18
22
  it { is_expected.to eq([]) }
19
23
  end
20
24
 
21
25
  context 'with validation error on entry' do
22
26
  subject { described_class.new.validate(minimal.merge(summary: 'A' * 145)) }
23
- it { is_expected.to eq([{ field: 'summary', message: "The property 'summary' was not of a maximum string length of 144" }]) }
27
+
28
+ it {
29
+ expect(subject).to eq([{ field: 'summary',
30
+ message: "The property 'summary' was not of a maximum string length of 144", }])
31
+ }
24
32
  end
25
33
 
26
34
  context 'with validation error on nested entry' do
27
35
  subject { described_class.new.validate(minimal.merge(dependencies: [{ name: 'in###id' }])) }
36
+
28
37
  it { expect(subject.size).to eq(1) }
29
- it { is_expected.to include(field: 'dependencies', message: a_string_matching(%r{The property 'dependencies/0/name' value "in###id" did not match the regex})) }
38
+
39
+ it {
40
+ expect(subject).to include(field: 'dependencies',
41
+ message: a_string_matching(%r{The property 'dependencies/0/name' value "in###id" did not match the regex}))
42
+ }
30
43
  end
31
44
 
32
45
  context 'with semver validation failure' do
33
46
  subject { described_class.new.validate(minimal.merge(version: 'a')) }
47
+
34
48
  it { expect(subject.size).to eq(1) }
35
- it { is_expected.to include(field: 'version', message: a_string_matching(/The property 'version' must be a valid semantic version/)) }
49
+
50
+ it {
51
+ expect(subject).to include(field: 'version',
52
+ message: a_string_matching(/The property 'version' must be a valid semantic version/))
53
+ }
36
54
  end
37
55
  end
38
56
  end
data/spec/spec_helper.rb CHANGED
@@ -2,7 +2,7 @@ begin
2
2
  require 'simplecov'
3
3
  require 'simplecov-console'
4
4
  require 'codecov'
5
- rescue LoadError # rubocop:disable Lint/HandleExceptions
5
+ rescue LoadError
6
6
  else
7
7
  SimpleCov.start do
8
8
  track_files 'lib/**/*.rb'
@@ -18,7 +18,7 @@ else
18
18
 
19
19
  SimpleCov.formatters = [
20
20
  SimpleCov::Formatter::Console,
21
- SimpleCov::Formatter::Codecov
21
+ SimpleCov::Formatter::Codecov,
22
22
  ]
23
23
  end
24
24
 
@@ -1 +1 @@
1
- Error: Unable to parse metadata.json: [0-9]*: unexpected token at
1
+ Error: Unable to parse metadata.json:.* unexpected token at
@@ -1,7 +1,7 @@
1
1
  $LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
2
2
  require 'metadata-json-lint/rake_task'
3
3
 
4
- task :test => %i[metadata_lint success]
4
+ task test: %i[metadata_lint success]
5
5
  task :success do
6
6
  puts 'Successfully linted'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata-json-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-24 00:00:00.000000000 Z
11
+ date: 2023-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -31,7 +31,7 @@ dependencies:
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
- name: spdx-licenses
34
+ name: semantic_puppet
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
@@ -45,75 +45,67 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: pry
48
+ name: spdx-licenses
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">="
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
53
+ version: '1.0'
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '1.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- version: '0'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - ">="
65
+ - - "~>"
73
66
  - !ruby/object:Gem::Version
74
- version: '0'
75
- - !ruby/object:Gem::Dependency
76
- name: rspec
77
- requirement: !ruby/object:Gem::Requirement
78
- requirements:
67
+ version: '13.0'
79
68
  - - ">="
80
69
  - !ruby/object:Gem::Version
81
- version: '0'
70
+ version: 13.0.6
82
71
  type: :development
83
72
  prerelease: false
84
73
  version_requirements: !ruby/object:Gem::Requirement
85
74
  requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '13.0'
86
78
  - - ">="
87
79
  - !ruby/object:Gem::Version
88
- version: '0'
80
+ version: 13.0.6
89
81
  - !ruby/object:Gem::Dependency
90
- name: rubocop
82
+ name: rspec
91
83
  requirement: !ruby/object:Gem::Requirement
92
84
  requirements:
93
85
  - - "~>"
94
86
  - !ruby/object:Gem::Version
95
- version: 0.57.2
87
+ version: '3.12'
96
88
  type: :development
97
89
  prerelease: false
98
90
  version_requirements: !ruby/object:Gem::Requirement
99
91
  requirements:
100
92
  - - "~>"
101
93
  - !ruby/object:Gem::Version
102
- version: 0.57.2
94
+ version: '3.12'
103
95
  - !ruby/object:Gem::Dependency
104
- name: semantic_puppet
96
+ name: voxpupuli-rubocop
105
97
  requirement: !ruby/object:Gem::Requirement
106
98
  requirements:
107
- - - ">="
99
+ - - "~>"
108
100
  - !ruby/object:Gem::Version
109
- version: '0'
101
+ version: '2.0'
110
102
  type: :development
111
103
  prerelease: false
112
104
  version_requirements: !ruby/object:Gem::Requirement
113
105
  requirements:
114
- - - ">="
106
+ - - "~>"
115
107
  - !ruby/object:Gem::Version
116
- version: '0'
108
+ version: '2.0'
117
109
  description: Utility to verify Puppet metadata.json files
118
110
  email: voxpupuli@groups.io
119
111
  executables:
@@ -137,7 +129,6 @@ files:
137
129
  - bin/metadata-json-lint
138
130
  - lib/metadata-json-lint/rake_task.rb
139
131
  - lib/metadata-json-lint/schema.rb
140
- - lib/metadata-json-lint/semantic_puppet_loader.rb
141
132
  - lib/metadata-json-lint/version_requirement.rb
142
133
  - lib/metadata_json_lint.rb
143
134
  - metadata-json-lint.gemspec
@@ -225,7 +216,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
216
  requirements:
226
217
  - - ">="
227
218
  - !ruby/object:Gem::Version
228
- version: 2.1.0
219
+ version: 2.7.0
229
220
  required_rubygems_version: !ruby/object:Gem::Requirement
230
221
  requirements:
231
222
  - - ">="
@@ -236,76 +227,4 @@ rubygems_version: 3.2.33
236
227
  signing_key:
237
228
  specification_version: 4
238
229
  summary: metadata-json-lint /path/to/metadata.json
239
- test_files:
240
- - spec/metadata_json_lint_spec.rb
241
- - spec/schema_spec.rb
242
- - spec/spec_helper.rb
243
- - spec/version_requirement_spec.rb
244
- - tests/bad_license/Rakefile
245
- - tests/bad_license/expected
246
- - tests/bad_license/metadata.json
247
- - tests/broken/Rakefile
248
- - tests/broken/expected
249
- - tests/broken/metadata.json
250
- - tests/duplicate-dep/Rakefile
251
- - tests/duplicate-dep/expected
252
- - tests/duplicate-dep/metadata.json
253
- - tests/duplicate-requirement/Rakefile
254
- - tests/duplicate-requirement/expected
255
- - tests/duplicate-requirement/metadata.json
256
- - tests/json_format/Rakefile
257
- - tests/json_format/expected
258
- - tests/json_format/metadata.json
259
- - tests/long_summary/Rakefile
260
- - tests/long_summary/expected
261
- - tests/long_summary/metadata.json
262
- - tests/missing_version_requirement/Rakefile
263
- - tests/missing_version_requirement/expected
264
- - tests/missing_version_requirement/metadata.json
265
- - tests/mixed_version_syntax/Rakefile
266
- - tests/mixed_version_syntax/expected
267
- - tests/mixed_version_syntax/metadata.json
268
- - tests/multiple_problems/Rakefile
269
- - tests/multiple_problems/expected
270
- - tests/multiple_problems/metadata.json
271
- - tests/no_dependencies/Rakefile
272
- - tests/no_dependencies/metadata.json
273
- - tests/no_files/.gitkeep
274
- - tests/no_files/expected
275
- - tests/no_pe/Rakefile
276
- - tests/no_pe/metadata.json
277
- - tests/no_version_range/Rakefile
278
- - tests/no_version_range/metadata.json
279
- - tests/non_array_requirements/Rakefile
280
- - tests/non_array_requirements/expected
281
- - tests/non_array_requirements/metadata.json
282
- - tests/noname/Rakefile
283
- - tests/noname/expected
284
- - tests/noname/metadata.json
285
- - tests/open_ended_dependency/Rakefile
286
- - tests/open_ended_dependency/expected
287
- - tests/open_ended_dependency/metadata.json
288
- - tests/perfect/Rakefile
289
- - tests/perfect/metadata.json
290
- - tests/proprietary/Rakefile
291
- - tests/proprietary/metadata.json
292
- - tests/rake_chaining/Rakefile
293
- - tests/rake_chaining/metadata.json
294
- - tests/rake_global_options/Rakefile
295
- - tests/rake_global_options/expected
296
- - tests/rake_global_options/metadata.json
297
- - tests/rake_multiple_json_options/Rakefile
298
- - tests/rake_multiple_json_options/metadata_license.json
299
- - tests/rake_multiple_json_options/metadata_ok.json
300
- - tests/requirements_eol_version/Rakefile
301
- - tests/requirements_eol_version/expected
302
- - tests/requirements_eol_version/metadata.json
303
- - tests/tags_no_array/Rakefile
304
- - tests/tags_no_array/expected
305
- - tests/tags_no_array/metadata.json
306
- - tests/tags_with_array/Rakefile
307
- - tests/tags_with_array/metadata.json
308
- - tests/test.sh
309
- - tests/types/Rakefile
310
- - tests/types/expected
311
- - tests/types/metadata.json
230
+ test_files: []
@@ -1,47 +0,0 @@
1
- module MetadataJsonLint
2
- # Attempts the various methods of loading SemanticPuppet.
3
- module SemanticPuppetLoader
4
- def try_load
5
- try_load_puppet
6
- return if defined?(SemanticPuppet)
7
-
8
- try_load_semantic
9
- return if defined?(SemanticPuppet)
10
-
11
- try_load_semantic_puppet
12
- return if defined?(SemanticPuppet)
13
-
14
- warn 'Could not find semantic_puppet gem, falling back to internal functionality. Version checks may be less robust.'
15
- end
16
- module_function :try_load
17
-
18
- # Most modern Puppet versions have SemanticPuppet vendored in the proper
19
- # namespace and automatically load it at require time.
20
- def try_load_puppet
21
- require 'puppet'
22
- rescue LoadError
23
- nil
24
- end
25
- module_function :try_load_puppet
26
-
27
- # Older Puppet 4.x versions have SemanticPuppet vendored but under the
28
- # Semantic namespace and require it on demand, so we need to load it
29
- # ourselves and then alias it to SemanticPuppet for convenience.
30
- def try_load_semantic
31
- require 'semantic'
32
- Kernel.const_set('SemanticPuppet', Semantic)
33
- rescue LoadError
34
- nil
35
- end
36
- module_function :try_load_semantic
37
-
38
- # If Puppet is not available or is a version that does not have
39
- # SemanticPuppet vendored, try to load the external gem.
40
- def try_load_semantic_puppet
41
- require 'semantic_puppet'
42
- rescue LoadError
43
- nil
44
- end
45
- module_function :try_load_semantic_puppet
46
- end
47
- end