microsoft / microsoft/TypeScript

Regular Expression - improve on-hover notation for literal expressions

Aperta
#60,344 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔍 Search Terms

regex, regular expression, syntax highlighting

✅ Viability Checklist
⭐ Suggestion

I would like to be able to hover my mouse over a variable holding a regular expression and see the literal string or /expression/ that was used in its construction (if known).

📃 Motivating Example

This feature adds the ability to view the regular expression that went into a variable, meaning that you can abstract regular expressions away into separate files without losing the meaning behind what the regular expression represents. This is a quality of life improvement that does not solve the million problems that most regular expression examples look to solve, meaning that it won't parse or try to understand the context of the RegExp, but it will no longer disadvantage users who hoist their expressions rather than inline them.

💻 Use Cases
  1. What do you want to use this for?
  • For projects where regular expressions would be better served by being hoisted to a different file (like a shared module)
  1. What shortcomings exist with current approaches?
  • Current approaches require augmenting every regular expression with detailed comments, which is a lot of unnecessary boilerplate (which is more aligned with JSDoc rather than TypeScript) and can get messy when doing things like renaming capture groups and needing to update the comments accordingly.
  1. What workarounds are you using in the meantime?
  • I'll show you what I've done, which works well for string-literal based regular expressions, but requires converting ALL /forward slash/ regular expressions to be manually refactored to their string literal equivalents, which is very time consuming and shouldn't be necessary for the end user. Here's what I've developed to solve my own problem, but that still requires not using /notation/:
/**
 * A regular expression that remembers the string literals used in its creation.
 */
export interface TypedRegExp<S extends string, F extends string> extends RegExp {
    source: S;
    flags: F;
}

export const createTypedRegExpr = <T extends string, M extends string = ''>(
    stringExpr: T,
    flags?: M
) => new RegExp(stringExpr, flags) as TypedRegExp<T, M>;

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando gli esempi di RegExp alla base della richiesta e il comportamento attuale dell'hover descritto nell'issue. Definisci il completamento in modo che mostri la stringa letterale nota o /expression/ utilizzata per costruire un'espressione regolare, incluse le espressioni sollevate, senza modificare il JavaScript emesso né il comportamento a runtime.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
developer-experience, tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.