Skip to content

Commit

Permalink
refactor(csv-parse)!: rename RECORD_DONT_MATCH_COLUMNS_LENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Nov 6, 2021
1 parent 0376af7 commit fb391c9
Show file tree
Hide file tree
Showing 17 changed files with 22 additions and 41 deletions.
1 change: 0 additions & 1 deletion packages/csv-parse/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ We invite you to join and contribute but create an issue before engaging any wor
* encoding: new encoding_input and encoding_output options (medium)
* `columns_duplicates_to_array`: this is just too long but I don't have much insipiration for a better name
* `relax_column_count`: rename INCONSISTENT_RECORD_LENGTH to RECORD_INCONSISTENT_FIELDS_LENGTH (easy)
* `relax_column_count`: rename RECORD_DONT_MATCH_COLUMNS_LENGTH to RECORD_INCONSISTENT_COLUMNS (easy)
* `info`: remove the `parser.info` object and move its properties to `state`
* `info`: rename the `info` related properties and functions to `context`
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5889,9 +5889,7 @@ class Parser extends Transform {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/dist/cjs/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export type CsvErrorCode =
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
| 'CSV_QUOTE_NOT_CLOSED'
| 'CSV_INCONSISTENT_RECORD_LENGTH'
| 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
| 'CSV_OPTION_COLUMNS_MISSING_NAME'

export class CsvError extends Error {
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/cjs/sync.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5889,9 +5889,7 @@ class Parser extends Transform {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/dist/esm/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export type CsvErrorCode =
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
| 'CSV_QUOTE_NOT_CLOSED'
| 'CSV_INCONSISTENT_RECORD_LENGTH'
| 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
| 'CSV_OPTION_COLUMNS_MISSING_NAME'

export class CsvError extends Error {
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5885,9 +5885,7 @@ class Parser extends Transform {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/esm/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5885,9 +5885,7 @@ class Parser extends Transform {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/iife/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5888,9 +5888,7 @@ var csv_parse = (function (exports) {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/iife/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5888,9 +5888,7 @@ var csv_parse_sync = (function (exports) {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/umd/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5891,9 +5891,7 @@
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/dist/umd/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5891,9 +5891,7 @@
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export type CsvErrorCode =
| 'CSV_NON_TRIMABLE_CHAR_AFTER_CLOSING_QUOTE'
| 'CSV_QUOTE_NOT_CLOSED'
| 'CSV_INCONSISTENT_RECORD_LENGTH'
| 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
| 'CSV_RECORD_INCONSISTENT_COLUMNS'
| 'CSV_OPTION_COLUMNS_MISSING_NAME'

export class CsvError extends Error {
Expand Down
4 changes: 1 addition & 3 deletions packages/csv-parse/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -889,9 +889,7 @@ class Parser extends Transform {
record: record,
})
:
// Todo: rename CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH to
// CSV_RECORD_INCONSISTENT_COLUMNS
new CsvError('CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH', [
new CsvError('CSV_RECORD_INCONSISTENT_COLUMNS', [
'Invalid Record Length:',
`columns length is ${columns.length},`, // rename columns
`got ${recordLength} on line ${this.info.lines}`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const records = parse('1,2\nin:va:lid\n3,4', {
relax_column_count: true,
raw: true,
on_record: ({raw, record}, {error}) => {
if(error && error.code === 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'){
if(error && error.code === 'CSV_RECORD_INCONSISTENT_COLUMNS'){
return raw.trim().split(':');
} else {
return record;
Expand Down
12 changes: 6 additions & 6 deletions packages/csv-parse/test/option.columns.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ describe 'Option `columns`', ->
""", columns: ["a", "b", "c", "d"], (err) ->
assert_error err,
message: 'Invalid Record Length: columns length is 4, got 3 on line 1'
code: 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_COLUMNS'
next()

it 'validate options column length on last line', (next) ->
Expand All @@ -190,7 +190,7 @@ describe 'Option `columns`', ->
""", columns: ["a", "b", "c", "d"], (err) ->
assert_error err,
message: 'Invalid Record Length: columns length is 4, got 3 on line 3'
code: 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_COLUMNS'
next()

it 'context column is null when cast force the context creation', (next) ->
Expand All @@ -201,15 +201,15 @@ describe 'Option `columns`', ->
, (err) ->
assert_error err,
message: 'Invalid Record Length: columns length is 1, got 2 on line 2'
code: 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_COLUMNS'
column: null
next()

it 'context column is null when columns number inferieur to record length, fix regression #259', (next) ->
parse "a\nb,\n", columns: true, (err) ->
assert_error err,
message: 'Invalid Record Length: columns length is 1, got 2 on line 2'
code: 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_COLUMNS'
column: null
next()

Expand Down Expand Up @@ -268,14 +268,14 @@ describe 'Option `columns`', ->
it 'last column value ignore when `null`', (next) ->
# Trigger a bug where error is try to stringify and parse an undefined
# value, conjointly triggered by a null column and a
# CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH error
# CSV_RECORD_INCONSISTENT_COLUMNS error
parse """
col_a,col_b,col_c
foo,bar
foo,bar,baz
"""
, columns: ['a', 'b', null], (err) ->
err.code.should.eql 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
err.code.should.eql 'CSV_RECORD_INCONSISTENT_COLUMNS'
next()

describe 'function', ->
Expand Down
2 changes: 1 addition & 1 deletion packages/csv-parse/test/option.relax_column_count.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe 'Option `relax_column_count`', ->
relax_column_count: true,
raw: true,
on_record: ({raw, record}, {error}) ->
if error?.code is 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
if error?.code is 'CSV_RECORD_INCONSISTENT_COLUMNS'
raw.trim().split ':'
else
record
Expand Down
4 changes: 2 additions & 2 deletions packages/csv-parse/test/option.skip_records_with_error.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ describe 'Option `skip_records_with_error`', ->
'''
parser.end()

it 'handle "CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH"', (next) ->
it 'handle "CSV_RECORD_INCONSISTENT_COLUMNS"', (next) ->
errors = 0
parser = parse skip_records_with_error: true, columns: ["a", "b", "c", "d"], (err, records) ->
records.should.eql [
Expand All @@ -97,7 +97,7 @@ describe 'Option `skip_records_with_error`', ->
parser.on 'skip', (err) ->
assert_error err,
message: 'Invalid Record Length: columns length is 4, got 3 on line 1'
code: 'CSV_RECORD_DONT_MATCH_COLUMNS_LENGTH'
code: 'CSV_RECORD_INCONSISTENT_COLUMNS'
record: ['1', '2', '3']
errors++
parser.write '''
Expand Down

0 comments on commit fb391c9

Please sign in to comment.