metadata-json-lint 2.0.1 → 2.0.2

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: 14659a2f1f2f0cdbc342929c70ebe0e808cb01d1
4
- data.tar.gz: 7dac64b05c3f98bd37b69982a73178c5cfa436eb
3
+ metadata.gz: a7b70935754237914b80d9ba45e9d45172e5e34d
4
+ data.tar.gz: 6f293e3f6f818c64b8407238f0687f400dfa97ca
5
5
  SHA512:
6
- metadata.gz: a84b3571e974ecdfb133532eedcdbbcea5c4afb483f029ee2e0850b8605bb73acfbdb2af973f4b542a5ba131c05c902083f690f99c1a38889c5419b13ca12f19
7
- data.tar.gz: 838914c262be020a5dd3df0837d404068be3eead05c973094bf938efaa7bb78c0c4a6494c323ca6368887250b196e9afdb787eb79aa8891d4db7253fe3be37db
6
+ metadata.gz: a5677fe621a72e4a80cf85a76c2c11a4be29f98d27bdb0fa79aec331a68173f38ff8d5e48b4392d62a328bd990ad670ee30fd1390245811ef799440fdaaeafef
7
+ data.tar.gz: 3e2776da0adc039b30c4c4df51f7ffb60b5b233e71faa2cd5b766bdd75387665dc1c65341d1245045a3f288aea54bafc1e131ca1ffc05d772e3621c76ca1420a
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## 2.0.2
9
+
10
+ ### Changes
11
+ * Make SemanticPuppet completely optional and remove dependency on Puppet [#86](https://github.com/voxpupuli/metadata-json-lint/pull/86)
12
+ * Only log open dependency warning with --strict-dependencies [#78](https://github.com/voxpupuli/metadata-json-lint/pull/78)
13
+
14
+ ### Fixed
15
+ * Fix readme for gemfile usage [#84](https://github.com/voxpupuli/metadata-json-lint/pull/84)
16
+
8
17
  ## 2.0.1
9
18
 
10
19
  ### Changes
data/README.md CHANGED
@@ -30,7 +30,7 @@ gem install metadata-json-lint semantic_puppet
30
30
  via Gemfile:
31
31
  ``` ruby
32
32
  gem 'metadata-json-lint'
33
- gem 'semantic_puppet
33
+ gem 'semantic_puppet'
34
34
  ```
35
35
 
36
36
  ## Usage
@@ -141,10 +141,28 @@ module MetadataJsonLint
141
141
 
142
142
  private
143
143
 
144
+ def semver_full_regex
145
+ @semver_full_regex ||= begin
146
+ # Version string matching regexes
147
+ numeric = '(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)' # Major . Minor . Patch
148
+ pre = '(?:-([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Prerelease
149
+ build = '(?:\+([0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*))?' # Build
150
+ full = numeric + pre + build
151
+
152
+ /\A#{full}\Z/
153
+ end
154
+ end
155
+
144
156
  def semver_validator(value)
145
- SemanticPuppet::Version.parse(value)
146
- rescue SemanticPuppet::Version::ValidationFailure => e
147
- raise JSON::Schema::CustomFormatError, "must be a valid semantic version: #{e.message}"
157
+ if defined?(SemanticPuppet::Version)
158
+ begin
159
+ SemanticPuppet::Version.parse(value)
160
+ rescue SemanticPuppet::Version::ValidationFailure => e
161
+ raise JSON::Schema::CustomFormatError, "must be a valid semantic version: #{e.message}"
162
+ end
163
+ elsif value.match(semver_full_regex).nil?
164
+ raise JSON::Schema::CustomFormatError, "must be a valid semantic version: Unable to parse '#{value}' as a semantic version identifier"
165
+ end
148
166
  end
149
167
  end
150
168
  end
@@ -1,13 +1,15 @@
1
- require 'puppet'
2
- require 'semantic_puppet' unless Puppet.version >= '4.9.0'
3
-
4
1
  module MetadataJsonLint
5
2
  # Parses a string module version requirement with semantic_puppet and
6
3
  # provides methods to analyse it for lint warnings
7
4
  class VersionRequirement
8
5
  def initialize(requirement)
9
6
  @requirement = requirement
10
- @range = SemanticPuppet::VersionRange.parse(requirement)
7
+
8
+ if defined?(SemanticPuppet::VersionRange)
9
+ @range = SemanticPuppet::VersionRange.parse(requirement)
10
+ elsif requirement.match(/\A[a-z0-9*.\-^~><=|\t ]*\Z/i).nil?
11
+ raise ArgumentError, "Unparsable version range: \"#{requirement}\""
12
+ end
11
13
  end
12
14
 
13
15
  # Whether the range uses a comparison operator (e.g. >=) with a wildcard
@@ -26,7 +28,22 @@ module MetadataJsonLint
26
28
  end
27
29
 
28
30
  def open_ended?
29
- @range.end == SemanticPuppet::Version::MAX
31
+ if range
32
+ range.end == SemanticPuppet::Version::MAX
33
+ else
34
+ # Empty requirement strings are open-ended.
35
+ return true if requirement.strip.empty?
36
+
37
+ # Strip superfluous whitespace.
38
+ range_set = requirement.gsub(/([><=~^])(?:\s+|\s*v)/, '\1')
39
+
40
+ # Split on logical OR
41
+ ranges = range_set.split(/\s*\|\|\s*/)
42
+
43
+ # Returns true if any range includes a '>' but not a corresponding '<'
44
+ # which should be the only way to declare an open-ended range.
45
+ ranges.select { |r| r.include?('>') }.any? { |r| !r.include?('<') }
46
+ end
30
47
  end
31
48
 
32
49
  private
@@ -2,6 +2,12 @@ require 'json'
2
2
  require 'spdx-licenses'
3
3
  require 'optparse'
4
4
 
5
+ begin
6
+ require 'semantic_puppet'
7
+ rescue LoadError
8
+ $stderr.puts('Could not find semantic_puppet gem, falling back to internal functionality. Version checks may be less robust.')
9
+ end
10
+
5
11
  require 'metadata-json-lint/schema'
6
12
  require 'metadata-json-lint/version_requirement'
7
13
 
@@ -164,10 +170,10 @@ module MetadataJsonLint
164
170
  def validate_version_requirement!(dep, requirement)
165
171
  # Open ended dependency
166
172
  # From: https://docs.puppet.com/puppet/latest/reference/modules_metadata.html#best-practice-set-an-upper-bound-for-dependencies
167
- if requirement.open_ended?
173
+ if options[:strict_dependencies] && requirement.open_ended?
168
174
  msg = "Dependency #{dep['name']} has an open " \
169
175
  "ended dependency version requirement #{dep['version_requirement']}"
170
- options[:strict_dependencies] == true ? error(:dependencies, msg) : warn(:dependencies, msg)
176
+ warn(:dependencies, msg)
171
177
  end
172
178
 
173
179
  # Mixing operator and wildcard version syntax
@@ -2,7 +2,7 @@ require 'date'
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'metadata-json-lint'
5
- s.version = '2.0.1'
5
+ s.version = '2.0.2'
6
6
  s.date = Date.today.to_s
7
7
  s.summary = 'metadata-json-lint /path/to/metadata.json'
8
8
  s.description = 'Utility to verify Puppet metadata.json files'
@@ -19,14 +19,14 @@ Gem::Specification.new do |s|
19
19
  s.required_ruby_version = '>= 2.0.0'
20
20
  s.add_runtime_dependency 'spdx-licenses', '~> 1.0'
21
21
  s.add_runtime_dependency 'json-schema', '~> 2.8'
22
- s.add_runtime_dependency 'puppet', '>= 4.7.0', '< 6.0.0'
23
22
  s.add_development_dependency 'rake'
24
23
  s.add_development_dependency 'rspec'
25
24
  s.add_development_dependency 'rubocop'
26
25
  s.post_install_message = '
27
- -------------------------------------------------
28
- semantic_puppet must be installed within
29
- your Gemfile if you use Puppet <= 4.8.x!!
30
- -------------------------------------------------
26
+ ----------------------------------------------------------
27
+ For the most accurate results, the semantic_puppet
28
+ gem should be included within your Gemfile if you
29
+ use Puppet <= 4.8.x
30
+ ----------------------------------------------------------
31
31
  '
32
32
  end
@@ -112,15 +112,19 @@ test "mixed_version_syntax" $FAILURE
112
112
  # Run one with empty dependencies array, expect SUCCESS
113
113
  test "no_dependencies" $SUCCESS
114
114
 
115
- # Run one with open ended dependency, expect SUCCESS
116
- test "open_ended_dependency" $SUCCESS --no-fail-on-warnings
115
+ # Run one with open ended dependency, expect SUCCESS as strict deps is off by default
116
+ test "open_ended_dependency" $SUCCESS
117
117
  # Run one with open ended dependency and --strict-dependencies, expect FAILURE
118
118
  test "open_ended_dependency" $FAILURE --strict-dependencies
119
+ # Run one with open ended dependency and --strict-dependencies, but pass on warnings, expect SUCCESS
120
+ test "open_ended_dependency" $SUCCESS --strict-dependencies --no-fail-on-warnings
119
121
 
120
122
  # Run one with missing version_requirement and --no-strict-dependency, expect SUCCESS
121
- test "missing_version_requirement" $SUCCESS --no-fail-on-warnings
123
+ test "missing_version_requirement" $SUCCESS
122
124
  # Run one with open ended dependency and --strict-dependencies, expect FAILURE
123
125
  test "missing_version_requirement" $FAILURE --strict-dependencies
126
+ # Run one with open ended dependency and --strict-dependencies, but pass on warnings, expect SUCCESS
127
+ test "missing_version_requirement" $SUCCESS --strict-dependencies --no-fail-on-warnings
124
128
 
125
129
  # Run test for "proprietary"-licensed modules, expect SUCCESS
126
130
  test "proprietary" $SUCCESS
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: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-30 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spdx-licenses
@@ -38,26 +38,6 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.8'
41
- - !ruby/object:Gem::Dependency
42
- name: puppet
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 4.7.0
48
- - - "<"
49
- - !ruby/object:Gem::Version
50
- version: 6.0.0
51
- type: :runtime
52
- prerelease: false
53
- version_requirements: !ruby/object:Gem::Requirement
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: 4.7.0
58
- - - "<"
59
- - !ruby/object:Gem::Version
60
- version: 6.0.0
61
41
  - !ruby/object:Gem::Dependency
62
42
  name: rake
63
43
  requirement: !ruby/object:Gem::Requirement
@@ -189,8 +169,9 @@ homepage: http://github.com/voxpupuli/metadata-json-lint
189
169
  licenses:
190
170
  - Apache-2.0
191
171
  metadata: {}
192
- post_install_message: "\n -------------------------------------------------\n semantic_puppet
193
- must be installed within\n your Gemfile if you use Puppet <= 4.8.x!!\n -------------------------------------------------\n
172
+ post_install_message: "\n ----------------------------------------------------------\n
173
+ \ For the most accurate results, the semantic_puppet\n gem should be included
174
+ within your Gemfile if you\n use Puppet <= 4.8.x\n ----------------------------------------------------------\n
194
175
  \ "
195
176
  rdoc_options: []
196
177
  require_paths: