1 | # dprint
|
2 |
|
3 | [![npm version](https://badge.fury.io/js/dprint.svg)](https://badge.fury.io/js/dprint)
|
4 | [![Build Status](https://travis-ci.org/dsherret/dprint.svg?branch=master)](https://travis-ci.org/dsherret/dprint)
|
5 |
|
6 | TypeScript and JSONC code formatter.
|
7 |
|
8 | ## Install
|
9 |
|
10 | Install `dprint` and the plugins you want to use as a dev dependency.
|
11 |
|
12 | For example:
|
13 |
|
14 | ```
|
15 | yarn add --dev dprint dprint-plugin-typescript dprint-plugin-jsonc
|
16 | # or
|
17 | npm install --save-dev dprint dprint-plugin-typescript dprint-plugin-jsonc
|
18 | ```
|
19 |
|
20 | ## Usage
|
21 |
|
22 | Create a *dprint.config.js* file in the repo. Here's an example (you don't need to copy this... use your own config):
|
23 |
|
24 | ```js
|
25 | // @ts-check
|
26 | const { TypeScriptPlugin } = require("dprint-plugin-typescript");
|
27 | const { JsoncPlugin } = require("dprint-plugin-jsonc");
|
28 |
|
29 | /** @type { import("dprint").Configuration } */
|
30 | module.exports.config = {
|
31 | projectType: "openSource",
|
32 | lineWidth: 160,
|
33 | plugins: [
|
34 | new TypeScriptPlugin({
|
35 | useBraces: "preferNone",
|
36 | "tryStatement.nextControlFlowPosition": "sameLine"
|
37 | }),
|
38 | new JsoncPlugin({
|
39 | indentWidth: 2
|
40 | })
|
41 | ]
|
42 | };
|
43 | ```
|
44 |
|
45 | Add a format script to your *package.json*'s "scripts" section (see `npx dprint --help` for usage):
|
46 |
|
47 | ```json
|
48 | {
|
49 | "name": "your-package-name",
|
50 | "scripts": {
|
51 | "format": "dprint \"**/*{.ts,.tsx,.json,.js}\""
|
52 | }
|
53 | }
|
54 | ```
|
55 |
|
56 | Format:
|
57 |
|
58 | ```
|
59 | yarn format
|
60 | # or
|
61 | npm run format
|
62 | ```
|