Escapable commas in CLI options?
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- typescript
- Domain
- cli
Research direction
Start with the --ignore definitions and parsing flow in packages/react-docgen-cli/src/commands/parse/command.ts, then compare them with Commander’s argument-parser typings at the linked typings/index.d.ts lines. Determine how escaped commas should be enabled without changing existing comma splitting, and verify that --ignore accepts comma-containing values while ordinary values retain their current behavior.
Written by the indexing model from the issue text.
Description
The commander argument parser for the --ignore option:
https://github.com/reactjs/react-docgen/blob/f5d644a3041c227c4889059e787fcbaab57ec70e/packages/react-docgen-cli/src/commands/parse/command.ts#L26-L39
https://github.com/reactjs/react-docgen/blob/f5d644a3041c227c4889059e787fcbaab57ec70e/packages/react-docgen-cli/src/commands/parse/command.ts#L62-L67
... splits on a comma, which makes it impossible to use glob brace expansion for this option or commas in general for any option that also uses this argument parser.
Would supporting escapable commas be possible?
To avoid breaking changes you may need to make it opt-in (behind a new option --comma-escaping or similar.)
The problem seems common enough and has been solved different ways in different languages. Here is a rough first pass after a little (very little) research:
/**
* Split on commas (","), unless they are escaped with a backslash("\,").
*
* Escaped commas are replaced with individual commas.
*/
export function splitOnComma(str: string): string[] {
if (typeof str !== 'string') {
const errorMessage = 'input must be a string'
throw new TypeError(errorMessage)
}
const DELIMETER = ','
const ESCAPE_CHAR = '\\'
const ESCAPED_DELIMETER = ESCAPE_CHAR + DELIMETER
const hasEscapedDelimeter = str.includes(ESCAPED_DELIMETER)
// Negative Lookbehind: https://www.regular-expressions.info/lookaround.html
const result = str.split(/,(?<!\\,)/)
if (hasEscapedDelimeter) {
return result.map((subStr) => subStr.replace(/\\,/gi, DELIMETER))
}
return result
}
I don't have experience with negative lookbehinds. I wrote the example to favor being excessively self-documenting. Refinements could include:
- improved error message
- reducing the number of lines needed
- adding unit tests
- if the build tools are configured for ES2021+,
String.prototype.replaceAllcould be used instead.subStr.replaceAll(ESCAPED_DELIMETER, DELIMETER))
- perform the replacement in fewer operations / general performance improvement
- Dominant language
- TypeScript
- Stars
- 3.8k
- Forks
- 316
- Avg merge
- 3h 28m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from reactjs/react-docgen
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
reactjs/react-docgen#1102 ·
-
Typescript Status Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
reactjs/react-docgen#1005 · 4 reactions ·
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
reactjs/react-docgen#997 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 42/100
reactjs/react-docgen#994 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
reactjs/react-docgen#982 · 2 comments ·
All issues in reactjs/react-docgen
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dennys-bd/agent-hive#184 ·
-
Add: hunch Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
AbdelStark/awesome-typesafe#104 ·
-
ai-observability bug team/ai-observability
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
vicharanashala/fln#563 ·