csvlint 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +6 -2
- data/CHANGELOG.md +14 -0
- data/features/cli.feature +14 -0
- data/features/step_definitions/cli_steps.rb +18 -0
- data/lib/csvlint/cli.rb +36 -10
- data/lib/csvlint/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDdiMTU5MDRkOWMzODllZGVjZTE1NWU0NzgyMjNkODgzYjlkNDE3NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MmY0YjQyZTM1ODBkOTA2OWQxOGRkOWYxYmI2ZDA2NWEyZjRjM2U2YQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NWM1OGNjNDk0MzgzY2MwZmY5NjJhOTBiNDFjYTA3YjBkYTAzN2IzNzUyYjg3
|
10
|
+
NDdlZjVlYzEzZTFkMmI2ODQzZjIwY2IwZDU1Mjk5Y2QwNzdjNTg3YjYxM2Zj
|
11
|
+
MzFkNWM5ZWUzOTY1NGUzZTgyMWZhYzRhNDI2ZWI0NmQyNWNjYzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ODc3MjNlZDRmOGFmNmJiYWM4OWJmN2IzZGYzNTI5YWY1Zjg5YzZmMmYyYjhi
|
14
|
+
NWZhMjQ3ZTc4NGRhYTQ5ZjBlZjQ5ZjcwOThhYzQ5NjNhZDViZDVjYTFjYjlk
|
15
|
+
YzgwNGM3NjMxMWNkOTI4ODU1ZDM4YmIwODc4MTExOWUyZWJkYjA=
|
data/.travis.yml
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
---
|
1
2
|
rvm:
|
2
3
|
- 2.0.0
|
3
4
|
- 2.1.0
|
@@ -9,7 +10,7 @@ notifications:
|
|
9
10
|
channels:
|
10
11
|
- irc.freenode.net#theodi
|
11
12
|
template:
|
12
|
-
-
|
13
|
+
- "%{repository} %{branch} - %{message} %{build_url}"
|
13
14
|
on_success: change
|
14
15
|
on_failure: always
|
15
16
|
deploy:
|
@@ -17,7 +18,7 @@ deploy:
|
|
17
18
|
api_key:
|
18
19
|
secure: fjnPS61/skQ1PsRJu1SYWIct0vjdkTyQhj0ria9zfcJfbWbfiHnpehVh1ege3sTUkDSTvoOFT35jzEeozvtKZOlAWMU5QbL8LTXu+JSp9olOdSuGeWRWVuQT3NLgRJW0+2c7N66piZvnRUUTyt2P8VIR8c/Ltuhc32bUGL7X6Gw=
|
19
20
|
gem: csvlint
|
20
|
-
|
21
|
+
true:
|
21
22
|
tags: true
|
22
23
|
repo: theodi/csvlint.rb
|
23
24
|
all_branches: true
|
@@ -26,7 +27,10 @@ after_success:
|
|
26
27
|
- '[ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && curl
|
27
28
|
-v -X POST -d ''{"ref":"refs/tags/''$GEM_VERSION''","sha":"''$TRAVIS_COMMIT''"}'' --header
|
28
29
|
"Content-Type:application/json" -u $GITHUB_USER:$GITHUB_PASSWORD "https://api.github.com/repos/$TRAVIS_REPO_SLUG/git/refs"'
|
30
|
+
- gem install henry
|
31
|
+
- henry deploy
|
29
32
|
env:
|
30
33
|
global:
|
31
34
|
- secure: hM8Pv/EAZoB4fGGEUwKQQ/2+mgKbUac+PH2cwud25l2MJ64eoKEMZzfy4TF6+XMIzXhlWpsg4s51y6K3+W8pUyRAuwo2MsN5Iee7HnLz+LlYTiT0//iQdAmxQ0JlOyh8vd2SEFBcVfwpp/iZFIHAfbBO73ZDXhtGMEieMk025I0=
|
32
35
|
- secure: hsKbZ0kVKVU/e8oVCPJpRmBxbbieN2tVbyjdhJo/UYchcyLWeGAmAj/ApUDL4SyR0HZxpfi+SIsGFNRy5LnrFeCFgY9aZ6u9ma4n0Y2cTElMRt5kvI/c28FehsRjCzAe6W8dxwhJ8wSkvFDNpLml47/iy8bw4a7aUZDdq3OYXck=
|
36
|
+
- secure: FW0iyoq4yS55yVTxWXv0OrnOQWuUzpsv32w0FsE7E6OgS/UtCSAQeXO+T448+JXVbJClQDQNM9Pimdfzz/znGzHF6//UVmIbxfKwbyGtvzg4dZUexK8KlGnQy1na/4qiOi5xBSQQ5q/CwtblkCkklhDIs8CwV1M7mCIK5Sf0HZ4=
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [0.3.0](https://github.com/theodi/csvlint.rb/tree/0.3.0) (2016-01-12)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/theodi/csvlint.rb/compare/0.2.6...0.3.0)
|
6
|
+
|
7
|
+
**Merged pull requests:**
|
8
|
+
|
9
|
+
- still increment current\_line after invalid\_encoding error [\#174](https://github.com/theodi/csvlint.rb/pull/174) ([wjordan213](https://github.com/wjordan213))
|
10
|
+
|
11
|
+
- Support for CSV on the Web transformations [\#173](https://github.com/theodi/csvlint.rb/pull/173) ([JeniT](https://github.com/JeniT))
|
12
|
+
|
13
|
+
## [0.2.6](https://github.com/theodi/csvlint.rb/tree/0.2.6) (2015-11-16)
|
14
|
+
|
15
|
+
[Full Changelog](https://github.com/theodi/csvlint.rb/compare/0.2.5...0.2.6)
|
16
|
+
|
3
17
|
## [0.2.5](https://github.com/theodi/csvlint.rb/tree/0.2.5) (2015-11-16)
|
4
18
|
|
5
19
|
[Full Changelog](https://github.com/theodi/csvlint.rb/compare/0.2.4...0.2.5)
|
data/features/cli.feature
CHANGED
@@ -65,6 +65,20 @@ Feature: CSVlint CLI
|
|
65
65
|
Then the output should contain "http://example.com/example1.csv is INVALID"
|
66
66
|
And the output should contain "whitespace"
|
67
67
|
|
68
|
+
Scenario: Invalid CSV from url with JSON
|
69
|
+
Given I have a CSV with the following content:
|
70
|
+
"""
|
71
|
+
"Foo", "Bar" , "Baz"
|
72
|
+
"""
|
73
|
+
And it is stored at the url "http://example.com/example1.csv"
|
74
|
+
When I run `csvlint http://example.com/example1.csv --json`
|
75
|
+
Then the output should contain JSON
|
76
|
+
And the JSON should have a state of "invalid"
|
77
|
+
And the JSON should have 1 error
|
78
|
+
And that error should have the "type" "whitespace"
|
79
|
+
And that error should have the "category" "structure"
|
80
|
+
And that error should have the "row" "1"
|
81
|
+
|
68
82
|
Scenario: Specify schema
|
69
83
|
Given I have a CSV with the following content:
|
70
84
|
"""
|
@@ -9,3 +9,21 @@ end
|
|
9
9
|
Then(/^nothing should be outputted to STDERR$/) do
|
10
10
|
expect(STDERR).to_not receive(:puts)
|
11
11
|
end
|
12
|
+
|
13
|
+
Then(/^the output should contain JSON$/) do
|
14
|
+
@json = JSON.parse(all_stdout)
|
15
|
+
expect(@json['validation']).to be_present
|
16
|
+
end
|
17
|
+
|
18
|
+
Then(/^the JSON should have a state of "(.*?)"$/) do |state|
|
19
|
+
expect(@json['validation']['state']).to eq(state)
|
20
|
+
end
|
21
|
+
|
22
|
+
Then(/^the JSON should have (\d+) error$/) do |count|
|
23
|
+
@index = count.to_i - 1
|
24
|
+
expect(@json['validation']['errors'].count).to eq(count.to_i)
|
25
|
+
end
|
26
|
+
|
27
|
+
Then(/^that error should have the "(.*?)" "(.*?)"$/) do |k, v|
|
28
|
+
expect(@json['validation']['errors'][@index][k].to_s).to eq(v)
|
29
|
+
end
|
data/lib/csvlint/cli.rb
CHANGED
@@ -10,12 +10,13 @@ module Csvlint
|
|
10
10
|
desc "myfile.csv OR csvlint http://example.com/myfile.csv", "Supports validating CSV files to check their syntax and contents"
|
11
11
|
option :dump_errors, desc: "Pretty print error and warning objects.", type: :boolean, aliases: :d
|
12
12
|
option :schema, banner: "FILENAME OR URL", desc: "Schema file", aliases: :s
|
13
|
+
option :json, desc: "Output errors as JSON", type: :boolean, aliases: :j
|
13
14
|
def validate(source = nil)
|
14
15
|
source = read_source(source)
|
15
16
|
@schema = get_schema(options[:schema]) if options[:schema]
|
16
17
|
fetch_schema_tables(@schema, options) if source.nil?
|
17
18
|
|
18
|
-
valid = validate_csv(source, @schema, options[:dump])
|
19
|
+
valid = validate_csv(source, @schema, options[:dump], options[:json])
|
19
20
|
exit 1 unless valid
|
20
21
|
end
|
21
22
|
|
@@ -77,7 +78,7 @@ module Csvlint
|
|
77
78
|
rescue Errno::ENOENT
|
78
79
|
return_error "#{source} not found"
|
79
80
|
end unless source =~ /^http(s)?/
|
80
|
-
valid &= validate_csv(source, schema, options[:dump])
|
81
|
+
valid &= validate_csv(source, schema, options[:dump], nil)
|
81
82
|
end
|
82
83
|
|
83
84
|
exit 1 unless valid
|
@@ -124,10 +125,14 @@ module Csvlint
|
|
124
125
|
exit 1
|
125
126
|
end
|
126
127
|
|
127
|
-
def validate_csv(source, schema, dump)
|
128
|
+
def validate_csv(source, schema, dump, json)
|
128
129
|
@error_count = 0
|
129
130
|
|
130
|
-
|
131
|
+
if json === true
|
132
|
+
validator = Csvlint::Validator.new( source, {}, schema )
|
133
|
+
else
|
134
|
+
validator = Csvlint::Validator.new( source, {}, schema, { lambda: report_lines } )
|
135
|
+
end
|
131
136
|
|
132
137
|
if source.class == String
|
133
138
|
csv = source
|
@@ -137,18 +142,39 @@ module Csvlint
|
|
137
142
|
csv = "CSV"
|
138
143
|
end
|
139
144
|
|
140
|
-
if
|
141
|
-
|
145
|
+
if json === true
|
146
|
+
json = {
|
147
|
+
validation: {
|
148
|
+
state: validator.valid? ? "valid" : "invalid",
|
149
|
+
errors: validator.errors.map { |v| hashify(v) },
|
150
|
+
warnings: validator.warnings.map { |v| hashify(v) },
|
151
|
+
info: validator.info_messages.map { |v| hashify(v) },
|
152
|
+
}
|
153
|
+
}.to_json
|
154
|
+
print json
|
142
155
|
else
|
143
|
-
|
144
|
-
|
156
|
+
if $stdout.tty?
|
157
|
+
puts "\r\n#{csv} is #{validator.valid? ? "VALID".green : "INVALID".red}"
|
158
|
+
else
|
159
|
+
puts "\r\n#{csv} is #{validator.valid? ? "VALID" : "INVALID"}"
|
160
|
+
end
|
145
161
|
|
146
|
-
|
147
|
-
|
162
|
+
print_errors(validator.errors, dump)
|
163
|
+
print_errors(validator.warnings, dump)
|
164
|
+
end
|
148
165
|
|
149
166
|
return validator.valid?
|
150
167
|
end
|
151
168
|
|
169
|
+
def hashify(error)
|
170
|
+
{
|
171
|
+
type: error.type,
|
172
|
+
category: error.category,
|
173
|
+
row: error.row,
|
174
|
+
col: error.column,
|
175
|
+
}
|
176
|
+
end
|
177
|
+
|
152
178
|
def report_lines
|
153
179
|
lambda do |row|
|
154
180
|
new_errors = row.errors.count
|
data/lib/csvlint/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csvlint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pezholio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mime-types
|