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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9440424c5ce5284432200d4275be3ef815c55a87
4
- data.tar.gz: b85712a8defcd3df4d0846d4993e0a967cc2283d
2
+ SHA256:
3
+ metadata.gz: 865549ae7f81666a0d93c1ea750f1e58c49b72f9d122d337370512759970cceb
4
+ data.tar.gz: a219e77d9061374565d230057e2b9374e801b94f3a557f8a2aa9a8229c2fda0f
5
5
  SHA512:
6
- metadata.gz: d2f64c73f7f4e8512dee6abc20228ad68de118a339fd45313766828c118e9bb0f370b067575017566d3138915ca0e6cce644b5db46e0bcba85f47f422585dea3
7
- data.tar.gz: 1dd3cea2cca3437c3dc766b57d63d79690cdb5fcdb7588c2d071ab2c281431492c18ef079439b596527fb3b844509a81a4113de1a8ffdf73404d3fcd365767fd
6
+ metadata.gz: 5fa98267d4c36018a931084e42d66590755d272dc15fb880eef54e659300a8bdb3b3cec59d5e691cfbdaec899ed95269a56ee7a680b1c638b7dd8acf85f4334d
7
+ data.tar.gz: 84de08ff27a4fcec4d7a07b7e06e589ffda10adc91430b6b7ca689f9ac48dcb9b23bd982964ea48f28dafe446889a80412718e94f1f2a1ca45e1aff594884d3d
@@ -1,6 +1,10 @@
1
+ dist: xenial
1
2
  language: ruby
3
+ before_install:
4
+ - gem update --system
5
+ - gem install bundler
2
6
  rvm:
3
- - 2.0.0-p648
4
- - 2.1.9
5
- - 2.2.5
6
- - 2.3.1
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+ - 2.6
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
+ [![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/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`)
@@ -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', '~> 12.3'
25
+ spec.add_development_dependency 'rspec', '~> 3.8'
26
+ spec.add_development_dependency 'aruba', '~> 0.14'
27
27
  end
@@ -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
@@ -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.3.0'
3
3
  end
@@ -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
@@ -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
@@ -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.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: 2016-08-07 00:00:00.000000000 Z
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: '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: '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: '0'
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: '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: '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
- rubyforge_project:
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: