Skip to content

Conversation

@bitbloxhub
Copy link
Contributor

  • <- Keep this line and put an x between the brackts.

Description

Some dprint plugins can use other dprint plugins to format nested code. For example, you can use markup_fmt with Malva to format CSS inside of HTML, Vue, Svelte, Astro, etc., @dprint/formatter recently added an API for handling this, see https://github.com/dprint/js-formatter/tree/7f90524?tab=readme-ov-file#use.

Example config for this:

{
  files: ["**/*.svelte"],
  languageOptions: {
    parser: format.parserPlain,
  },
  plugins: {
    format,
  },
  rules: {
    "format/dprint": ["error", {
      plugins: [
        {
          plugin: "node_modules/dprint-plugin-malva/plugin.wasm",
          options: {},
        },
        {
          plugin: "node_modules/dprint-plugin-markup/plugin.wasm",
          options: {
            scriptIndent: true,
            styleIndent: true,
          },
        },
      ],
      useTabs: false,
      indentWidth: 2,
    }],
  },
}

Linked Issues

Additional context

Not sure about the API design, also we don't cache the context for multi-formatter setups.

@bitbloxhub bitbloxhub force-pushed the dprint-multiple-plugins branch from 55ac8d2 to 11c587b Compare January 6, 2026 21:53
@bitbloxhub bitbloxhub marked this pull request as ready for review January 9, 2026 19:15
@bitbloxhub
Copy link
Contributor Author

@antfu Do you have any feedback on the API design or ideas about caching (which is what i am currently stuck on)?

@antfu
Copy link
Owner

antfu commented Jan 13, 2026

We can use ohash to create a hash from the plugin+options and store the context in a map.

@antfu antfu merged commit 3eaeba4 into antfu:main Jan 13, 2026
5 checks passed
@bitbloxhub bitbloxhub mentioned this pull request Jan 13, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants