Repository navigation
Conversation
|
Hi @wdavidw, could you take a look at this when you have a moment? Happy to fix up anything that needs changing. Thanks! |
|
Hi @smoltafet, I have been receiving a flood of PR recently, alimented by AI, and I don't have the time to review them. I quickly looked at it recently. If I understand your proposition correctly, counting lines, even those containing comments, is on purpose. The idea is that if someone open a document and found the CVS records start in line 200, then parsing shall start there, whichever comes before. Another argument is that the PR introduces a breaking change. What could be done is the introduction of a new option, something like |
|
@wdavidw thanks, that makes sense. I reworked it so from_line counts physical lines by default like before, and the comment skipping is now opt-in through a new from_line_skip_comments option. Tests pass locally (full csv-parse suite, 637 passing). Happy to rename the option if you prefer something else. |
|
I am currently thinking that
what do you think ? |
|
@wdavidw good call, I went with the object form. |
Fixes #422.
Updated after @wdavidw's feedback, twice over:
from_linekeeps counting physical lines by default (no breaking change), and the comment-skipping behavior now lives onfrom_lineitself instead of a separate option.from_linetakes two forms:An integer is normalized to an object with the integer as
positionandskip_commentsset to false; in an object,skip_commentsis optional and defaults to false.Implementation notes:
from_lineactivation check subtracts the number of full comment lines seen so far only whenskip_commentsis true. That count is taken when a comment starts (newstate.fullCommentLines), not at the record delimiter: while emission is disabled byfrom_line,__onFieldshort-circuits and the record/field state at the delimiter no longer reflects the line's content, which would misclassify lines with trailing comments as comment lines.state.lineHasContent). A trailing comment after content does not make the line a comment line.info.comment_linesand error line numbers still use physical lines, unchanged.positionmust be a positive integer,skip_commentsa boolean); the normalized option is typed inoptions.d.tsand the API types test covers both forms.from_linetransition (or theskip_empty_linesskip) fired on a line ending with a trailing comment, the earlycontinueskipped thestate.commenting = falsereset, so the whole next line was silently swallowed as a comment. On master,parse('a,b # comment\n1,2\n3,4', { comment: '#', from_line: 2 })returns only['3','4']and reportscomment_lines: 1; it now returns both records andcomment_lines: 0. Both branches now resetcommentingbefore continuing.to_lineis intentionally left counting physical lines, as in the issue's request; happy to align it too if you prefer.Tests: eight new tests in
packages/csv-parse/test/option.from_line.jscovering the object form (leading comment lines using the issue's example, comments between records, boundary positioning, trailing comments,columns: trueafter comments, validation of the object form,skip_commentsunset, and a default-behavior test showing comment lines are counted for a plain integer). Full csv-parse suite: 637 passing, 2 pending (pristine master: 629 passing, 2 pending);tsc --noEmitand eslint are clean. Default behavior was also compared against pristine master on the distinguishing cases and is unchanged.