metadata-json-lint 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/metadata_json_lint.rb +52 -15
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a60434bef6d7594672b4de904d56f329d598b149
4
- data.tar.gz: bf55bd986686f7c8f9b12c1190dbe21e245d2b92
3
+ metadata.gz: 98bde19c3628ff9f087cddf19bda737480646331
4
+ data.tar.gz: 79bc0a7ba2e8f160bf57359059f000d47120d817
5
5
  SHA512:
6
- metadata.gz: 998f77de243d71dd44e5b66df7a17b8e7386de67adbc25e5c579881940d7bc2d0497e78a599a30e1c4aae0e130e9ac949236ef0654da3b96787f2fc15c7b2898
7
- data.tar.gz: bc73115194b69d677238304dd773b15c118054eb1a3ae51dfb3a284efa0e2f7cbf1992fb61a7a52f87f128ccf4514f6c6d28f148f0d27e48cbaaf44996e0a059
6
+ metadata.gz: c6897facd6d33655ff84f489373f589269ff5646e3f8977560ec9609b7235051198a9997499a1d6e9ebb7a62904471a5599bf3b16be5379ca58c836a00820bcb
7
+ data.tar.gz: 0ede3fccd32938c18df7e3da63cd52c25d9be3033c63148fb2c1146afa0d1699734ebb176bee11285a85d06d468187c6c3a9683ba980f355601ea78a5edd1725
@@ -5,11 +5,15 @@ require 'semantic_puppet'
5
5
 
6
6
  module MetadataJsonLint
7
7
  def options
8
- @options ||= {
9
- :fail_on_warnings => true,
10
- :strict_license => true,
11
- :strict_dependencies => false
12
- }
8
+ @options ||= Struct.new(
9
+ :fail_on_warnings,
10
+ :strict_license,
11
+ :strict_dependencies
12
+ ).new(
13
+ true, # fail_on_warnings
14
+ true, # strict_license
15
+ false # strict_dependencies
16
+ )
13
17
  end
14
18
  module_function :options
15
19
 
@@ -17,15 +21,15 @@ module MetadataJsonLint
17
21
  OptionParser.new do |opts|
18
22
  opts.banner = 'Usage: metadata-json-lint [options] [metadata.json]'
19
23
 
20
- opts.on('--[no-]strict-dependencies', 'Fail on open-ended module version dependencies') do |v|
24
+ opts.on('--[no-]strict-dependencies', "Fail on open-ended module version dependencies. Defaults to '#{options[:strict_dependencies]}'.") do |v|
21
25
  options[:strict_dependencies] = v
22
26
  end
23
27
 
24
- opts.on('--[no-]strict-license', "Don't fail on strict license check") do |v|
28
+ opts.on('--[no-]strict-license', "Don't fail on strict license check. Defaults to '#{options[:strict_license]}'.") do |v|
25
29
  options[:strict_license] = v
26
30
  end
27
31
 
28
- opts.on('--[no-]fail-on-warnings', 'Fail on any warnings') do |v|
32
+ opts.on('--[no-]fail-on-warnings', "Fail on any warnings. Defaults to '#{options[:fail_on_warnings]}'.") do |v|
29
33
  options[:fail_on_warnings] = v
30
34
  end
31
35
  end.parse!
@@ -45,7 +49,15 @@ module MetadataJsonLint
45
49
  module_function :run
46
50
 
47
51
  def parse(metadata)
48
- f = File.read(metadata)
52
+ # Small hack to use the module settings as defaults but allow overriding for different rake tasks
53
+ options = options().clone
54
+ # Configuration from rake tasks
55
+ yield options if block_given?
56
+ begin
57
+ f = File.read(metadata)
58
+ rescue Exception => e
59
+ abort("Error: Unable to read metadata file: #{e.exception}")
60
+ end
49
61
 
50
62
  begin
51
63
  parsed = JSON.parse(f)
@@ -53,12 +65,11 @@ module MetadataJsonLint
53
65
  abort("Error: Unable to parse metadata.json: #{e.exception}")
54
66
  end
55
67
 
56
- # Fields required to be in metadata.json
57
- # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
58
68
  error_state = false
59
69
 
70
+ # Fields required to be in metadata.json
71
+ # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
60
72
  required_fields = %w(name version author license summary source dependencies)
61
-
62
73
  required_fields.each do |field|
63
74
  if parsed[field].nil?
64
75
  puts "Error: Required field '#{field}' not found in metadata.json."
@@ -70,9 +81,7 @@ module MetadataJsonLint
70
81
 
71
82
  # Deprecated fields
72
83
  # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
73
-
74
84
  deprecated_fields = %w(types checksum)
75
-
76
85
  deprecated_fields.each do |field|
77
86
  unless parsed[field].nil?
78
87
  puts "Error: Deprecated field '#{field}' found in metadata.json."
@@ -80,6 +89,10 @@ module MetadataJsonLint
80
89
  end
81
90
  end
82
91
 
92
+ # The nested 'requirements' name of 'pe' is deprecated as well.
93
+ # https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/puppet-users/nkRPvG4q0Oo/GmXa109aJQAJ
94
+ error_state ||= invalid_requirements?(parsed['requirements']) if parsed['requirements']
95
+
83
96
  # Summary can not be over 144 characters:
84
97
  # From: https://forge.puppetlabs.com/razorsedge/snmp/3.3.1/scores
85
98
  if !parsed['summary'].nil? && parsed['summary'].size > 144
@@ -89,12 +102,17 @@ module MetadataJsonLint
89
102
 
90
103
  # Shoulds/recommendations
91
104
  # From: https://docs.puppetlabs.com/puppet/latest/reference/modules_publishing.html#write-a-metadatajson-file
92
-
105
+ #
93
106
  if !parsed['license'].nil? && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] != 'proprietary'
94
107
  puts "Warning: License identifier #{parsed['license']} is not in the SPDX list: http://spdx.org/licenses/"
95
108
  error_state = true if options[:strict_license]
96
109
  end
97
110
 
111
+ if !parsed['tags'].nil? && !parsed['tags'].is_a?(Array)
112
+ puts "Warning: Tags must be in an array. Currently it's a #{parsed['tags'].class}."
113
+ error_state = true
114
+ end
115
+
98
116
  return unless error_state
99
117
  if options[:fail_on_warnings] == true
100
118
  abort("Errors found in #{metadata}")
@@ -104,6 +122,18 @@ module MetadataJsonLint
104
122
  end
105
123
  module_function :parse
106
124
 
125
+ def invalid_requirements?(requirements)
126
+ error_state = false
127
+ requirements.each do |requirement|
128
+ if requirement['name'] == 'pe'
129
+ puts "The 'pe' requirement is no longer supported by the Forge."
130
+ error_state = true
131
+ end
132
+ end
133
+ error_state
134
+ end
135
+ module_function :invalid_requirements?
136
+
107
137
  def invalid_dependencies?(deps)
108
138
  error_state = false
109
139
  dep_names = []
@@ -126,6 +156,13 @@ module MetadataJsonLint
126
156
  puts "Invalid 'version_requirement' field in metadata.json: #{e}"
127
157
  error_state = true
128
158
  end
159
+
160
+ # 'version_range' is no longer used by the forge
161
+ # See https://tickets.puppetlabs.com/browse/PUP-2781
162
+ next unless dep['version_range']
163
+ puts "Warning: Dependency #{dep['name']} has a 'version_range' attribute " \
164
+ 'which is no longer used by the forge.'
165
+ error_state = true
129
166
  end
130
167
  error_state
131
168
  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: 1.0.0
4
+ version: 1.1.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: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2017-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spdx-licenses