daidodo/format-imports

Format MDX files?

Open

#32 创建于 2024年10月6日

在 GitHub 查看
 (0 评论) (0 反应) (0 负责人)TypeScript (4 fork)github user discovery
enhancementhelp wanted

仓库指标

Star
 (51 star)
PR 合并指标
 (PR 指标待抓取)

描述

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

--

贡献者指南