dprint
TypeScript and JSONC code formatter.
Install
Install dprint
and the plugins you want to use as a dev dependency.
For example:
yarn add --dev dprint dprint-plugin-typescript dprint-plugin-jsonc
# or
npm install --save-dev dprint dprint-plugin-typescript dprint-plugin-jsonc
Usage
Create a dprint.config.js file in the repo. Here's an example (you don't need to copy this... use your own config):
const { TypeScriptPlugin } = require("dprint-plugin-typescript");
const { JsoncPlugin } = require("dprint-plugin-jsonc");
module.exports.config = {
projectType: "openSource",
lineWidth: 160,
plugins: [
new TypeScriptPlugin({
useBraces: "preferNone",
"tryStatement.nextControlFlowPosition": "sameLine"
}),
new JsoncPlugin({
indentWidth: 2
})
]
};
Add a format script to your package.json's "scripts" section (see npx dprint --help
for usage):
{
"name": "your-package-name",
"scripts": {
"format": "dprint \"**/*.{ts,tsx,json,js,jsx}\""
}
}
Format:
yarn format
# or
npm run format