daidodo/format-imports

Format MDX files?

Open

#32 aperta il 6 ott 2024

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)TypeScript (4 fork)github user discovery
enhancementhelp wanted

Metriche repository

Star
 (51 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

Is your feature request related to a problem? Please describe.

MDX files are not currently sorted and unused imports and exports are not removed

Describe the solution you'd like

Similar to Vue support, also support MDX files (.mdx extension), which can include import and export statements

Example file from MDX homepage:

index.mdx

import {Chart} from './snowfall.js'
export const year = 2023

# Last year’s snowfall

In {year}, the snowfall was above average.
It was followed by a warm spring which caused
flood conditions in many of the nearby rivers.

<Chart year={year} color="#fcb32c" />

This will probably require:

  1. A custom parser (maybe with @mdx-js/mdx? or maybe something lower level from the unified ecosystem)
  2. Maybe also a custom formatter? Although the imports / exports should be "just JavaScript"...

Describe alternatives you've considered

Avoiding parsing: Match and format only import and export statements at the top of the document (eg. using regular expressions)

But this would be brittle and would fail in many cases.

Additional context

--

Guida contributor