metadata-json-lint 0.0.2 → 0.0.3
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.
- data/bin/metadata-json-lint +1 -10
- data/lib/metadata_json_lint.rb +55 -6
- metadata +39 -6
data/bin/metadata-json-lint
CHANGED
@@ -1,17 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
3
|
lib = File.expand_path('../../lib', __FILE__)
|
5
4
|
$:.unshift(lib) unless $:.include?(lib)
|
6
5
|
|
7
|
-
require "json"
|
8
6
|
require "metadata_json_lint"
|
9
|
-
#require "MetadataJsonLint"
|
10
|
-
|
11
|
-
if ARGV[0].nil?
|
12
|
-
abort("Error: Must provide a metadata.json file to parse")
|
13
|
-
end
|
14
|
-
|
15
|
-
metadata = ARGV[0]
|
16
7
|
|
17
|
-
MetadataJsonLint.
|
8
|
+
MetadataJsonLint.run
|
data/lib/metadata_json_lint.rb
CHANGED
@@ -1,14 +1,43 @@
|
|
1
|
-
|
1
|
+
require 'json'
|
2
|
+
require 'spdx-licenses'
|
3
|
+
require 'optparse'
|
2
4
|
|
3
5
|
module MetadataJsonLint
|
4
|
-
def
|
6
|
+
def run
|
7
|
+
options = {
|
8
|
+
:fail_on_warnings => true,
|
9
|
+
:strict_license => true
|
10
|
+
}
|
5
11
|
|
12
|
+
OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: metadata-json-lint [options] metadata.json"
|
14
|
+
|
15
|
+
opts.on("--[no-]strict-license", "Don't fail on strict license check") do |v|
|
16
|
+
options[:strict_license] = v
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("--[no-]fail-on-warnings", "Fail on any warnings") do |v|
|
20
|
+
options[:fail_on_warnings] = v
|
21
|
+
end
|
22
|
+
end.parse!
|
23
|
+
|
24
|
+
@options = options
|
25
|
+
|
26
|
+
if ARGV[0].nil?
|
27
|
+
abort("Error: Must provide a metadata.json file to parse")
|
28
|
+
end
|
29
|
+
|
30
|
+
MetadataJsonLint.parse(ARGV.first)
|
31
|
+
end
|
32
|
+
module_function :run
|
33
|
+
|
34
|
+
def parse(metadata)
|
6
35
|
f = File.read(metadata)
|
7
36
|
|
8
37
|
begin
|
9
38
|
parsed = JSON.parse(f)
|
10
|
-
rescue
|
11
|
-
abort("Error: Unable to parse json
|
39
|
+
rescue Exception => e
|
40
|
+
abort("Error: Unable to parse metadata.json: #{e.exception}")
|
12
41
|
end
|
13
42
|
|
14
43
|
# Fields required to be in metadata.json
|
@@ -24,7 +53,15 @@ module MetadataJsonLint
|
|
24
53
|
end
|
25
54
|
end
|
26
55
|
|
27
|
-
|
56
|
+
deps = parsed['dependencies']
|
57
|
+
dep_names = []
|
58
|
+
deps.each do |dep|
|
59
|
+
if dep_names.include?(dep['name'])
|
60
|
+
puts "Error: duplicate dependencies on #{dep['name']}"
|
61
|
+
error_state = true
|
62
|
+
end
|
63
|
+
dep_names << dep['name']
|
64
|
+
end
|
28
65
|
|
29
66
|
# Deprecated fields
|
30
67
|
# From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
|
@@ -38,10 +75,22 @@ module MetadataJsonLint
|
|
38
75
|
end
|
39
76
|
end
|
40
77
|
|
78
|
+
# Shoulds/recommendations
|
79
|
+
# From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
|
80
|
+
|
81
|
+
if !parsed['license'].nil? && !SpdxLicenses.exist?(parsed['license'])
|
82
|
+
puts "Warning: License identifier #{parsed['license']} is not in the SPDX list: http://spdx.org/licenses/"
|
83
|
+
error_state = true if @options[:strict_license]
|
84
|
+
end
|
41
85
|
|
42
86
|
if error_state
|
43
|
-
|
87
|
+
if @options[:fail_on_warnings] == true
|
88
|
+
abort("Errors found in #{metadata}")
|
89
|
+
else
|
90
|
+
puts "Errors found in #{metadata}"
|
91
|
+
end
|
44
92
|
end
|
45
93
|
|
46
94
|
end
|
95
|
+
module_function :parse
|
47
96
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metadata-json-lint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,10 +10,42 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
14
|
-
dependencies:
|
13
|
+
date: 2014-12-31 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: spdx-licenses
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '1.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '1.0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: json
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :runtime
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
15
47
|
description: Utility to verify Puppet metadata.json files
|
16
|
-
email:
|
48
|
+
email: nibz@spencerkrum.com
|
17
49
|
executables:
|
18
50
|
- metadata-json-lint
|
19
51
|
extensions: []
|
@@ -21,9 +53,9 @@ extra_rdoc_files: []
|
|
21
53
|
files:
|
22
54
|
- bin/metadata-json-lint
|
23
55
|
- lib/metadata_json_lint.rb
|
24
|
-
homepage: http://github.com/nibalizer/metadata-json-lint
|
56
|
+
homepage: http://github.com/nibalizer/metadata-json-lint
|
25
57
|
licenses:
|
26
|
-
- Apache
|
58
|
+
- Apache-2.0
|
27
59
|
post_install_message:
|
28
60
|
rdoc_options: []
|
29
61
|
require_paths:
|
@@ -47,3 +79,4 @@ signing_key:
|
|
47
79
|
specification_version: 3
|
48
80
|
summary: metadata-json-lint /path/to/metadata.json
|
49
81
|
test_files: []
|
82
|
+
has_rdoc:
|