Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a CLI based on unified-args #2378

Closed
4 tasks done
remcohaszing opened this issue Oct 21, 2023 · 7 comments
Closed
4 tasks done

Provide a CLI based on unified-args #2378

remcohaszing opened this issue Oct 21, 2023 · 7 comments
Labels
🤷 no/invalid This cannot be acted upon

Comments

@remcohaszing
Copy link
Member

Initial checklist

Problem

The unified ecosystem has some CLIs based on unified-args that can be used for linting and formatting. Since MDX is based on remark, remark-cli can support MDX, but it’s not obvious. By default remark-cli doesn’t contain remark-mdx, not does it check .mdx files by default.

It would be nice if there is a simple blessed way to lint MDX files.

Solution

Create a new package remark-mdx-cli. This registers the remark-mdx command.

#!/usr/bin/env node

/**
 * @typedef Pack
 * @property {string} name
 * @property {string} version
 * @property {string} description
 */

import fs from 'node:fs/promises'
import {remark} from 'remark'
import remarkMdx from 'remark-mdx'
import {args} from 'unified-args'

/** @type {Pack} */
const cli = JSON.parse(
  String(await fs.readFile(new URL('package.json', import.meta.url)))
)

args({
  description: cli.description,
  extensions: ['mdx'],
  ignoreName: '.remarkmdxignore',
  name: 'remark-mdx',
  packageField: 'remarkmdxConfig',
  pluginPrefix: 'remark',
  processor: remark.use(remarkMdx),
  rcName: '.remarkmdxrc',
  version: cli.name + ': ' + cli.version
})

This will also be accompanied by a language server (remark-mdx-language-server) and VSCode plugin (unifiedjs.vscode-remark-mdx) based on unified-language-server.

Alternatives

There are plenty of variations possible on the names of various parameters. I.e. should the package name be scoped? Should the command be different? Should it use .remarkignore instead of .remarkmdxignore?

@remcohaszing remcohaszing added 💬 type/discussion This is a request for comments 🤞 phase/open Post is being triaged manually labels Oct 21, 2023
@wooorm
Copy link
Member

wooorm commented Oct 21, 2023

simple way is remark -e mdx -u mdx? Not sure if another CLI that needs to be documented is an improvement, over adding docs somewhere on how to do this?

@wooorm
Copy link
Member

wooorm commented Oct 21, 2023

By extension, should we have remark-gfm-cli? What if you want to combine both?

@wooorm
Copy link
Member

wooorm commented Oct 21, 2023

And, wouldn’t an MDX CLI be more about compiling/evaluating code?

@remcohaszing
Copy link
Member Author

remcohaszing commented Oct 21, 2023

IMO configuration is usually preferred over CLI arguments.

  • Configuration gives the user a standard place to define it.
  • Configuration can be shared between integrations.

This goes for other tooling as well. I.e. it’s perfectly possible to run git, Prettier, or ESLint using CLI arguments and no configuration, but it’s very inconvenient and you don’t get editor integrations. IMO this falls in the same category.

Perhaps we could also investigate an MDX CLI for compiling code, but that’s a different issue and I don’t see a need for that right now.

@remcohaszing
Copy link
Member Author

The difference between GFM and MDX is that typically it’s fine to treat other .md files as GFM, but it’s not ok to treat .md files as MDX, or .mdx files as regular markdown.

@wooorm
Copy link
Member

wooorm commented Oct 21, 2023

  • you can already use remark-mdx in configuration
  • markdown and MDX are, except for .mdx and remark-mdx, very similar. This project uses shared configuration for both. Duplicating all of the config files seems superfluous. Like having an eslintjsxrc, eslintjsrc, eslinttsrc.
  • integrations including .mdx, and then applying remark-mdx, but otherwise loading all the remark ignore files / config files seems better to me

@wooorm
Copy link
Member

wooorm commented Oct 2, 2024

Closing this as an issue: we can use discussions for discussions. Then we can use issues for actionable things.
It remains vague to me what this is about. There could be many CLIs for MDX.
If this is about linting, perhaps there could be a new guide, discussing how to lint and format MDX?
One such is a type checking CLI, which is discussed: mdx-js/mdx-analyzer#292.

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
@wooorm wooorm added 🤷 no/invalid This cannot be acted upon and removed 💬 type/discussion This is a request for comments 🤞 phase/open Post is being triaged manually labels Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤷 no/invalid This cannot be acted upon
Development

No branches or pull requests

2 participants