Prettier as a dprint Wasm plugin.
The plugin has Prettier 3.10.1, with the versions of the packages that Prettier 3.10.1 is released with.
- Install dprint
- Run
dprint initto create the config file. - Run
dprint add prettierto add this plugin.
See Prettier's configuration here. Specify using the "API Override" column.
Add the file extension to the start of the configuration option. For example:
{
// ...etc...
"prettier": {
"singleQuote": true,
// use double quotes in js files
"js.singleQuote": false,
// use double quotes in ts files
"ts.singleQuote": false,
},
}Besides the languages that Prettier has built in, the plugin includes these Prettier plugins, at the versions in plugins/package.json:
- prettier-plugin-svelte, which formats
.sveltefiles. - prettier-plugin-jsdoc, which formats JSDoc comments when it is turned on with
"plugin.jsDoc": true. Its options, such asjsdocSpaces, are given like Prettier's.
The source is in these folders:
prettier- Prettier 3.10.1's source with type annotations in JSDoc comments that make the compiled code fast. They are comments only, so the code is Prettier's as it is.package.jsonlists the packages that the source imports, at the versions that Prettier 3.10.1 has.plugins- the Prettier plugins that the plugin includes, with the packages that they import (package.json), which are compiled fromnode_modules.nts- compiles TypeScript and JavaScript to C#, with the declarations thatsrcis checked with (lib.d.ts).deno task buildbundles it again first when nts is checked out beside this repository (../nts), andCOMMITsays what it was bundled from.src- the entry point that dprint calls (main.ts), Prettier's own plugins (builtin-plugins.ts) and those that it formats with (plugins.ts), with the libraries that are compiled along with Prettier (vendor,shims), what Prettier's*.evaluate.jsfiles give (generated, made bynode scripts/generate.mjs) and Prettier's TypeScript parser as npm has it (prettier-plugins).wasm- the C# project that compiles what nts makes ofsrc/main.tsto the Wasm module, with the functions that dprint calls. Flow's parser is a Wasm module in the flow-parser package, which wasm2c makes C of to compile into the plugin (wasm/flow).
To build, install Deno, Node.js, the .NET 11 SDK, the WASI SDK, Binaryen and WABT. Then:
deno task setup
WASI_SDK_PATH=<wasi-sdk folder> BINARYEN=<binaryen folder>/bin WABT=<wabt folder> deno task build
deno task testThis creates target/plugin.wasm. deno task test runs the specs in tests/specs, checks what dprint sees of the plugin (tests/dprint_test.ts), and formats the samples in tests/samples with every value of every option that Prettier has, which must come out as Prettier from npm gives them (tests/options_test.ts). deno task test:prettier checks it against Prettier's own format tests, each also with CRLF and CR line endings and formatted a second time, and deno task test:plugins (after that) against the tests of the Prettier plugins and Prettier's tests of JavaScript with prettier-plugin-jsdoc. docs/upgrading.md says how to upgrade Prettier.
To check that the plugin formats like Prettier from npm, deno task test:repos clones codebases into target/repos and formats their files with both. It takes a while, so it is not part of deno task test. Set REPOS to a comma separated list of the names in tests/repos_test.ts to only test those, and see target/repos/diffs for the files that differ.
{ // ...etc... "prettier": { "trailingComma": "all", "singleQuote": true, "proseWrap": "always", }, }