metadata-json-lint 4.1.0 → 4.2.0

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
  SHA256:
3
- metadata.gz: 392e39d697c2b5355eebedd010f8a80b575db099a6865a66f82397c387733969
4
- data.tar.gz: 7dbcb7bce5b9ddf5e20bf0f0fc91f854c0dacd81d097dff585f1aef2b442fb77
3
+ metadata.gz: b60ce6545987408a2b495837f6817aec37c8caf185ed8d607ecc2067421e4604
4
+ data.tar.gz: b945326563aa3db151f3c11dc52bb8a3aca36920d541dc3a23a2ed1bb0c85ee3
5
5
  SHA512:
6
- metadata.gz: e9e4de4ab6f67f70575b5e73be16871d4f629f3d0e1954c5ee7a6f42859bc2b63bc8eef9028b6591fd0780ad49d506a07b55b16774b32b54792ac063ef8f6814
7
- data.tar.gz: 240dbbc7fa193e30197704e3313cebb07617999053ff53caf5860cc7c17efa16bfd24a2b15fd87d53c22e34ac1e4e23651d9a48750cb2ab3b5fc382cb56fab7c
6
+ metadata.gz: 6248271c94ffdaa61d9236884c01af123114f14850885f09d7699ebeaa639f262fc476834781b80c6ae413ef434b8cec269368f63a54681f8c39ad178a1a640f
7
+ data.tar.gz: 61690474cee73b0fc0f14a32dd9c87d3a82ea682a3754e695acc4c87d261093f531ad0407a95d91d68d317ba8c5cd409bb9d80ff8c995a90d40b35240fe7cdb6
@@ -11,10 +11,10 @@ jobs:
11
11
  if: github.repository_owner == 'voxpupuli'
12
12
  steps:
13
13
  - uses: actions/checkout@v4
14
- - name: Install Ruby 3.3
14
+ - name: Install Ruby 3.4
15
15
  uses: ruby/setup-ruby@v1
16
16
  with:
17
- ruby-version: '3.3'
17
+ ruby-version: '3.4'
18
18
  env:
19
19
  BUNDLE_WITHOUT: release
20
20
  - name: Build gem
@@ -10,49 +10,45 @@ env:
10
10
  BUNDLE_WITHOUT: release
11
11
 
12
12
  jobs:
13
- rubocop:
13
+ rubocop_and_matrix:
14
14
  runs-on: ubuntu-latest
15
+ outputs:
16
+ ruby: ${{ steps.ruby.outputs.versions }}
15
17
  steps:
16
18
  - uses: actions/checkout@v4
17
- - name: Install Ruby ${{ matrix.ruby }}
19
+ - name: Install Ruby 3.4
18
20
  uses: ruby/setup-ruby@v1
19
21
  with:
20
- ruby-version: "3.3"
22
+ ruby-version: '3.4'
21
23
  bundler-cache: true
22
- - name: Run Rubocop
24
+ - name: Run RuboCop
23
25
  run: bundle exec rake rubocop
24
- rspec:
26
+ - id: ruby
27
+ uses: voxpupuli/ruby-version@v1
28
+
29
+ test:
30
+ name: "Ruby ${{ matrix.ruby }}"
25
31
  runs-on: ubuntu-latest
32
+ needs: rubocop_and_matrix
26
33
  strategy:
34
+ fail-fast: false
27
35
  matrix:
28
- include:
29
- - ruby: "2.7"
30
- - ruby: "3.0"
31
- - ruby: "3.1"
32
- coverage: "yes"
33
- - ruby: "3.2"
34
- - ruby: "3.3"
35
- env:
36
- COVERAGE: ${{ matrix.coverage }}
37
- # https://github.com/rubygems/rubygems/issues/5234#issuecomment-1003773622
38
- RUBYOPT: '--disable-did_you_mean'
39
- name: RSpec - Ruby ${{ matrix.ruby }}
36
+ ruby: ${{ fromJSON(needs.rubocop_and_matrix.outputs.ruby) }}
40
37
  steps:
41
38
  - uses: actions/checkout@v4
42
- - name: Install Ruby ${{ matrix.ruby }}
39
+ - name: Setup ruby
43
40
  uses: ruby/setup-ruby@v1
44
41
  with:
45
42
  ruby-version: ${{ matrix.ruby }}
46
43
  bundler-cache: true
47
- - name: spec tests
44
+ - name: Run tests
48
45
  run: bundle exec rake test
49
- - name: Verify gem builds
46
+ - name: Build the gem
50
47
  run: gem build --strict --verbose *.gemspec
51
48
 
52
49
  tests:
53
50
  needs:
54
- - rubocop
55
- - rspec
51
+ - test
56
52
  runs-on: ubuntu-latest
57
53
  name: Test suite
58
54
  steps:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## [4.2.0](https://github.com/voxpupuli/metadata-json-lint/tree/4.2.0) (2025-01-24)
4
+
5
+ [Full Changelog](https://github.com/voxpupuli/metadata-json-lint/compare/4.1.0...4.2.0)
6
+
7
+ **Implemented enhancements:**
8
+
9
+ - Fail if metadata.json has no proper newline [\#154](https://github.com/voxpupuli/metadata-json-lint/pull/154) ([bastelfreak](https://github.com/bastelfreak))
10
+ - Fail on escape sequences in metadata.json [\#152](https://github.com/voxpupuli/metadata-json-lint/pull/152) ([bastelfreak](https://github.com/bastelfreak))
11
+ - Rake: Use RuboCop tasks from voxpupuli-rubocop [\#150](https://github.com/voxpupuli/metadata-json-lint/pull/150) ([bastelfreak](https://github.com/bastelfreak))
12
+ - Add Ruby 3.4 to CI [\#149](https://github.com/voxpupuli/metadata-json-lint/pull/149) ([bastelfreak](https://github.com/bastelfreak))
13
+
14
+ **Merged pull requests:**
15
+
16
+ - CI: Switch to voxpupuli/ruby-version [\#156](https://github.com/voxpupuli/metadata-json-lint/pull/156) ([bastelfreak](https://github.com/bastelfreak))
17
+ - Drop code coverage in testing [\#153](https://github.com/voxpupuli/metadata-json-lint/pull/153) ([ekohl](https://github.com/ekohl))
18
+ - Update voxpupuli-rubocop requirement from ~\> 2.8.0 to ~\> 3.0.0 [\#147](https://github.com/voxpupuli/metadata-json-lint/pull/147) ([dependabot[bot]](https://github.com/apps/dependabot))
19
+
3
20
  ## [4.1.0](https://github.com/voxpupuli/metadata-json-lint/tree/4.1.0) (2024-08-19)
4
21
 
5
22
  [Full Changelog](https://github.com/voxpupuli/metadata-json-lint/compare/4.0.0...4.1.0)
data/Gemfile CHANGED
@@ -6,8 +6,3 @@ group :release do
6
6
  gem 'faraday-retry', require: false
7
7
  gem 'github_changelog_generator', require: false
8
8
  end
9
-
10
- group :coverage, optional: ENV['COVERAGE'] != 'yes' do
11
- gem 'codecov', require: false
12
- gem 'simplecov-console', require: false
13
- end
data/Rakefile CHANGED
@@ -2,16 +2,9 @@ desc 'Run all tests'
2
2
  task test: %i[spec test:acceptance]
3
3
 
4
4
  begin
5
- require 'rubocop/rake_task'
5
+ require 'voxpupuli/rubocop/rake'
6
6
  rescue LoadError
7
- # RuboCop is an optional group
8
- else
9
- RuboCop::RakeTask.new(:rubocop) do |task|
10
- # These make the rubocop experience maybe slightly less terrible
11
- task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
12
- # Use Rubocop's Github Actions formatter if possible
13
- task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
14
- end
7
+ # the voxpupuli-rubocop gem is optional
15
8
  end
16
9
 
17
10
  namespace :test do
@@ -8,6 +8,9 @@ require 'metadata-json-lint/version_requirement'
8
8
 
9
9
  module MetadataJsonLint
10
10
  MIN_PUPPET_VER = '4.10.0'.freeze
11
+ # Regex looks for:
12
+ # 1. Invalid escape sequences (\x or incomplete \u)
13
+ INVALID_ESCAPE_REGEX = %r{\\[^"/bfnrtu]|\\u(?![0-9a-fA-F]{4})}.freeze
11
14
 
12
15
  def options
13
16
  @options ||= Struct.new(
@@ -69,6 +72,16 @@ module MetadataJsonLint
69
72
  end
70
73
  module_function :run
71
74
 
75
+ def contains_invalid_escape?(content)
76
+ content.match?(INVALID_ESCAPE_REGEX)
77
+ end
78
+ module_function :contains_invalid_escape?
79
+
80
+ def misses_newline_at_end?(content)
81
+ content[-1] != "\n"
82
+ end
83
+ module_function :misses_newline_at_end?
84
+
72
85
  def parse(metadata)
73
86
  @errors = []
74
87
  @warnings = []
@@ -83,6 +96,10 @@ module MetadataJsonLint
83
96
  abort("Error: Unable to read metadata file: #{e.exception}")
84
97
  end
85
98
 
99
+ abort('Error: metadata.json does not have a valid newline at the end') if misses_newline_at_end?(f)
100
+
101
+ abort('Error: Unable to parse metadata.json: Invalid escape character in string') if contains_invalid_escape?(f)
102
+
86
103
  begin
87
104
  parsed = JSON.parse(f)
88
105
  rescue Exception => e
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'metadata-json-lint'
3
- s.version = '4.1.0'
3
+ s.version = '4.2.0'
4
4
  s.summary = 'metadata-json-lint /path/to/metadata.json'
5
5
  s.description = 'Utility to verify Puppet metadata.json files'
6
6
  s.authors = ['Vox Pupuli']
@@ -14,10 +14,10 @@ Gem::Specification.new do |s|
14
14
 
15
15
  s.required_ruby_version = '>= 2.7.0'
16
16
 
17
- s.add_runtime_dependency 'json-schema', '>= 2.8', '< 6.0'
18
- s.add_runtime_dependency 'semantic_puppet', '~> 1.0'
19
- s.add_runtime_dependency 'spdx-licenses', '~> 1.0'
17
+ s.add_dependency 'json-schema', '>= 2.8', '< 6.0'
18
+ s.add_dependency 'semantic_puppet', '~> 1.0'
19
+ s.add_dependency 'spdx-licenses', '~> 1.0'
20
20
  s.add_development_dependency 'rake', '~> 13.0', '>= 13.0.6'
21
21
  s.add_development_dependency 'rspec', '~> 3.12'
22
- s.add_development_dependency 'voxpupuli-rubocop', '~> 2.8.0'
22
+ s.add_development_dependency 'voxpupuli-rubocop', '~> 3.0.0'
23
23
  end
data/spec/spec_helper.rb CHANGED
@@ -1,27 +1,3 @@
1
- begin
2
- require 'simplecov'
3
- require 'simplecov-console'
4
- require 'codecov'
5
- rescue LoadError
6
- else
7
- SimpleCov.start do
8
- track_files 'lib/**/*.rb'
9
-
10
- add_filter '/spec'
11
-
12
- enable_coverage :branch
13
-
14
- # do not track vendored files
15
- add_filter '/vendor'
16
- add_filter '/.vendor'
17
- end
18
-
19
- SimpleCov.formatters = [
20
- SimpleCov::Formatter::Console,
21
- SimpleCov::Formatter::Codecov,
22
- ]
23
- end
24
-
25
1
  require 'metadata_json_lint'
26
2
 
27
3
  # This file was generated by the `rspec --init` command
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1 @@
1
+ Error: Unable to parse metadata.json: Invalid escape character in string
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "A description with an invalid \( escape sequence",
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
+ "requirements": [
13
+ ],
14
+ "dependencies": [
15
+ ]
16
+ }
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift(File.expand_path('../../lib', __dir__))
2
+ require 'metadata-json-lint/rake_task'
@@ -0,0 +1 @@
1
+ Error: metadata.json does not have a valid newline at the end
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "puppetlabs-postgresql",
3
+ "version": "3.4.1",
4
+ "author": "Inkling/Puppet Labs",
5
+ "summary": "A metadata.json file without a newline at the end",
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
+ "requirements": [
13
+ ],
14
+ "dependencies": [
15
+ ]
16
+ }
data/tests/test.sh CHANGED
@@ -103,6 +103,12 @@ test "bad_license" $SUCCESS --no-strict-license
103
103
  # Run with --no-fail-on-warnings, expect SUCCESS
104
104
  test "bad_license" $SUCCESS --no-fail-on-warnings
105
105
 
106
+ # Run a broken one, expect FAILURE
107
+ test "invalid_escape_char" $FAILURE
108
+
109
+ # Run a broken one, expect FAILURE
110
+ test "missing_newline" $FAILURE
111
+
106
112
  # Run a broken one, expect FAILURE
107
113
  test "long_summary" $FAILURE
108
114
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metadata-json-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-08-19 00:00:00.000000000 Z
10
+ date: 2025-01-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: json-schema
@@ -98,14 +97,14 @@ dependencies:
98
97
  requirements:
99
98
  - - "~>"
100
99
  - !ruby/object:Gem::Version
101
- version: 2.8.0
100
+ version: 3.0.0
102
101
  type: :development
103
102
  prerelease: false
104
103
  version_requirements: !ruby/object:Gem::Requirement
105
104
  requirements:
106
105
  - - "~>"
107
106
  - !ruby/object:Gem::Version
108
- version: 2.8.0
107
+ version: 3.0.0
109
108
  description: Utility to verify Puppet metadata.json files
110
109
  email: voxpupuli@groups.io
111
110
  executables:
@@ -148,12 +147,18 @@ files:
148
147
  - tests/duplicate-requirement/Rakefile
149
148
  - tests/duplicate-requirement/expected
150
149
  - tests/duplicate-requirement/metadata.json
150
+ - tests/invalid_escape_char/Rakefile
151
+ - tests/invalid_escape_char/expected
152
+ - tests/invalid_escape_char/metadata.json
151
153
  - tests/json_format/Rakefile
152
154
  - tests/json_format/expected
153
155
  - tests/json_format/metadata.json
154
156
  - tests/long_summary/Rakefile
155
157
  - tests/long_summary/expected
156
158
  - tests/long_summary/metadata.json
159
+ - tests/missing_newline/Rakefile
160
+ - tests/missing_newline/expected
161
+ - tests/missing_newline/metadata.json
157
162
  - tests/missing_version_requirement/Rakefile
158
163
  - tests/missing_version_requirement/expected
159
164
  - tests/missing_version_requirement/metadata.json
@@ -208,7 +213,6 @@ homepage: https://github.com/voxpupuli/metadata-json-lint
208
213
  licenses:
209
214
  - Apache-2.0
210
215
  metadata: {}
211
- post_install_message:
212
216
  rdoc_options: []
213
217
  require_paths:
214
218
  - lib
@@ -223,8 +227,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
227
  - !ruby/object:Gem::Version
224
228
  version: '0'
225
229
  requirements: []
226
- rubygems_version: 3.5.11
227
- signing_key:
230
+ rubygems_version: 3.6.2
228
231
  specification_version: 4
229
232
  summary: metadata-json-lint /path/to/metadata.json
230
233
  test_files: []