csvlint 1.2.0 → 1.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
2
  SHA256:
3
- metadata.gz: 1b539755c5a3e55301ec58027cdfe2df880109aeee0e4c130bdab1e40e1dd38f
4
- data.tar.gz: f2d6f801c28e86b75de094302fce55054232f7b3ffd85a8278faab1a6f2fdaba
3
+ metadata.gz: 0d15e75580e44bba3f1f8965b348f0ccfe088c6fb60e881b9f997c99fc05a7cc
4
+ data.tar.gz: 0bdf3cbec5a855f68abec7c2dccaa4f90db70955459044f7cfc67cbec963f9b8
5
5
  SHA512:
6
- metadata.gz: 66ac4e79de88c7a7aa58106ae2e4c030e63e94e5cc1609cd3ac1b5ec72c2f2dc64755f05172da23cfd306fa60c4254bd90a9fa60280ea7e15c08379a76ca489c
7
- data.tar.gz: 42fcb514ba728eaf7c957033e08dbc9ce1e9c9bfc92c94229ac158b22dd8267cf47c911dde294325c5f51ac314d359d8dcd97932966a4ac324ae6e932e7a234c
6
+ metadata.gz: 0c86225f94173f87c44bd337975b3716c9b1ec629aa6d784e4b309724655d2af5eaa118fda1d1f139f0d6a432cfeb1536e7076603a2a4b0e94fe18278d28dcb9
7
+ data.tar.gz: 4986940f1b2d928d85ae65b01a8c2c3eede4f352218a5ad18aa761a153fcd0a1530189e418a1e38aa4c0544c998f19944a8de290ef924d6f539d959fa2dcca8f
@@ -5,14 +5,34 @@ on:
5
5
  pull_request:
6
6
  branches: [ main ]
7
7
  jobs:
8
- test:
8
+ appraisal:
9
+ name: Ruby ${{ matrix.ruby-version }} / Rails ${{ matrix.activesupport-version }}
9
10
  runs-on: ubuntu-latest
10
11
  strategy:
11
12
  matrix:
12
- ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
13
+ ruby-version: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3']
14
+ activesupport-version:
15
+ - activesupport_5.2
16
+ - activesupport_6.0
17
+ - activesupport_6.1
18
+ - activesupport_7.0
19
+ - activesupport_7.1
20
+ exclude:
21
+ - ruby-version: '2.5'
22
+ activesupport-version: activesupport_7.0
23
+ - ruby-version: '2.6'
24
+ activesupport-version: activesupport_7.0
25
+ - ruby-version: '2.5'
26
+ activesupport-version: activesupport_7.1
27
+ - ruby-version: '2.6'
28
+ activesupport-version: activesupport_7.1
13
29
  fail-fast: false
30
+
31
+ env:
32
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.activesupport-version }}.gemfile
33
+
14
34
  steps:
15
- - uses: actions/checkout@v3
35
+ - uses: actions/checkout@v4
16
36
  - uses: ruby/setup-ruby@v1
17
37
  with:
18
38
  bundler-cache: true
@@ -21,14 +41,15 @@ jobs:
21
41
  run: bundle install
22
42
  - name: Run the tests
23
43
  run: bundle exec rake
44
+
24
45
  lint:
25
46
  runs-on: ubuntu-latest
26
47
  steps:
27
- - uses: actions/checkout@v2
48
+ - uses: actions/checkout@v4
28
49
  - uses: ruby/setup-ruby@v1
29
50
  with:
30
51
  bundler-cache: true
31
- ruby-version: "3.2"
52
+ ruby-version: "3.3"
32
53
  - name: Install dependencies
33
54
  run: bundle install
34
55
  - name: Run the tests
data/.gitignore CHANGED
@@ -27,3 +27,5 @@ bin/run-csvw-tests
27
27
 
28
28
  csvlint-earl.ttl
29
29
  .byebug_history
30
+
31
+ gemfiles/*.lock
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.2.0
1
+ 3.3.0
data/.standard_todo.yml CHANGED
@@ -2,14 +2,8 @@
2
2
  # Remove from this list as you refactor files.
3
3
  ---
4
4
  ignore:
5
- - features/step_definitions/validation_errors_steps.rb:
6
- - Lint/Void
7
5
  - features/support/load_tests.rb:
8
- - Style/For
9
6
  - Security/Open
10
- - Lint/UselessAssignment
11
- - lib/csvlint/cli.rb:
12
- - Style/NonNilCheck
13
7
  - lib/csvlint/csvw/column.rb:
14
8
  - Style/TernaryParentheses
15
9
  - lib/csvlint/csvw/date_format.rb:
@@ -41,3 +35,7 @@ ignore:
41
35
  - Lint/NonLocalExitFromIterator
42
36
  - spec/validator_spec.rb:
43
37
  - Lint/UselessAssignment
38
+ - lib/csvlint/schema.rb:
39
+ - Lint/UselessRescue
40
+ - lib/csvlint/validate.rb:
41
+ - Lint/UselessRescue
data/Appraisals ADDED
@@ -0,0 +1,22 @@
1
+ # After a new entry: `bundle exec appraisal install`
2
+ # Add an entry in `.github/workflows/push.yml`'s file
3
+
4
+ appraise "activesupport_5.2" do
5
+ gem "activesupport", "~> 5.2.0"
6
+ end
7
+
8
+ appraise "activesupport_6.0" do
9
+ gem "activesupport", "~> 6.0.0"
10
+ end
11
+
12
+ appraise "activesupport_6.1" do
13
+ gem "activesupport", "~> 6.1.0"
14
+ end
15
+
16
+ appraise "activesupport_7.0" do
17
+ gem "activesupport", "~> 7.0.0"
18
+ end
19
+
20
+ appraise "activesupport_7.1" do
21
+ gem "activesupport", "~> 7.1.0"
22
+ end
data/README.md CHANGED
@@ -17,7 +17,7 @@ A ruby gem to support validating CSV files to check their syntax and contents. Y
17
17
 
18
18
  ## Development
19
19
 
20
- `ruby version 3.2`
20
+ `ruby version 3.3`
21
21
 
22
22
  ### Tests
23
23
 
data/csvlint.gemspec CHANGED
@@ -16,8 +16,9 @@ Gem::Specification.new do |spec|
16
16
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
17
  spec.require_paths = ["lib"]
18
18
 
19
- spec.required_ruby_version = [">= 2.5", "< 3.3"]
19
+ spec.required_ruby_version = [">= 2.5", "< 3.4"]
20
20
 
21
+ spec.add_dependency "csv"
21
22
  spec.add_dependency "rainbow"
22
23
  spec.add_dependency "open_uri_redirections"
23
24
  spec.add_dependency "activesupport"
@@ -47,4 +48,5 @@ Gem::Specification.new do |spec|
47
48
  spec.add_development_dependency "rdf-turtle"
48
49
  spec.add_development_dependency "henry"
49
50
  spec.add_development_dependency "standardrb"
51
+ spec.add_development_dependency "appraisal"
50
52
  end
@@ -16,7 +16,7 @@ def cache_file(filename)
16
16
  unless File.exist?(file)
17
17
  if filename.include? "/"
18
18
  levels = filename.split("/")[0..-2]
19
- for i in 0..levels.length
19
+ (0..levels.length).each do |i|
20
20
  dir = File.join(BASE_PATH, levels[0..i].join("/"))
21
21
  Dir.mkdir(dir) unless Dir.exist?(dir)
22
22
  end
@@ -26,7 +26,7 @@ def cache_file(filename)
26
26
  f.puts URI.open(uri, "rb").read
27
27
  end
28
28
  end
29
- [uri, file]
29
+ uri
30
30
  end
31
31
 
32
32
  unless File.exist? SCRIPT_FILE_PATH
@@ -66,7 +66,7 @@ unless File.exist? VALIDATION_FEATURE_FILE_PATH
66
66
  file.puts ""
67
67
 
68
68
  manifest["entries"].each do |entry|
69
- action_uri, action_file = cache_file(entry["action"])
69
+ action_uri = cache_file(entry["action"])
70
70
  metadata = nil
71
71
  provided_files = []
72
72
  missing_files = []
@@ -98,7 +98,7 @@ unless File.exist? VALIDATION_FEATURE_FILE_PATH
98
98
  missing_files << URI.join(action_uri, "csv-metadata.json").to_s
99
99
  end
100
100
  entry["implicit"]&.each do |implicit|
101
- implicit_uri, implicit_file = cache_file(implicit)
101
+ implicit_uri = cache_file(implicit)
102
102
  provided_files << implicit_uri.to_s
103
103
  unless implicit_uri == metadata
104
104
  file.puts "\t\tAnd I have a file called \"csvw/#{implicit}\" at the url \"#{implicit_uri}\""
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 5.2.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 6.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 7.0.0"
6
+
7
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activesupport", "~> 7.1.0"
6
+
7
+ gemspec path: "../"
data/lib/csvlint/cli.rb CHANGED
@@ -105,7 +105,7 @@ module Csvlint
105
105
  end
106
106
  output_string = "#{index + 1}. "
107
107
  if error.column && @schema && @schema.instance_of?(Csvlint::Schema)
108
- if @schema.fields[error.column - 1] != nil
108
+ unless @schema.fields[error.column - 1].nil?
109
109
  output_string += "#{@schema.fields[error.column - 1].name}: "
110
110
  end
111
111
  end
@@ -176,7 +176,7 @@ module Csvlint
176
176
  col: error.column
177
177
  }
178
178
 
179
- if error.column && @schema && @schema.instance_of?(Csvlint::Schema) && @schema.fields[error.column - 1] != nil
179
+ if error.column && @schema && @schema.instance_of?(Csvlint::Schema) && !@schema.fields[error.column - 1].nil?
180
180
  field = @schema.fields[error.column - 1]
181
181
  h[:header] = field.name
182
182
  h[:constraints] = field.constraints.map { |k, v| [k.underscore, v] }.to_h
@@ -126,14 +126,14 @@ module Csvlint
126
126
  format = Csvlint::Csvw::DateFormat.new(nil, type) if format.nil?
127
127
  v = format.parse(value)
128
128
  return nil, warning if v.nil?
129
- return v, nil
129
+ [v, nil]
130
130
  }
131
131
  end
132
132
 
133
133
  def create_regexp_based_parser(regexp, warning)
134
134
  lambda { |value, format|
135
135
  return nil, warning unless value&.match?(regexp)
136
- return value, nil
136
+ [value, nil]
137
137
  }
138
138
  end
139
139
 
@@ -256,14 +256,14 @@ module Csvlint
256
256
  "http://www.w3.org/2001/XMLSchema#time" => NO_ADDITIONAL_VALIDATION
257
257
  }
258
258
 
259
- TRIM_VALUE = lambda { |value, format| return value.strip, nil }
260
- ALL_VALUES_VALID = lambda { |value, format| return value, nil }
259
+ TRIM_VALUE = lambda { |value, format| [value.strip, nil] }
260
+ ALL_VALUES_VALID = lambda { |value, format| [value, nil] }
261
261
 
262
262
  NUMERIC_PARSER = lambda { |value, format, integer = false|
263
263
  format = Csvlint::Csvw::NumberFormat.new(nil, nil, ".", integer) if format.nil?
264
264
  v = format.parse(value)
265
265
  return nil, :invalid_number if v.nil?
266
- return v, nil
266
+ [v, nil]
267
267
  }
268
268
 
269
269
  DATATYPE_PARSER = {
@@ -281,7 +281,7 @@ module Csvlint
281
281
  return true, nil if value == format[0]
282
282
  return false, nil if value == format[1]
283
283
  end
284
- return value, :invalid_boolean
284
+ [value, :invalid_boolean]
285
285
  },
286
286
  "http://www.w3.org/2001/XMLSchema#date" =>
287
287
  create_date_parser("http://www.w3.org/2001/XMLSchema#date", :invalid_date),
@@ -291,85 +291,85 @@ module Csvlint
291
291
  create_date_parser("http://www.w3.org/2001/XMLSchema#dateTimeStamp", :invalid_date_time_stamp),
292
292
  "http://www.w3.org/2001/XMLSchema#decimal" => lambda { |value, format|
293
293
  return nil, :invalid_decimal if /(E|e|^(NaN|INF|-INF)$)/.match?(value)
294
- return NUMERIC_PARSER.call(value, format)
294
+ NUMERIC_PARSER.call(value, format)
295
295
  },
296
296
  "http://www.w3.org/2001/XMLSchema#integer" => lambda { |value, format|
297
297
  v, w = NUMERIC_PARSER.call(value, format, true)
298
298
  return v, :invalid_integer unless w.nil?
299
299
  return nil, :invalid_integer unless v.is_a? Integer
300
- return v, w
300
+ [v, w]
301
301
  },
302
302
  "http://www.w3.org/2001/XMLSchema#long" => lambda { |value, format|
303
303
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
304
304
  return v, :invalid_long unless w.nil?
305
305
  return nil, :invalid_long unless v <= 9223372036854775807 && v >= -9223372036854775808
306
- return v, w
306
+ [v, w]
307
307
  },
308
308
  "http://www.w3.org/2001/XMLSchema#int" => lambda { |value, format|
309
309
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
310
310
  return v, :invalid_int unless w.nil?
311
311
  return nil, :invalid_int unless v <= 2147483647 && v >= -2147483648
312
- return v, w
312
+ [v, w]
313
313
  },
314
314
  "http://www.w3.org/2001/XMLSchema#short" => lambda { |value, format|
315
315
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
316
316
  return v, :invalid_short unless w.nil?
317
317
  return nil, :invalid_short unless v <= 32767 && v >= -32768
318
- return v, w
318
+ [v, w]
319
319
  },
320
320
  "http://www.w3.org/2001/XMLSchema#byte" => lambda { |value, format|
321
321
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
322
322
  return v, :invalid_byte unless w.nil?
323
323
  return nil, :invalid_byte unless v <= 127 && v >= -128
324
- return v, w
324
+ [v, w]
325
325
  },
326
326
  "http://www.w3.org/2001/XMLSchema#nonNegativeInteger" => lambda { |value, format|
327
327
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
328
328
  return v, :invalid_nonNegativeInteger unless w.nil?
329
329
  return nil, :invalid_nonNegativeInteger unless v >= 0
330
- return v, w
330
+ [v, w]
331
331
  },
332
332
  "http://www.w3.org/2001/XMLSchema#positiveInteger" => lambda { |value, format|
333
333
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
334
334
  return v, :invalid_positiveInteger unless w.nil?
335
335
  return nil, :invalid_positiveInteger unless v > 0
336
- return v, w
336
+ [v, w]
337
337
  },
338
338
  "http://www.w3.org/2001/XMLSchema#unsignedLong" => lambda { |value, format|
339
339
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#nonNegativeInteger"].call(value, format)
340
340
  return v, :invalid_unsignedLong unless w.nil?
341
341
  return nil, :invalid_unsignedLong unless v <= 18446744073709551615
342
- return v, w
342
+ [v, w]
343
343
  },
344
344
  "http://www.w3.org/2001/XMLSchema#unsignedInt" => lambda { |value, format|
345
345
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#nonNegativeInteger"].call(value, format)
346
346
  return v, :invalid_unsignedInt unless w.nil?
347
347
  return nil, :invalid_unsignedInt unless v <= 4294967295
348
- return v, w
348
+ [v, w]
349
349
  },
350
350
  "http://www.w3.org/2001/XMLSchema#unsignedShort" => lambda { |value, format|
351
351
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#nonNegativeInteger"].call(value, format)
352
352
  return v, :invalid_unsignedShort unless w.nil?
353
353
  return nil, :invalid_unsignedShort unless v <= 65535
354
- return v, w
354
+ [v, w]
355
355
  },
356
356
  "http://www.w3.org/2001/XMLSchema#unsignedByte" => lambda { |value, format|
357
357
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#nonNegativeInteger"].call(value, format)
358
358
  return v, :invalid_unsignedByte unless w.nil?
359
359
  return nil, :invalid_unsignedByte unless v <= 255
360
- return v, w
360
+ [v, w]
361
361
  },
362
362
  "http://www.w3.org/2001/XMLSchema#nonPositiveInteger" => lambda { |value, format|
363
363
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
364
364
  return v, :invalid_nonPositiveInteger unless w.nil?
365
365
  return nil, :invalid_nonPositiveInteger unless v <= 0
366
- return v, w
366
+ [v, w]
367
367
  },
368
368
  "http://www.w3.org/2001/XMLSchema#negativeInteger" => lambda { |value, format|
369
369
  v, w = DATATYPE_PARSER["http://www.w3.org/2001/XMLSchema#integer"].call(value, format)
370
370
  return v, :invalid_negativeInteger unless w.nil?
371
371
  return nil, :invalid_negativeInteger unless v < 0
372
- return v, w
372
+ [v, w]
373
373
  },
374
374
  "http://www.w3.org/2001/XMLSchema#double" => NUMERIC_PARSER,
375
375
  # regular expressions here taken from XML Schema datatypes spec
@@ -60,7 +60,7 @@ module Csvlint
60
60
  raise Csvlint::Csvw::MetadataError.new, "common property with @value has properties other than @language or @type" unless value.except("@type").except("@language").except("@value").empty?
61
61
  when "@language"
62
62
  raise Csvlint::Csvw::MetadataError.new, "common property with @language lacks a @value" unless value["@value"]
63
- raise Csvlint::Csvw::MetadataError.new, "common property has invalid @language (#{v})" unless ((v.is_a? String) && (v =~ BCP47_LANGUAGE_REGEXP)) || v.nil?
63
+ raise Csvlint::Csvw::MetadataError.new, "common property has invalid @language (#{v})" if !((v.is_a? String) && (v =~ BCP47_LANGUAGE_REGEXP)) || !v.nil?
64
64
  else
65
65
  if p[0] == "@"
66
66
  raise Csvlint::Csvw::MetadataError.new, "common property has property other than @id, @type, @value or @language beginning with @ (#{p})"
@@ -99,7 +99,7 @@ module Csvlint
99
99
  v = format.parse(value[property])
100
100
  if v.nil?
101
101
  value.delete(property)
102
- return [":invalid_#{property}".to_sym]
102
+ return [:":invalid_#{property}"]
103
103
  else
104
104
  value[property] = v
105
105
  return []
@@ -116,35 +116,35 @@ module Csvlint
116
116
  def array_property(type)
117
117
  lambda { |value, base_url, lang|
118
118
  return value, nil, type if value.instance_of? Array
119
- return false, :invalid_value, type
119
+ [false, :invalid_value, type]
120
120
  }
121
121
  end
122
122
 
123
123
  def boolean_property(type)
124
124
  lambda { |value, base_url, lang|
125
125
  return value, nil, type if value == true || value == false
126
- return false, :invalid_value, type
126
+ [false, :invalid_value, type]
127
127
  }
128
128
  end
129
129
 
130
130
  def string_property(type)
131
131
  lambda { |value, base_url, lang|
132
132
  return value, nil, type if value.instance_of? String
133
- return "", :invalid_value, type
133
+ ["", :invalid_value, type]
134
134
  }
135
135
  end
136
136
 
137
137
  def uri_template_property(type)
138
138
  lambda { |value, base_url, lang|
139
139
  return URITemplate.new(value), nil, type if value.instance_of? String
140
- return URITemplate.new(""), :invalid_value, type
140
+ [URITemplate.new(""), :invalid_value, type]
141
141
  }
142
142
  end
143
143
 
144
144
  def numeric_property(type)
145
145
  lambda { |value, base_url, lang|
146
146
  return value, nil, type if value.is_a?(Integer) && value >= 0
147
- return nil, :invalid_value, type
147
+ [nil, :invalid_value, type]
148
148
  }
149
149
  end
150
150
 
@@ -152,14 +152,14 @@ module Csvlint
152
152
  lambda { |value, base_url, lang|
153
153
  raise Csvlint::Csvw::MetadataError.new, "URL #{value} starts with _:" if /^_:/.match?(value.to_s)
154
154
  return (base_url.nil? ? URI(value) : URI.join(base_url, value)), nil, type if value.instance_of? String
155
- return base_url, :invalid_value, type
155
+ [base_url, :invalid_value, type]
156
156
  }
157
157
  end
158
158
 
159
159
  def language_property(type)
160
160
  lambda { |value, base_url, lang|
161
161
  return value, nil, type if BCP47_REGEXP.match?(value)
162
- return nil, :invalid_value, type
162
+ [nil, :invalid_value, type]
163
163
  }
164
164
  end
165
165
 
@@ -167,7 +167,7 @@ module Csvlint
167
167
  lambda { |value, base_url, lang|
168
168
  warnings = []
169
169
  if value.instance_of? String
170
- return {lang => [value]}, nil, type
170
+ [{lang => [value]}, nil, type]
171
171
  elsif value.instance_of? Array
172
172
  valid_titles = []
173
173
  value.each do |title|
@@ -177,7 +177,7 @@ module Csvlint
177
177
  warnings << :invalid_value
178
178
  end
179
179
  end
180
- return {lang => valid_titles}, warnings, type
180
+ [{lang => valid_titles}, warnings, type]
181
181
  elsif value.instance_of? Hash
182
182
  value = value.clone
183
183
  value.each do |l, v|
@@ -197,16 +197,16 @@ module Csvlint
197
197
  end
198
198
  end
199
199
  warnings << :invalid_value if value.empty?
200
- return value, warnings, type
200
+ [value, warnings, type]
201
201
  else
202
- return {}, :invalid_value, type
202
+ [{}, :invalid_value, type]
203
203
  end
204
204
  }
205
205
  end
206
206
 
207
207
  def column_reference_property(type)
208
208
  lambda { |value, base_url, lang|
209
- return Array(value), nil, type
209
+ [Array(value), nil, type]
210
210
  }
211
211
  end
212
212
  end
@@ -226,7 +226,7 @@ module Csvlint
226
226
  values << v
227
227
  warnings += w
228
228
  end
229
- return values, warnings, :common
229
+ [values, warnings, :common]
230
230
  },
231
231
  "suppressOutput" => boolean_property(:common),
232
232
  "dialect" => lambda { |value, base_url, lang|
@@ -249,16 +249,16 @@ module Csvlint
249
249
  end
250
250
  end
251
251
  end
252
- return value, warnings, :common
252
+ [value, warnings, :common]
253
253
  else
254
- return {}, :invalid_value, :common
254
+ [{}, :invalid_value, :common]
255
255
  end
256
256
  },
257
257
  # inherited properties
258
258
  "null" => lambda { |value, base_url, lang|
259
259
  case value
260
260
  when String
261
- return [value], nil, :inherited
261
+ [[value], nil, :inherited]
262
262
  when Array
263
263
  values = []
264
264
  warnings = []
@@ -269,15 +269,15 @@ module Csvlint
269
269
  warnings << :invalid_value
270
270
  end
271
271
  end
272
- return values, warnings, :inherited
272
+ [values, warnings, :inherited]
273
273
  else
274
- return [""], :invalid_value, :inherited
274
+ [[""], :invalid_value, :inherited]
275
275
  end
276
276
  },
277
277
  "default" => string_property(:inherited),
278
278
  "separator" => lambda { |value, base_url, lang|
279
279
  return value, nil, :inherited if value.instance_of?(String) || value.nil?
280
- return nil, :invalid_value, :inherited
280
+ [nil, :invalid_value, :inherited]
281
281
  },
282
282
  "lang" => language_property(:inherited),
283
283
  "datatype" => lambda { |value, base_url, lang|
@@ -387,7 +387,7 @@ module Csvlint
387
387
  end
388
388
  end
389
389
  end
390
- return value, warnings, :inherited
390
+ [value, warnings, :inherited]
391
391
  },
392
392
  "required" => boolean_property(:inherited),
393
393
  "ordered" => boolean_property(:inherited),
@@ -397,14 +397,14 @@ module Csvlint
397
397
  "textDirection" => lambda { |value, base_url, lang|
398
398
  value = value.to_sym
399
399
  return value, nil, :inherited if [:ltr, :rtl, :auto, :inherit].include? value
400
- return :inherit, :invalid_value, :inherited
400
+ [:inherit, :invalid_value, :inherited]
401
401
  },
402
402
  # column level properties
403
403
  "virtual" => boolean_property(:column),
404
404
  "titles" => natural_language_property(:column),
405
405
  "name" => lambda { |value, base_url, lang|
406
406
  return value, nil, :column if value.instance_of?(String) && value =~ NAME_REGEXP
407
- return nil, :invalid_value, :column
407
+ [nil, :invalid_value, :column]
408
408
  },
409
409
  # table level properties
410
410
  "transformations" => lambda { |value, base_url, lang|
@@ -423,7 +423,7 @@ module Csvlint
423
423
  elsif p == "titles"
424
424
  else
425
425
  v, warning, type = check_property(p, v, base_url, lang)
426
- unless type == :transformation && (warning.nil? || warning.empty?)
426
+ if type != :transformation && !(warning.nil? || warning.empty?)
427
427
  value.delete(p)
428
428
  warnings << :invalid_property unless type == :transformation
429
429
  warnings += Array(warning)
@@ -438,12 +438,12 @@ module Csvlint
438
438
  else
439
439
  warnings << :invalid_value
440
440
  end
441
- return transformations, warnings, :table
441
+ [transformations, warnings, :table]
442
442
  },
443
443
  "tableDirection" => lambda { |value, base_url, lang|
444
444
  value = value.to_sym
445
445
  return value, nil, :table if [:ltr, :rtl, :auto].include? value
446
- return :auto, :invalid_value, :table
446
+ [:auto, :invalid_value, :table]
447
447
  },
448
448
  "tableSchema" => lambda { |value, base_url, lang|
449
449
  schema_base_url = base_url
@@ -483,7 +483,7 @@ module Csvlint
483
483
  end
484
484
  end
485
485
  end
486
- return schema, warnings, :table
486
+ [schema, warnings, :table]
487
487
  },
488
488
  "url" => link_property(:table),
489
489
  # dialect properties
@@ -492,7 +492,7 @@ module Csvlint
492
492
  "doubleQuote" => boolean_property(:dialect),
493
493
  "encoding" => lambda { |value, base_url, lang|
494
494
  return value, nil, :dialect if VALID_ENCODINGS.include? value
495
- return nil, :invalid_value, :dialect
495
+ [nil, :invalid_value, :dialect]
496
496
  },
497
497
  "header" => boolean_property(:dialect),
498
498
  "headerRowCount" => numeric_property(:dialect),
@@ -508,10 +508,10 @@ module Csvlint
508
508
  value = :start if value == "start"
509
509
  value = :end if value == "end"
510
510
  return value, nil, :dialect if [:true, :false, :start, :end].include? value
511
- return true, :invalid_value, :dialect
511
+ [true, :invalid_value, :dialect]
512
512
  },
513
513
  # schema properties
514
- "columns" => lambda { |value, base_url, lang| return value, nil, :schema },
514
+ "columns" => lambda { |value, base_url, lang| [value, nil, :schema] },
515
515
  "primaryKey" => column_reference_property(:schema),
516
516
  "foreignKeys" => lambda { |value, base_url, lang|
517
517
  foreign_keys = []
@@ -540,13 +540,13 @@ module Csvlint
540
540
  else
541
541
  warnings << :invalid_value
542
542
  end
543
- return foreign_keys, warnings, :schema
543
+ [foreign_keys, warnings, :schema]
544
544
  },
545
545
  "rowTitles" => column_reference_property(:schema),
546
546
  # transformation properties
547
- "targetFormat" => lambda { |value, base_url, lang| return value, nil, :transformation },
548
- "scriptFormat" => lambda { |value, base_url, lang| return value, nil, :transformation },
549
- "source" => lambda { |value, base_url, lang| return value, nil, :transformation },
547
+ "targetFormat" => lambda { |value, base_url, lang| [value, nil, :transformation] },
548
+ "scriptFormat" => lambda { |value, base_url, lang| [value, nil, :transformation] },
549
+ "source" => lambda { |value, base_url, lang| [value, nil, :transformation] },
550
550
  # foreignKey properties
551
551
  "columnReference" => column_reference_property(:foreign_key),
552
552
  "reference" => lambda { |value, base_url, lang|
@@ -572,15 +572,15 @@ module Csvlint
572
572
  raise Csvlint::Csvw::MetadataError.new("foreignKey.reference.columnReference"), "foreignKey reference columnReference is missing" unless value["columnReference"]
573
573
  raise Csvlint::Csvw::MetadataError.new("foreignKey.reference"), "foreignKey reference does not have either resource or schemaReference" unless value["resource"] || value["schemaReference"]
574
574
  raise Csvlint::Csvw::MetadataError.new("foreignKey.reference"), "foreignKey reference has both resource and schemaReference" if value["resource"] && value["schemaReference"]
575
- return value, warnings, :foreign_key
575
+ [value, warnings, :foreign_key]
576
576
  else
577
577
  raise Csvlint::Csvw::MetadataError.new("foreignKey.reference"), "foreignKey reference is not an object"
578
578
  end
579
579
  },
580
580
  # foreignKey reference properties
581
- "resource" => lambda { |value, base_url, lang| return value, nil, :foreign_key_reference },
581
+ "resource" => lambda { |value, base_url, lang| [value, nil, :foreign_key_reference] },
582
582
  "schemaReference" => lambda { |value, base_url, lang|
583
- return URI.join(base_url, value).to_s, nil, :foreign_key_reference
583
+ [URI.join(base_url, value).to_s, nil, :foreign_key_reference]
584
584
  }
585
585
  }
586
586
 
data/lib/csvlint/field.rb CHANGED
@@ -16,7 +16,7 @@ module Csvlint
16
16
 
17
17
  def validate_column(value, row = nil, column = nil, all_errors = [])
18
18
  reset
19
- unless all_errors.any? { |error| ((error.type == :invalid_regex) && (error.column == column)) }
19
+ unless all_errors.any? { |error| (error.type == :invalid_regex) && (error.column == column) }
20
20
  validate_regex(value, row, column, all_errors)
21
21
  end
22
22
  validate_length(value, row, column)
@@ -590,14 +590,14 @@ module Csvlint
590
590
  numeric: /\A[-+]?\d*\.?\d+(?:[eE][-+]?\d+)?\z/,
591
591
  uri: /\Ahttps?:/,
592
592
  date_db: /\A\d{4,}-\d\d-\d\d\z/, # "12345-01-01"
593
- date_long: /\A(?:#{Date::MONTHNAMES.join('|')}) [ \d]\d, \d{4,}\z/, # "January 1, 12345"
594
- date_rfc822: /\A[ \d]\d (?:#{Date::ABBR_MONTHNAMES.join('|')}) \d{4,}\z/, # " 1 Jan 12345"
595
- date_short: /\A[ \d]\d (?:#{Date::ABBR_MONTHNAMES.join('|')})\z/, # "1 Jan"
593
+ date_long: /\A(?:#{Date::MONTHNAMES.join("|")}) [ \d]\d, \d{4,}\z/, # "January 1, 12345"
594
+ date_rfc822: /\A[ \d]\d (?:#{Date::ABBR_MONTHNAMES.join("|")}) \d{4,}\z/, # " 1 Jan 12345"
595
+ date_short: /\A[ \d]\d (?:#{Date::ABBR_MONTHNAMES.join("|")})\z/, # "1 Jan"
596
596
  dateTime_db: /\A\d{4,}-\d\d-\d\d \d\d:\d\d:\d\d\z/, # "12345-01-01 00:00:00"
597
597
  dateTime_hms: /\A\d\d:\d\d:\d\d\z/, # "00:00:00"
598
598
  dateTime_iso8601: /\A\d{4,}-\d\d-\d\dT\d\d:\d\d:\d\dZ\z/, # "12345-01-01T00:00:00Z"
599
- dateTime_long: /\A(?:#{Date::MONTHNAMES.join('|')}) \d\d, \d{4,} \d\d:\d\d\z/, # "January 01, 12345 00:00"
600
- dateTime_short: /\A\d\d (?:#{Date::ABBR_MONTHNAMES.join('|')}) \d\d:\d\d\z/, # "01 Jan 00:00"
599
+ dateTime_long: /\A(?:#{Date::MONTHNAMES.join("|")}) \d\d, \d{4,} \d\d:\d\d\z/, # "January 01, 12345 00:00"
600
+ dateTime_short: /\A\d\d (?:#{Date::ABBR_MONTHNAMES.join("|")}) \d\d:\d\d\z/, # "01 Jan 00:00"
601
601
  dateTime_time: /\A\d\d:\d\d\z/ # "00:00"
602
602
  }.freeze
603
603
 
@@ -1,3 +1,3 @@
1
1
  module Csvlint
2
- VERSION = "1.2.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/csvlint.rb CHANGED
@@ -4,9 +4,7 @@ require "open-uri"
4
4
  require "tempfile"
5
5
  require "typhoeus"
6
6
 
7
- require "active_support/core_ext/date/conversions"
8
- require "active_support/core_ext/time/conversions"
9
- require "active_support/core_ext/object"
7
+ require "active_support"
10
8
  require "open_uri_redirections"
11
9
  require "uri_template"
12
10
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csvlint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pezholio
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-27 00:00:00.000000000 Z
11
+ date: 2024-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rainbow
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -402,6 +416,20 @@ dependencies:
402
416
  - - ">="
403
417
  - !ruby/object:Gem::Version
404
418
  version: '0'
419
+ - !ruby/object:Gem::Dependency
420
+ name: appraisal
421
+ requirement: !ruby/object:Gem::Requirement
422
+ requirements:
423
+ - - ">="
424
+ - !ruby/object:Gem::Version
425
+ version: '0'
426
+ type: :development
427
+ prerelease: false
428
+ version_requirements: !ruby/object:Gem::Requirement
429
+ requirements:
430
+ - - ">="
431
+ - !ruby/object:Gem::Version
432
+ version: '0'
405
433
  description: CSV Validator
406
434
  email:
407
435
  - pezholio@gmail.com
@@ -421,6 +449,7 @@ files:
421
449
  - ".pre-commit-hooks.yaml"
422
450
  - ".ruby-version"
423
451
  - ".standard_todo.yml"
452
+ - Appraisals
424
453
  - CHANGELOG.md
425
454
  - CODE_OF_CONDUCT.md
426
455
  - CONTRIBUTING.md
@@ -474,6 +503,11 @@ files:
474
503
  - features/validation_errors.feature
475
504
  - features/validation_info.feature
476
505
  - features/validation_warnings.feature
506
+ - gemfiles/activesupport_5.2.gemfile
507
+ - gemfiles/activesupport_6.0.gemfile
508
+ - gemfiles/activesupport_6.1.gemfile
509
+ - gemfiles/activesupport_7.0.gemfile
510
+ - gemfiles/activesupport_7.1.gemfile
477
511
  - lib/csvlint.rb
478
512
  - lib/csvlint/cli.rb
479
513
  - lib/csvlint/csvw/column.rb
@@ -513,14 +547,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
513
547
  version: '2.5'
514
548
  - - "<"
515
549
  - !ruby/object:Gem::Version
516
- version: '3.3'
550
+ version: '3.4'
517
551
  required_rubygems_version: !ruby/object:Gem::Requirement
518
552
  requirements:
519
553
  - - ">="
520
554
  - !ruby/object:Gem::Version
521
555
  version: '0'
522
556
  requirements: []
523
- rubygems_version: 3.4.1
557
+ rubygems_version: 3.5.3
524
558
  signing_key:
525
559
  specification_version: 4
526
560
  summary: CSV Validator