metadata-json-lint 0.0.11 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cc99aac134e5318ffd0f79339b1f972cc554e024
4
- data.tar.gz: 3fd67ef0b5c0fcd45867a8a9f8d0f7b57d9c3dc4
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTU0NDFiYzdkYTJjZTg1NjFkODEwZmE5MzZlYTI3ZGM4NjkyMjQ0Zg==
5
+ data.tar.gz: !binary |-
6
+ OThlNDFiYmFiYmY2MWNjMjA5ODg4NjVkYzk4NzRmMDhiZDIwZmQzZg==
5
7
  SHA512:
6
- metadata.gz: a67148113bdbd5eb661fe21ce0c8264d44a81d16c5a3d5a80e8ff015d41f767a17ccfd114587ccd7770c79827f36034d63f5e69899195dd9e7201f5ae8bb8632
7
- data.tar.gz: 99294678081f996adf170dc0a9cb06bf96671eb4a9d542e6f6fc23a63ff92492e2d514e9f38ef2713e8569996b5299e7270fae2c73349186350bb6b505d31723
8
+ metadata.gz: !binary |-
9
+ Y2Q2ODE4NTc2OTJmYmEzYTQzZDRmOTg0NzJkYThiNDlhZTMxMmQ4OTNiMDFj
10
+ YTU3OTI4ODAwODRlYWMxZTk1ZjdlN2ZmZTE4Y2YzNGU3OTI2YzI0MmI3Mjgy
11
+ ZDUxZjA0NDVlNDgzNGIwMzM3YzQ4NDkwMTE5NTNmYmJkZTY4YjQ=
12
+ data.tar.gz: !binary |-
13
+ ODE4MmNmY2ZjYmFhNTY1YTkwNTNmYmYxNGM0ZjU2YzRhMTM2ODRjYThhNzcy
14
+ N2NhYTc3MjgwN2Y4ZWZlYjIwZWVjNzM4ZGZkZDNjY2UyNWYxZDc0MTAyNDA0
15
+ YjdlOGMxM2ViNjBkNzhmNmJjMWNjN2NkYjk5ZDJmYmQxZTJkZDA=
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  lib = File.expand_path('../../lib', __FILE__)
4
- $:.unshift(lib) unless $:.include?(lib)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
- require "metadata_json_lint"
6
+ require 'metadata_json_lint'
7
7
 
8
8
  MetadataJsonLint.run
@@ -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
- MetadataJsonLint.parse('metadata.json')
10
- end
8
+ MetadataJsonLint.parse('metadata.json') if File.exist?('metadata.json')
11
9
  end
@@ -1,32 +1,36 @@
1
1
  require 'json'
2
2
  require 'spdx-licenses'
3
3
  require 'optparse'
4
+ require 'semantic_puppet'
4
5
 
5
6
  module MetadataJsonLint
6
7
  def options
7
8
  @options ||= {
8
- :fail_on_warnings => true,
9
- :strict_license => true
9
+ :fail_on_warnings => true,
10
+ :strict_license => true,
11
+ :strict_dependencies => false
10
12
  }
11
13
  end
12
14
  module_function :options
13
15
 
14
16
  def run
15
17
  OptionParser.new do |opts|
16
- opts.banner = "Usage: metadata-json-lint [options] metadata.json"
18
+ opts.banner = 'Usage: metadata-json-lint [options] metadata.json'
17
19
 
18
- opts.on("--[no-]strict-license", "Don't fail on strict license check") do |v|
20
+ opts.on('--[no-]strict-dependencies', 'Fail on open-ended module version dependencies') do |v|
21
+ options[:strict_dependencies] = v
22
+ end
23
+
24
+ opts.on('--[no-]strict-license', "Don't fail on strict license check") do |v|
19
25
  options[:strict_license] = v
20
26
  end
21
27
 
22
- opts.on("--[no-]fail-on-warnings", "Fail on any warnings") do |v|
28
+ opts.on('--[no-]fail-on-warnings', 'Fail on any warnings') do |v|
23
29
  options[:fail_on_warnings] = v
24
30
  end
25
31
  end.parse!
26
32
 
27
- if ARGV[0].nil?
28
- abort("Error: Must provide a metadata.json file to parse")
29
- end
33
+ abort('Error: Must provide a metadata.json file to parse') if ARGV[0].nil?
30
34
 
31
35
  MetadataJsonLint.parse(ARGV.first)
32
36
  end
@@ -45,7 +49,7 @@ module MetadataJsonLint
45
49
  # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
46
50
  error_state = false
47
51
 
48
- required_fields = [ "name", "version", "author", "license", "summary", "source", "dependencies" ]
52
+ required_fields = %w(name version author license summary source dependencies)
49
53
 
50
54
  required_fields.each do |field|
51
55
  if parsed[field].nil?
@@ -54,23 +58,15 @@ module MetadataJsonLint
54
58
  end
55
59
  end
56
60
 
57
- deps = parsed['dependencies']
58
- dep_names = []
59
- deps.each do |dep|
60
- if dep_names.include?(dep['name'])
61
- puts "Error: duplicate dependencies on #{dep['name']}"
62
- error_state = true
63
- end
64
- dep_names << dep['name']
65
- end
61
+ error_state ||= invalid_dependencies?(parsed['dependencies']) if parsed['dependencies']
66
62
 
67
63
  # Deprecated fields
68
64
  # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
69
65
 
70
- deprecated_fields = ["types", "checksum"]
66
+ deprecated_fields = %w(types checksum)
71
67
 
72
68
  deprecated_fields.each do |field|
73
- if not parsed[field].nil?
69
+ unless parsed[field].nil?
74
70
  puts "Error: Deprecated field '#{field}' found in metadata.json."
75
71
  error_state = true
76
72
  end
@@ -79,26 +75,56 @@ module MetadataJsonLint
79
75
  # Summary can not be over 144 characters:
80
76
  # From: https://forge.puppetlabs.com/razorsedge/snmp/3.3.1/scores
81
77
  if !parsed['summary'].nil? && parsed['summary'].size > 144
82
- puts "Error: summary exceeds 144 characters in metadata.json."
78
+ puts 'Error: summary exceeds 144 characters in metadata.json.'
83
79
  error_state = true
84
80
  end
85
81
 
86
82
  # Shoulds/recommendations
87
83
  # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
88
84
 
89
- if !parsed['license'].nil? && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] != "proprietary"
85
+ if !parsed['license'].nil? && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] != 'proprietary'
90
86
  puts "Warning: License identifier #{parsed['license']} is not in the SPDX list: http://spdx.org/licenses/"
91
87
  error_state = true if options[:strict_license]
92
88
  end
93
89
 
94
- if error_state
95
- if options[:fail_on_warnings] == true
96
- abort("Errors found in #{metadata}")
97
- else
98
- puts "Errors found in #{metadata}"
90
+ return unless error_state
91
+ if options[:fail_on_warnings] == true
92
+ abort("Errors found in #{metadata}")
93
+ else
94
+ puts "Errors found in #{metadata}"
95
+ end
96
+ end
97
+ module_function :parse
98
+
99
+ def invalid_dependencies?(deps)
100
+ error_state = false
101
+ dep_names = []
102
+ deps.each do |dep|
103
+ if dep_names.include?(dep['name'])
104
+ puts "Error: duplicate dependencies on #{dep['name']}"
105
+ error_state = true
106
+ end
107
+ dep_names << dep['name']
108
+
109
+ # Open ended dependency
110
+ # From: https://docs.puppet.com/puppet/latest/reference/modules_metadata.html#best-practice-set-an-upper-bound-for-dependencies
111
+ begin
112
+ next unless dep['version_requirement'].nil? || open_ended?(dep['version_requirement'])
113
+ puts "Warning: Dependency #{dep['name']} has an open " \
114
+ "ended dependency version requirement #{dep['version_requirement']}"
115
+ error_state = true if options[:strict_dependencies]
116
+ rescue ArgumentError => e
117
+ # Raised when the version_requirement provided could not be parsed
118
+ puts "Invalid 'version_requirement' field in metadata.json: #{e}"
119
+ error_state = true
99
120
  end
100
121
  end
122
+ error_state
123
+ end
124
+ module_function :invalid_dependencies?
101
125
 
126
+ def open_ended?(module_end)
127
+ SemanticPuppet::VersionRange.parse(module_end).end == SemanticPuppet::Version::MAX
102
128
  end
103
- module_function :parse
129
+ module_function :open_ended?
104
130
  end
metadata CHANGED
@@ -1,60 +1,94 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata-json-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spencer Krum
8
- - In August
8
+ - Vox Pupuli
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-09-11 00:00:00.000000000 Z
12
+ date: 2016-10-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: spdx-licenses
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
20
  version: '1.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: json
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - ! '>='
33
33
  - !ruby/object:Gem::Version
34
34
  version: '0'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ">="
39
+ - - ! '>='
40
40
  - !ruby/object:Gem::Version
41
41
  version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: semantic_puppet
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: 0.1.2
49
+ - - <
50
+ - !ruby/object:Gem::Version
51
+ version: 1.0.0
52
+ type: :runtime
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: 0.1.2
59
+ - - <
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
42
62
  - !ruby/object:Gem::Dependency
43
63
  name: rake
44
64
  requirement: !ruby/object:Gem::Requirement
45
65
  requirements:
46
- - - ">="
66
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: rubocop
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
47
81
  - !ruby/object:Gem::Version
48
82
  version: '0'
49
83
  type: :development
50
84
  prerelease: false
51
85
  version_requirements: !ruby/object:Gem::Requirement
52
86
  requirements:
53
- - - ">="
87
+ - - ! '>='
54
88
  - !ruby/object:Gem::Version
55
89
  version: '0'
56
90
  description: Utility to verify Puppet metadata.json files
57
- email: nibz@spencerkrum.com
91
+ email: voxpupuli@groups.io
58
92
  executables:
59
93
  - metadata-json-lint
60
94
  extensions: []
@@ -63,7 +97,7 @@ files:
63
97
  - bin/metadata-json-lint
64
98
  - lib/metadata-json-lint/rake_task.rb
65
99
  - lib/metadata_json_lint.rb
66
- homepage: http://github.com/nibalizer/metadata-json-lint
100
+ homepage: http://github.com/voxpupuli/metadata-json-lint
67
101
  licenses:
68
102
  - Apache-2.0
69
103
  metadata: {}
@@ -73,17 +107,17 @@ require_paths:
73
107
  - lib
74
108
  required_ruby_version: !ruby/object:Gem::Requirement
75
109
  requirements:
76
- - - ">="
110
+ - - ! '>='
77
111
  - !ruby/object:Gem::Version
78
112
  version: '0'
79
113
  required_rubygems_version: !ruby/object:Gem::Requirement
80
114
  requirements:
81
- - - ">="
115
+ - - ! '>='
82
116
  - !ruby/object:Gem::Version
83
117
  version: '0'
84
118
  requirements: []
85
119
  rubyforge_project:
86
- rubygems_version: 2.2.2
120
+ rubygems_version: 2.4.5
87
121
  signing_key:
88
122
  specification_version: 4
89
123
  summary: metadata-json-lint /path/to/metadata.json