Skip to content

Plugins: allow overriding internal plugins, e.g., printer for JS or CSS #5919

@jsnajdr

Description

@jsnajdr

Steps to reproduce:
Create a plugin that exports a custom printer for JS and/or CSS:

module.exports = {
  printers: {
    estree: myJSPrinter,
    postcss: myCSSPrinter
  }
}

Then run Prettier with this plugin on a JS or CSS file.

Expected behavior:
The plugin's printer is the one that's used for formatting.

Actual behavior:
The default printer is used, no matter what the plugin offers. That's because the array of plugins has the internal plugins first, the external plugins last, and then the printer to use is the first one that matches the AST format.

Why would anyone need it?
The WordPress community uses a formatting style with a lot of spaces inside parens:

function Label( { date } ) {
  const [ translate ] = useTranslate();
  return ( <span>{ translate( 'Updated %s', moment( date ).fromNow() ) }</span> );
}

We've been maintaining a fork that adds a --paren-spacing option for the last two years. Now we would like to turn it into a plugin and publish it to NPM as prettier-plugin-wordpress.

Then users could install the official prettier package and configure it to use the wordpress plugin. All editor integrations that search for node_modules/prettier/index.js and other packages that have prettier as peer dependency would use the right version.

Thoughts? Would the team be interested in a PR that swaps the order of the plugin array or searches in it using findLast?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:apiIssues with Prettier's Application Programming Interfacearea:plugin api

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions