jsonlint 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -4
- data/README.md +13 -2
- data/jsonlint.gemspec +9 -9
- data/lib/jsonlint/cli.rb +3 -3
- data/lib/jsonlint/linter.rb +5 -0
- data/lib/jsonlint/rake_task.rb +19 -2
- data/lib/jsonlint/version.rb +1 -1
- data/spec/cli_spec.rb +5 -5
- data/spec/linter_spec.rb +2 -0
- data/spec/spec_helper.rb +1 -1
- metadata +22 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 865549ae7f81666a0d93c1ea750f1e58c49b72f9d122d337370512759970cceb
|
4
|
+
data.tar.gz: a219e77d9061374565d230057e2b9374e801b94f3a557f8a2aa9a8229c2fda0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fa98267d4c36018a931084e42d66590755d272dc15fb880eef54e659300a8bdb3b3cec59d5e691cfbdaec899ed95269a56ee7a680b1c638b7dd8acf85f4334d
|
7
|
+
data.tar.gz: 84de08ff27a4fcec4d7a07b7e06e589ffda10adc91430b6b7ca689f9ac48dcb9b23bd982964ea48f28dafe446889a80412718e94f1f2a1ca45e1aff594884d3d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# jsonlint
|
2
2
|
|
3
|
-
[![Build Status](https://travis-ci.org/
|
3
|
+
[![Build Status](https://travis-ci.org/dougbarth/jsonlint.svg?branch=master)](https://travis-ci.org/dougbarth/jsonlint)
|
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/
|
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 = [
|
10
|
-
spec.email = [
|
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 =
|
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', '~>
|
21
|
-
spec.add_dependency '
|
20
|
+
spec.add_dependency 'oj', '~> 3'
|
21
|
+
spec.add_dependency 'optimist', '~> 3'
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 2'
|
24
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.8'
|
26
|
+
spec.add_development_dependency 'aruba', '~> 0.14'
|
27
27
|
end
|
data/lib/jsonlint/cli.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
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
|
-
|
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 =
|
39
|
+
@opts = Optimist.options(@argv) do
|
40
40
|
banner 'Usage: jsonlint [options] file1.json [file2.json ...]'
|
41
41
|
version(JsonLint::VERSION)
|
42
42
|
banner ''
|
data/lib/jsonlint/linter.rb
CHANGED
data/lib/jsonlint/rake_task.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
data/lib/jsonlint/version.rb
CHANGED
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
|
-
|
52
|
-
|
53
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.3.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:
|
11
|
+
date: 2019-06-10 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: '
|
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: '
|
26
|
+
version: '3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: optimist
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
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: '
|
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: '
|
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: '
|
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: '
|
61
|
+
version: '12.3'
|
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: '
|
68
|
+
version: '12.3'
|
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: '
|
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: '
|
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: '0.14'
|
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: '0.14'
|
97
97
|
description: Checks JSON files for correct syntax and no silly mistakes
|
98
98
|
email:
|
99
99
|
- dougbarth@gmail.com
|
@@ -147,8 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
- !ruby/object:Gem::Version
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
|
-
|
151
|
-
rubygems_version: 2.5.1
|
150
|
+
rubygems_version: 3.0.3
|
152
151
|
signing_key:
|
153
152
|
specification_version: 4
|
154
153
|
summary: JSON lint checker
|
@@ -165,4 +164,3 @@ test_files:
|
|
165
164
|
- spec/data/valid_array_of_objects.json
|
166
165
|
- spec/linter_spec.rb
|
167
166
|
- spec/spec_helper.rb
|
168
|
-
has_rdoc:
|