metadata-json-lint 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +24 -0
  5. data/.rubocop_todo.yml +18 -0
  6. data/.travis.yml +24 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE +13 -0
  9. data/README.md +63 -0
  10. data/Rakefile +15 -0
  11. data/lib/metadata-json-lint/version_requirement.rb +35 -0
  12. data/metadata-json-lint.gemspec +25 -0
  13. data/spec/spec_helper.rb +36 -0
  14. data/spec/version_requirement_spec.rb +28 -0
  15. data/tests/bad_license/Rakefile +2 -0
  16. data/tests/bad_license/expected +1 -0
  17. data/tests/bad_license/metadata.json +83 -0
  18. data/tests/broken/Rakefile +2 -0
  19. data/tests/broken/expected +1 -0
  20. data/tests/broken/metadata.json +87 -0
  21. data/tests/duplicate-dep/Rakefile +2 -0
  22. data/tests/duplicate-dep/expected +1 -0
  23. data/tests/duplicate-dep/metadata.json +91 -0
  24. data/tests/json_format/Rakefile +2 -0
  25. data/tests/json_format/expected +1 -0
  26. data/tests/json_format/metadata.json +83 -0
  27. data/tests/long_summary/Rakefile +2 -0
  28. data/tests/long_summary/expected +1 -0
  29. data/tests/long_summary/metadata.json +24 -0
  30. data/tests/missing_version_requirement/Rakefile +2 -0
  31. data/tests/missing_version_requirement/expected +1 -0
  32. data/tests/missing_version_requirement/metadata.json +27 -0
  33. data/tests/mixed_version_syntax/Rakefile +2 -0
  34. data/tests/mixed_version_syntax/expected +1 -0
  35. data/tests/mixed_version_syntax/metadata.json +30 -0
  36. data/tests/multiple_problems/Rakefile +2 -0
  37. data/tests/multiple_problems/expected +3 -0
  38. data/tests/multiple_problems/metadata.json +86 -0
  39. data/tests/no_dependencies/Rakefile +2 -0
  40. data/tests/no_dependencies/metadata.json +66 -0
  41. data/tests/no_files/.gitkeep +0 -0
  42. data/tests/no_files/expected +1 -0
  43. data/tests/no_pe/Rakefile +2 -0
  44. data/tests/no_pe/metadata.json +31 -0
  45. data/tests/no_version_range/Rakefile +2 -0
  46. data/tests/no_version_range/metadata.json +34 -0
  47. data/tests/noname/Rakefile +2 -0
  48. data/tests/noname/expected +1 -0
  49. data/tests/noname/metadata.json +86 -0
  50. data/tests/open_ended_dependency/Rakefile +2 -0
  51. data/tests/open_ended_dependency/expected +1 -0
  52. data/tests/open_ended_dependency/metadata.json +30 -0
  53. data/tests/perfect/Rakefile +2 -0
  54. data/tests/perfect/metadata.json +91 -0
  55. data/tests/proprietary/Rakefile +2 -0
  56. data/tests/proprietary/metadata.json +79 -0
  57. data/tests/rake_global_options/Rakefile +4 -0
  58. data/tests/rake_global_options/expected +1 -0
  59. data/tests/rake_global_options/metadata.json +79 -0
  60. data/tests/rake_multiple_json_options/Rakefile +14 -0
  61. data/tests/rake_multiple_json_options/metadata_license.json +79 -0
  62. data/tests/rake_multiple_json_options/metadata_ok.json +79 -0
  63. data/tests/tags_no_array/Rakefile +2 -0
  64. data/tests/tags_no_array/expected +1 -0
  65. data/tests/tags_no_array/metadata.json +96 -0
  66. data/tests/tags_with_array/Rakefile +2 -0
  67. data/tests/tags_with_array/metadata.json +92 -0
  68. data/tests/test.sh +157 -0
  69. data/tests/types/Rakefile +2 -0
  70. data/tests/types/expected +1 -0
  71. data/tests/types/metadata.json +88 -0
  72. metadata +131 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26b0284277b14da2149836312d2f7470eeb42fec
4
- data.tar.gz: 1f700550be689ad9379a1bfb5a617f4de64a18db
3
+ metadata.gz: 2f363e6245ce619ab7b466ed22c81b5777a63266
4
+ data.tar.gz: 78003ad2f645237859a2a3a79c1ad6bafbba25d9
5
5
  SHA512:
6
- metadata.gz: f0160d90cb4707dc94deb44d16f9a3d22dcd15f9f6b7749c054b8354ea593089407de42e679040a052c634637d6718d636f7abec41c3cd0e2811ee439d2a9211
7
- data.tar.gz: 9cbad4cbd0437415b6c347a05491a4a17f5324ca2c4472fc02772701fc7c37ebbda5a2c95106cbf5305f8afe11b4bc224e9de13ce4b74967eb9fed593da3743f
6
+ metadata.gz: 313273da7c521fbd0ddc64241576ea316341c0830ff5783f7507c547b20379d7db3e639f5e95983f6ccb635167f742808b91ea67e35a990291e61603191d336d
7
+ data.tar.gz: a2d3690009e395396de889258d89e5a5dcd207179051ebdecc8de0e9e410e212995ce00e2e202fcb3fd12be3f01f027cd6e0f721083d4f119182a405d4a9873f
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ *.gem
3
+ Gemfile.lock
4
+ /.bundle
5
+ /vendor
6
+ tests/*/last_output
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,24 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
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/PerceivedComplexity:
21
+ Enabled: false
22
+
23
+ Metrics/ModuleLength:
24
+ Max: 175
@@ -0,0 +1,18 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-10-08 14:05:42 -0700 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/RescueException:
11
+ Exclude:
12
+ - 'lib/metadata_json_lint.rb'
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: Exclude.
16
+ Style/Documentation:
17
+ Exclude:
18
+ - 'lib/metadata_json_lint.rb'
@@ -0,0 +1,24 @@
1
+ ---
2
+ language: ruby
3
+
4
+ script:
5
+ - bundle exec rake test
6
+
7
+ sudo: false
8
+
9
+ rvm:
10
+ - 2.0.0
11
+ - 2.1.9
12
+ - 2.3.1
13
+
14
+ deploy:
15
+ provider: rubygems
16
+ api_key:
17
+ secure: Rm6j/fS5n4TyqmqftwMj2Ebw0avsuDbuI9wVX4exUNiuQRru967QPrQinMuAwBGLCNYMs69ZHFBMkpk61khQGC3W7d5Yr/25HabnQBFpfO2llHhKKgM/Ckyqur+ku88EVJH9nRCDqOprJtC4RGHIA833ENL8xVP/VOvfiKG0Q14=
18
+ gem: metadata-json-lint
19
+ on:
20
+ tags: true
21
+ repo: voxpupuli/metadata-json-lint
22
+
23
+ notifications:
24
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2014 HP Development Corporation L.P.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this software except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,63 @@
1
+ # metadata-json-lint
2
+
3
+ The metadata-json-lint tool validates and lints `metadata.json` files in Puppet modules against style guidelines from the [Puppet Forge module metadata](https://docs.puppet.com/puppet/latest/modules_publishing.html#write-a-metadatajson-file) recommendations.
4
+
5
+ ## Compatibility
6
+
7
+ metadata-json-lint is compatible with Ruby versions 2.0.0, 2.1.9, and 2.3.1.
8
+
9
+ ## Installation
10
+
11
+ Install the `metadata-json-lint` gem:
12
+
13
+ ```shell
14
+ gem install metadata-json-lint
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Testing with metadata-json-lint
20
+
21
+ On the command line, run `metadata-json-lint` with the path of your `metadata.json` file:
22
+
23
+ ```shell
24
+ metadata-json-lint /path/to/metadata.json
25
+ ```
26
+
27
+ ### Testing with metadata-json-lint as a Rake task
28
+
29
+ If you are already using `puppet_spec_helper`, the 'validate' task already includes `metadata-json-lint`.
30
+
31
+ You can also integrate `metadata-json-lint` checks into your tests using the Rake task. Add `require 'metadata-json-lint/rake_task'` to your `Rakefile`, and then run:
32
+
33
+ ```ruby
34
+ rake metadata_lint
35
+ ```
36
+
37
+ To set options for the Rake task, include them when you define the task:
38
+
39
+ ```ruby
40
+ require 'metadata-json-lint'
41
+ task :metadata_lint do
42
+ MetadataJsonLint.parse('metadata.json') do |options|
43
+ options.strict_license = false
44
+ end
45
+ end
46
+ ```
47
+
48
+ Alternatively, set the option after requiring the Rake task:
49
+
50
+ ```ruby
51
+ require 'metadata-json-lint/rake_task'
52
+ MetadataJsonLint.options.strict_license = false
53
+ ```
54
+
55
+ ### Options
56
+
57
+ * `--[no-]strict-dependencies`: Whether to fail if module version dependencies are open-ended. Defaults to `false`.
58
+ * `--[no-]strict-license`: Whether to fail on strict license check. Defaults to `true`.
59
+ * `--[no-]fail-on-warnings`: Whether to fail on warnings. Defaults to `true`.
60
+
61
+ ## Contributors
62
+
63
+ A big thank you to the [contributors](https://github.com/voxpupuli/metadata-json-lint/graphs/contributors).
@@ -0,0 +1,15 @@
1
+ desc 'Run all tests'
2
+ task :test => %i[rubocop spec test:acceptance]
3
+
4
+ require 'rubocop/rake_task'
5
+ RuboCop::RakeTask.new
6
+
7
+ namespace :test do
8
+ desc 'Acceptance suite under test/ which runs metadata-json-lint against sample files with expected output'
9
+ task :acceptance do
10
+ sh 'tests/test.sh'
11
+ end
12
+ end
13
+
14
+ require 'rspec/core/rake_task'
15
+ RSpec::Core::RakeTask.new(:spec)
@@ -0,0 +1,35 @@
1
+ require 'semantic_puppet'
2
+
3
+ module MetadataJsonLint
4
+ # Parses a string module version requirement with semantic_puppet and
5
+ # provides methods to analyse it for lint warnings
6
+ class VersionRequirement
7
+ def initialize(requirement)
8
+ @requirement = requirement
9
+ @range = SemanticPuppet::VersionRange.parse(requirement)
10
+ end
11
+
12
+ # Whether the range uses a comparison operator (e.g. >=) with a wildcard
13
+ # syntax, such as ">= 1.x" or "< 2.0.x"
14
+ def mixed_syntax?
15
+ !/
16
+ [><=^~]{1,2} # comparison operators
17
+ \s*
18
+ \d\. # MAJOR
19
+ (?:
20
+ (?:x|\*) # MINOR is wildcard
21
+ |
22
+ \d\.(?:x|\*) # MINOR is digit and PATCH is wildcard
23
+ )
24
+ /x.match(requirement).nil?
25
+ end
26
+
27
+ def open_ended?
28
+ @range.end == SemanticPuppet::Version::MAX
29
+ end
30
+
31
+ private
32
+
33
+ attr_reader :range, :requirement
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ require 'date'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'metadata-json-lint'
5
+ s.version = '1.2.1'
6
+ s.date = Date.today.to_s
7
+ s.summary = 'metadata-json-lint /path/to/metadata.json'
8
+ s.description = 'Utility to verify Puppet metadata.json files'
9
+ s.authors = ['Vox Pupuli']
10
+ s.email = 'voxpupuli@groups.io'
11
+
12
+ s.files = `git ls-files -z`.split("\x0")
13
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
14
+ s.test_files = s.files.grep(%r{^(tests|spec)/})
15
+
16
+ s.homepage = 'http://github.com/voxpupuli/metadata-json-lint'
17
+ s.license = 'Apache-2.0'
18
+
19
+ s.add_runtime_dependency 'spdx-licenses', '~> 1.0'
20
+ s.add_runtime_dependency 'json'
21
+ s.add_runtime_dependency 'semantic_puppet', '>= 0.1.2', '< 2.0.0'
22
+ s.add_development_dependency 'rake'
23
+ s.add_development_dependency 'rspec'
24
+ s.add_development_dependency 'rubocop'
25
+ end
@@ -0,0 +1,36 @@
1
+ require 'metadata_json_lint'
2
+
3
+ # This file was generated by the `rspec --init` command
4
+ #
5
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
6
+ RSpec.configure do |config|
7
+ # rspec-expectations config goes here. You can use an alternate
8
+ # assertion/expectation library such as wrong or the stdlib/minitest
9
+ # assertions if you prefer.
10
+ config.expect_with :rspec do |expectations|
11
+ # This option will default to `true` in RSpec 4. It makes the `description`
12
+ # and `failure_message` of custom matchers include text for helper methods
13
+ # defined using `chain`, e.g.:
14
+ # be_bigger_than(2).and_smaller_than(4).description
15
+ # # => "be bigger than 2 and smaller than 4"
16
+ # ...rather than:
17
+ # # => "be bigger than 2"
18
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
19
+ end
20
+
21
+ # rspec-mocks config goes here. You can use an alternate test double
22
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
23
+ config.mock_with :rspec do |mocks|
24
+ # Prevents you from mocking or stubbing a method that does not exist on
25
+ # a real object. This is generally recommended, and will default to
26
+ # `true` in RSpec 4.
27
+ mocks.verify_partial_doubles = true
28
+ end
29
+
30
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
31
+ # have no way to turn it off -- the option exists only for backwards
32
+ # compatibility in RSpec 3). It causes shared context metadata to be
33
+ # inherited by the metadata hash of host groups and examples, rather than
34
+ # triggering implicit auto-inclusion in groups with matching metadata.
35
+ config.shared_context_metadata_behavior = :apply_to_host_groups
36
+ end
@@ -0,0 +1,28 @@
1
+ describe MetadataJsonLint::VersionRequirement do
2
+ describe '.new' do
3
+ it { expect(described_class.new('')).to be_a(MetadataJsonLint::VersionRequirement) }
4
+ it { expect(described_class.new('>= 1.0')).to be_a(MetadataJsonLint::VersionRequirement) }
5
+ it { expect { described_class.new('## 1.0') }.to raise_error(ArgumentError) }
6
+ end
7
+
8
+ describe '#mixed_syntax?' do
9
+ it { expect(described_class.new('>= 1.0.0').mixed_syntax?).to be false }
10
+ it { expect(described_class.new('1.0.x').mixed_syntax?).to be false }
11
+ it { expect(described_class.new('>= 1.0.0 < 2.0').mixed_syntax?).to be false }
12
+ it { expect(described_class.new('< 2.0').mixed_syntax?).to be false }
13
+
14
+ it { expect(described_class.new('>= 1.0.x').mixed_syntax?).to be true }
15
+ it { expect(described_class.new('>= 1.0.*').mixed_syntax?).to be true }
16
+ it { expect(described_class.new('>= 1.x').mixed_syntax?).to be true }
17
+ it { expect(described_class.new('>= 1.x.x').mixed_syntax?).to be true }
18
+ it { expect(described_class.new('>= 1.*').mixed_syntax?).to be true }
19
+ it { expect(described_class.new('>= 1.0.0 < 2.x').mixed_syntax?).to be true }
20
+ it { expect(described_class.new('<2.x').mixed_syntax?).to be true }
21
+ end
22
+
23
+ describe '#open_ended?' do
24
+ it { expect(described_class.new('>= 1.0 < 2.0').open_ended?).to be false }
25
+ it { expect(described_class.new('>= 1.0').open_ended?).to be true }
26
+ it { expect(described_class.new('').open_ended?).to be true }
27
+ end
28
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1 @@
1
+ License identifier Unknown-1.0 is not in the SPDX list: http://spdx.org/licenses/
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "Unknown-1.0",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "operatingsystem_support": [
11
+ {
12
+ "operatingsystem": "RedHat",
13
+ "operatingsystemrelease": [
14
+ "5",
15
+ "6",
16
+ "7"
17
+ ]
18
+ },
19
+ {
20
+ "operatingsystem": "CentOS",
21
+ "operatingsystemrelease": [
22
+ "5",
23
+ "6",
24
+ "7"
25
+ ]
26
+ },
27
+ {
28
+ "operatingsystem": "OracleLinux",
29
+ "operatingsystemrelease": [
30
+ "5",
31
+ "6",
32
+ "7"
33
+ ]
34
+ },
35
+ {
36
+ "operatingsystem": "Scientific",
37
+ "operatingsystemrelease": [
38
+ "5",
39
+ "6",
40
+ "7"
41
+ ]
42
+ },
43
+ {
44
+ "operatingsystem": "Debian",
45
+ "operatingsystemrelease": [
46
+ "6",
47
+ "7"
48
+ ]
49
+ },
50
+ {
51
+ "operatingsystem": "Ubuntu",
52
+ "operatingsystemrelease": [
53
+ "10.04",
54
+ "12.04",
55
+ "14.04"
56
+ ]
57
+ }
58
+ ],
59
+ "requirements": [
60
+ {
61
+ "name": "puppet",
62
+ "version_requirement": "3.x"
63
+ }
64
+ ],
65
+ "dependencies": [
66
+ {
67
+ "name": "puppetlabs/stdlib",
68
+ "version_requirement": "4.x"
69
+ },
70
+ {
71
+ "name": "puppetlabs/firewall",
72
+ "version_requirement": ">= 0.0.4"
73
+ },
74
+ {
75
+ "name": "puppetlabs/apt",
76
+ "version_requirement": ">=1.1.0 <2.0.0"
77
+ },
78
+ {
79
+ "name": "puppetlabs/concat",
80
+ "version_requirement": ">= 1.1.0 <2.0.0"
81
+ }
82
+ ]
83
+ }
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../../lib', __FILE__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1 @@
1
+ Error: Unable to parse metadata.json: [0-9]*: unexpected token at
@@ -0,0 +1,87 @@
1
+ {
2
+ "name": "puppetlabs-postgresql"
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "PostgreSQL defined resource types",
6
+ "license": "Apache-2.0",
7
+ "source": "git://github.com/puppetlabs/puppet-postgresql.git",
8
+ "project_page": "https://github.com/puppetlabs/puppet-postgresql",
9
+ "issues_url": "https://github.com/puppetlabs/puppet-postgresql/issues",
10
+ "operatingsystem_support": [
11
+ {
12
+ "operatingsystem": "RedHat",
13
+ "operatingsystemrelease": [
14
+ "5",
15
+ "6",
16
+ "7"
17
+ ]
18
+ },
19
+ {
20
+ "operatingsystem": "CentOS",
21
+ "operatingsystemrelease": [
22
+ "5",
23
+ "6",
24
+ "7"
25
+ ]
26
+ },
27
+ {
28
+ "operatingsystem": "OracleLinux",
29
+ "operatingsystemrelease": [
30
+ "5",
31
+ "6",
32
+ "7"
33
+ ]
34
+ },
35
+ {
36
+ "operatingsystem": "Scientific",
37
+ "operatingsystemrelease": [
38
+ "5",
39
+ "6",
40
+ "7"
41
+ ]
42
+ },
43
+ {
44
+ "operatingsystem": "Debian",
45
+ "operatingsystemrelease": [
46
+ "6",
47
+ "7"
48
+ ]
49
+ },
50
+ {
51
+ "operatingsystem": "Ubuntu",
52
+ "operatingsystemrelease": [
53
+ "10.04",
54
+ "12.04",
55
+ "14.04"
56
+ ]
57
+ }
58
+ ],
59
+ "requirements": [
60
+ {
61
+ "name": "pe",
62
+ "version_requirement": ">= 3.2.0 < 3.4.0"
63
+ },
64
+ {
65
+ "name": "puppet",
66
+ "version_requirement": "3.x"
67
+ }
68
+ ],
69
+ "dependencies": [
70
+ {
71
+ "name": "puppetlabs/stdlib",
72
+ "version_requirement": "4.x"
73
+ },
74
+ {
75
+ "name": "puppetlabs/firewall",
76
+ "version_requirement": ">= 0.0.4"
77
+ },
78
+ {
79
+ "name": "puppetlabs/apt",
80
+ "version_requirement": ">=1.1.0 <2.0.0"
81
+ },
82
+ {
83
+ "name": "puppetlabs/concat",
84
+ "version_requirement": ">= 1.1.0 <2.0.0"
85
+ }
86
+ ]
87
+ }