feat(readtext): add position-aware list parsing - #928
Merged
Conversation
Add toListWithPosition/readListWithPosition returning each surviving line's 1-origin line/column, so callers that reject invalid entries can report which line of the source file they came from — toList's plain string[] loses that mapping once blank/comment lines are filtered out. toList is reimplemented on top of the new parser to keep the filtering rules in one place.
Consumers that need to type an intermediate value as ListItem[] (e.g. a caller partitioning valid/invalid entries) could not name the type — list.ts re-exported the parsing functions but not their shared item type.
README only covered readList/readGrid; the new position-aware companion is a main public API addition and was missing from the usage section.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
toListWithPosition/readListWithPosition, position-aware companions totoList/readListthat tag each surviving line with its 1-origin line/column in the source texttoListon top oftoListWithPositionso the blank-line/comment filtering rules stay in one placeListItemtype from the./listsubpath so consumers can name it explicitlyMotivation
toList/readListstrip blank lines and#comments before returning a plainstring[], so a caller that needs to report "line 3 of the source file was invalid" back to a user cannot reconstruct the original line number from the filtered array — the index has already shifted.nitpicker's--inventoryCLI flag needs exactly this (nitpicker/nitpicker#99: warn-and-skip invalid URL lines with their line:column instead of hard-erroring on the first bad line).Test plan
yarn test— 1673 tests pass (118 files)yarn lint— cleanyarn build— 28 projects build successfullyto-list-with-position.spec.tscovers: line numbering across blank/comment lines, column position with leading whitespace (spaces and tabs), whitespace-only lines treated as blank, CRLF line endings, and the empty-result case🤖 Generated with Claude Code