You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'Comma separated list of glob patterns which will ignore the paths that match. Can also be used multiple times.',
collect,
defaultIgnoreGlobs,
)
... 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. */exportfunctionsplitOnComma(str: string): string[]{if(typeofstr!=='string'){consterrorMessage='input must be a string'thrownewTypeError(errorMessage)}constDELIMETER=','constESCAPE_CHAR='\\'constESCAPED_DELIMETER=ESCAPE_CHAR+DELIMETERconsthasEscapedDelimeter=str.includes(ESCAPED_DELIMETER)// Negative Lookbehind: https://www.regular-expressions.info/lookaround.htmlconstresult=str.split(/,(?<!\\,)/)if(hasEscapedDelimeter){returnresult.map((subStr)=>subStr.replace(/\\,/gi,DELIMETER))}returnresult}
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.replaceAll could be used instead.
subStr.replaceAll(ESCAPED_DELIMETER, DELIMETER))
perform the replacement in fewer operations / general performance improvement
The text was updated successfully, but these errors were encountered:
The commander argument parser for the
--ignore
option:react-docgen/packages/react-docgen-cli/src/commands/parse/command.ts
Lines 26 to 39 in f5d644a
react-docgen/packages/react-docgen-cli/src/commands/parse/command.ts
Lines 62 to 67 in f5d644a
... 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:
I don't have experience with negative lookbehinds. I wrote the example to favor being excessively self-documenting. Refinements could include:
String.prototype.replaceAll
could be used instead.subStr.replaceAll(ESCAPED_DELIMETER, DELIMETER))
The text was updated successfully, but these errors were encountered: