Escapable commas in CLI options?
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 45/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- typescript
- 領域
- cli
調査の方向性
packages/react-docgen-cli/src/commands/parse/command.ts にある --ignore の定義とパースフローから始め、リンク先の typings/index.d.ts の該当行にある Commander の引数パーサーの型定義と比較します。既存のカンマ分割を変更せずにエスケープされたカンマを有効にする方法を確認し、--ignore がカンマを含む値を受け付ける一方で、通常の値が現在の動作を維持することを検証します。
索引モデルが issue の本文から書いたものです。
説明
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
- 主要言語
- TypeScript
- スター
- 3.8k
- フォーク
- 316
- 平均マージ
- 3時間 28分
- マージ済み PR(30日)
- 6
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
reactjs/react-docgen のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
reactjs/react-docgen#1102 ·
-
Typescript Status オープン
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
reactjs/react-docgen#1005 · リアクション 4 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
reactjs/react-docgen#997 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
reactjs/react-docgen#994 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
reactjs/react-docgen#982 · コメント 2 件 ·
reactjs/react-docgen の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
copse-dev/agent-pane#2953 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
calcite-components needs triage refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Esri/calcite-design-system#15203 ·