daidodo / daidodo/format-imports

Format MDX files?

Open
#32 0 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
TypeScript
Stars
51
Forks
4
PR merge metrics
No merged PRs in 30d

Description

**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](https://mdxjs.com/) files (`.mdx` extension), [which can include `import` and `export` statements](https://mdxjs.com/docs/what-is-mdx/#esm)

Example file from [MDX homepage](https://mdxjs.com/):

`index.mdx`

```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.

```

This will probably require:

1. A custom parser (maybe with [`@mdx-js/mdx`](https://mdxjs.com/packages/mdx/#architecture)? 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**

--

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.