jsonlint 0.2.0 → 0.4.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
- SHA1:
3
- metadata.gz: 9440424c5ce5284432200d4275be3ef815c55a87
4
- data.tar.gz: b85712a8defcd3df4d0846d4993e0a967cc2283d
2
+ SHA256:
3
+ metadata.gz: 7f90b077d96d488246693d4e290cda456d87811fc15eeace4b44550b0f2e6928
4
+ data.tar.gz: 0dee5476a67f9e9f64b9bbdd2ed884d0825359782c8d54a5996c735a1a00bbab
5
5
  SHA512:
6
- metadata.gz: d2f64c73f7f4e8512dee6abc20228ad68de118a339fd45313766828c118e9bb0f370b067575017566d3138915ca0e6cce644b5db46e0bcba85f47f422585dea3
7
- data.tar.gz: 1dd3cea2cca3437c3dc766b57d63d79690cdb5fcdb7588c2d071ab2c281431492c18ef079439b596527fb3b844509a81a4113de1a8ffdf73404d3fcd365767fd
6
+ metadata.gz: a1f4395ee50f30488fe8327dcafcf9a3a00853c23725602d2667841b2842364113f5f5731901a5e13ceb93b938754c2137103d74563db35525caa863c68510fb
7
+ data.tar.gz: c2cbe22002cc5eba2bf7cd5a08d17ba1f9a2316910ed0e5bf52200abcdd7c4c769536492179206269bf9822abd8501cc820e68383f192307dcfc986054fe505b
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@55283cc23133118229fd3f97f9336ee23a179fcf # v1.146.0
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # jsonlint
2
2
 
3
- [![Build Status](https://travis-ci.org/PagerDuty/jsonlint.svg?branch=master)](https://travis-ci.org/PagerDuty/jsonlint)
3
+ [![Ruby](https://github.com/dougbarth/jsonlint/actions/workflows/ruby.yml/badge.svg)](https://github.com/dougbarth/jsonlint/actions/workflows/ruby.yml)
4
4
  [![Gem Version](http://img.shields.io/gem/v/jsonlint.svg)](https://rubygems.org/gems/jsonlint)
5
5
 
6
6
  jsonlint checks your JSON files for syntax errors or silly mistakes. Currently it checks for:
@@ -65,9 +65,20 @@ spec/data/overlapping_keys.json
65
65
  The same key is defined twice: foo
66
66
  ```
67
67
 
68
+ ### Rake task options
69
+
70
+ Add these options similarly to the path option seen above.
71
+
72
+ | Option | Description | Default |
73
+ | ------------- | ------------- | ------------- |
74
+ | `exclude_paths` | List of files or paths to exclude from linting | `nil` |
75
+ | `fail_on_error` | Continue on to the next rake task when false and don't fail even if JsonLint finds errors | `true` |
76
+ | `log_level` | Logger level (DEBUG, INFO, WARN, ERROR, FATAL, or UNKNOWN) | `INFO` |
77
+ | `paths` | List of files or paths to lint | `nil` |
78
+
68
79
  ## Contributing
69
80
 
70
- 1. Fork it ( https://github.com/PagerDuty/jsonlint/fork )
81
+ 1. Fork it ( https://github.com/dougbarth/jsonlint/fork )
71
82
  2. Create your feature branch (`git checkout -b my-new-feature`)
72
83
  3. Commit your changes (`git commit -am 'Add some feature'`)
73
84
  4. Push to the branch (`git push origin my-new-feature`)
data/jsonlint.gemspec CHANGED
@@ -6,22 +6,22 @@ require 'jsonlint/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "jsonlint"
8
8
  spec.version = JsonLint::VERSION
9
- spec.authors = ["Doug Barth"]
10
- spec.email = ["dougbarth@gmail.com"]
9
+ spec.authors = ['Doug Barth']
10
+ spec.email = ['dougbarth@gmail.com']
11
11
  spec.summary = %q{JSON lint checker}
12
12
  spec.description = %q{Checks JSON files for correct syntax and no silly mistakes}
13
- spec.license = "MIT"
13
+ spec.license = 'MIT'
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0")
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_dependency 'oj', '~> 2'
21
- spec.add_dependency 'trollop', '~> 2'
20
+ spec.add_dependency 'oj', '~> 3'
21
+ spec.add_dependency 'optimist', '~> 3'
22
22
 
23
- spec.add_development_dependency "bundler", "~> 1.6"
24
- spec.add_development_dependency "rake"
25
- spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "aruba"
23
+ spec.add_development_dependency 'bundler', '~> 2'
24
+ spec.add_development_dependency 'rake', '~> 13'
25
+ spec.add_development_dependency 'rspec', '~> 3.8'
26
+ spec.add_development_dependency 'aruba', '~> 2'
27
27
  end
data/lib/jsonlint/cli.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'trollop'
1
+ require 'optimist'
2
2
 
3
3
  module JsonLint
4
4
  class CLI
@@ -11,7 +11,7 @@ module JsonLint
11
11
 
12
12
  files_to_check = @argv
13
13
 
14
- Trollop::die 'need at least one JSON file to check' if files_to_check.empty?
14
+ Optimist::die 'need at least one JSON file to check' if files_to_check.empty?
15
15
 
16
16
  linter = JsonLint::Linter.new
17
17
  begin
@@ -36,7 +36,7 @@ module JsonLint
36
36
  private
37
37
 
38
38
  def parse_options
39
- @opts = Trollop.options(@argv) do
39
+ @opts = Optimist.options(@argv) do
40
40
  banner 'Usage: jsonlint [options] file1.json [file2.json ...]'
41
41
  version(JsonLint::VERSION)
42
42
  banner ''
@@ -42,6 +42,11 @@ module JsonLint
42
42
  !errors.empty?
43
43
  end
44
44
 
45
+ # Return the number of lint errors found
46
+ def errors_count
47
+ errors.length
48
+ end
49
+
45
50
  def display_errors
46
51
  errors.each do |path, errors|
47
52
  puts path
@@ -74,7 +79,7 @@ module JsonLint
74
79
  end
75
80
 
76
81
  def check_syntax_valid?(json_data, errors_array)
77
- Oj.load(json_data, nilnil: false)
82
+ Oj.load(json_data, nilnil: false, mode: :strict)
78
83
  true
79
84
  rescue Oj::ParseError => e
80
85
  errors_array << e.message
@@ -7,9 +7,14 @@ module JsonLint
7
7
  class RakeTask < Rake::TaskLib
8
8
  attr_accessor :name
9
9
  attr_accessor :paths
10
+ attr_accessor :exclude_paths
11
+ attr_accessor :fail_on_error
12
+ attr_accessor :log_level
10
13
 
11
14
  def initialize(name = :jsonlint)
12
15
  @name = name
16
+ @exclude_paths = []
17
+ @fail_on_error = true
13
18
 
14
19
  yield self if block_given?
15
20
 
@@ -22,14 +27,26 @@ module JsonLint
22
27
  desc 'Run jsonlint' unless ::Rake.application.last_description
23
28
 
24
29
  task(name) do
25
- files_to_check = Rake::FileList.new(paths)
30
+ puts 'Running JsonLint...'
31
+
32
+ JsonLint.logger.level = Logger.const_get(log_level) if log_level
33
+
34
+ files_to_check_raw = Rake::FileList.new(paths)
35
+ files_to_exclude = Rake::FileList.new(exclude_paths)
36
+ files_to_check = files_to_check_raw.exclude(files_to_exclude)
37
+
38
+ puts "Checking #{files_to_check.flatten.length} files"
39
+ puts "Excluding #{files_to_exclude.flatten.length} files"
26
40
 
27
41
  linter = ::JsonLint::Linter.new
28
42
  linter.check_all(files_to_check)
29
43
 
30
44
  if linter.errors?
31
45
  linter.display_errors
32
- abort('JSON lint found')
46
+ puts "JSON lint found #{linter.errors_count} errors"
47
+ abort('JsonLint failed!') if fail_on_error
48
+ else
49
+ puts 'JsonLint found no errors'
33
50
  end
34
51
  end
35
52
  end
@@ -1,3 +1,3 @@
1
1
  module JsonLint
2
- VERSION = '0.2.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -48,9 +48,9 @@ describe 'jsonlint' do
48
48
  end
49
49
 
50
50
  it 'should fail with a path that is unreadable' do
51
- run_simple('mkdir -p tmp')
52
- run_simple('touch tmp/unreadable_file.json')
53
- run_simple('chmod -r tmp/unreadable_file.json')
51
+ run_command_and_stop('mkdir -p tmp')
52
+ run_command_and_stop('touch tmp/unreadable_file.json')
53
+ run_command_and_stop('chmod -r tmp/unreadable_file.json')
54
54
 
55
55
  jsonlint 'tmp/unreadable_file.json'
56
56
  expect(last_command_started).to_not be_successfully_executed
@@ -58,13 +58,13 @@ describe 'jsonlint' do
58
58
  end
59
59
 
60
60
  it 'should be able to lint good JSON from STDIN' do
61
- run "#{jsonlint_bin} -"
61
+ run_command "#{jsonlint_bin} -"
62
62
  pipe_in_file('../../spec/data/valid.json') and close_input
63
63
  expect(last_command_started).to be_successfully_executed
64
64
  end
65
65
 
66
66
  it 'should be able to lint bad JSON from STDIN' do
67
- run "#{jsonlint_bin} -"
67
+ run_command "#{jsonlint_bin} -"
68
68
  pipe_in_file('../../spec/data/missing_comma.json') and close_input
69
69
  expect(last_command_started).to_not be_successfully_executed
70
70
  end
@@ -0,0 +1 @@
1
+ {"^o":"SerialisationTestWhichDefinitelyDoesNotExist"}
data/spec/linter_spec.rb CHANGED
@@ -12,10 +12,12 @@ describe 'JsonLint::Linter' do
12
12
  expect(linter.check(spec_data('valid.json'))).to be(true)
13
13
  expect(linter.check(spec_data('valid_array_of_objects.json'))).to be(true)
14
14
  expect(linter.check(spec_data('valid_array_of_arrays.json'))).to be(true)
15
+ expect(linter.errors_count).to eq(0)
15
16
  end
16
17
 
17
18
  it 'should be unhappy with an invalid JSON file' do
18
19
  expect(linter.check(spec_data('missing_comma.json'))).to be(false)
20
+ expect(linter.errors_count).to eq(1)
19
21
  end
20
22
 
21
23
  it 'should be unhappy with JSON that has overlapping keys' do
@@ -38,4 +40,8 @@ describe 'JsonLint::Linter' do
38
40
  it 'should be unhapy with a JSON file full of spaces' do
39
41
  expect(linter.check(spec_data('lots_of_spaces.json'))).to be(false)
40
42
  end
43
+
44
+ it 'should not deserialise objects' do
45
+ expect(linter.check(spec_data('serialised.json'))).to be(true)
46
+ end
41
47
  end
data/spec/spec_helper.rb CHANGED
@@ -13,7 +13,7 @@ end
13
13
 
14
14
  module CliSpecHelpers
15
15
  def jsonlint(args = nil)
16
- run_simple("#{jsonlint_bin} #{args}", fail_on_error: false)
16
+ run_command_and_stop("#{jsonlint_bin} #{args}", fail_on_error: false)
17
17
  end
18
18
 
19
19
  def jsonlint_bin
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jsonlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Barth
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-07 00:00:00.000000000 Z
11
+ date: 2023-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: oj
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: trollop
28
+ name: optimist
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '2'
33
+ version: '3'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '2'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.6'
47
+ version: '2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.6'
54
+ version: '2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '3.8'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '3.8'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: aruba
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '2'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '2'
97
97
  description: Checks JSON files for correct syntax and no silly mistakes
98
98
  email:
99
99
  - dougbarth@gmail.com
@@ -102,8 +102,8 @@ executables:
102
102
  extensions: []
103
103
  extra_rdoc_files: []
104
104
  files:
105
+ - ".github/workflows/ruby.yml"
105
106
  - ".gitignore"
106
- - ".travis.yml"
107
107
  - Gemfile
108
108
  - LICENSE.txt
109
109
  - README.md
@@ -123,6 +123,7 @@ files:
123
123
  - spec/data/missing_brace.json
124
124
  - spec/data/missing_comma.json
125
125
  - spec/data/overlapping_keys.json
126
+ - spec/data/serialised.json
126
127
  - spec/data/valid.json
127
128
  - spec/data/valid_array_of_arrays.json
128
129
  - spec/data/valid_array_of_objects.json
@@ -147,8 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
148
  - !ruby/object:Gem::Version
148
149
  version: '0'
149
150
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.5.1
151
+ rubygems_version: 3.0.3.1
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: JSON lint checker
@@ -160,9 +160,9 @@ test_files:
160
160
  - spec/data/missing_brace.json
161
161
  - spec/data/missing_comma.json
162
162
  - spec/data/overlapping_keys.json
163
+ - spec/data/serialised.json
163
164
  - spec/data/valid.json
164
165
  - spec/data/valid_array_of_arrays.json
165
166
  - spec/data/valid_array_of_objects.json
166
167
  - spec/linter_spec.rb
167
168
  - spec/spec_helper.rb
168
- has_rdoc:
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0-p648
4
- - 2.1.9
5
- - 2.2.5
6
- - 2.3.1