1 # Prettier formatter for coc.nvim
3 Coc extension to format your JavaScript / TypeScript / CSS / JSON using [Prettier](https://github.com/prettier/prettier).
5 A fork of [prettier-vscode](https://github.com/prettier/prettier-vscode)
12 :CocInstall coc-prettier
17 ### Setup `Prettier` command in your `init.vim` or `.vimrc`
20 command! -nargs=0 Prettier :CocCommand prettier.formatFile
23 Then you can use `:Prettier` to format current buffer.
25 ### Remap keys for range format in your `init.vim` or `.vimrc`
28 vmap <leader>f <Plug>(coc-format-selected)
29 nmap <leader>f <Plug>(coc-format-selected)
32 Then your can `<leader>f` for range format.
34 Prettier range format only support languageId including: `javascript`,
35 `javascriptreact`, `typescript`, `typescriptreact`, `json` and `graphql`.
37 ### Update your `coc-settings.json` for format on save.
39 Open settings file with:
46 "coc.preferences.formatOnSaveFiletypes": ["css", "markdown"],
49 to setup the languages which you want to format on save.
51 **Note:** prettier extension have lower priority, if the document have other
52 registered document format provider, prettier would not work.
54 To check the format is done by prettier, check out the output message after
55 format, which should contains `Formatted by prettier`.
57 To make prettier do the format, use command `:CocCommand prettier.formatFile`
59 To save without formatting, use `:noa w`
63 ### Prettier's Settings
65 Settings will be read from (listed by priority):
67 1. [Prettier configuration file](https://prettier.io/docs/en/configuration.html)
70 Or if no prettier configuration file exist
73 1. Coc prettier's settings (described below with their default)
75 #### prettier.printWidth (default: 80)
77 Fit code within this line limit
79 #### prettier.tabWidth (default: 2)
81 Number of spaces it should use per tab
83 #### prettier.singleQuote (default: false)
85 If true, will use single instead of double quotes
87 #### prettier.trailingComma (default: 'none')
89 Controls the printing of trailing commas wherever possible. Valid options:
91 - "none" - No trailing commas
92 - "es5" - Trailing commas where valid in ES5 (objects, arrays, etc)
93 - "all" - Trailing commas wherever possible (function arguments)
95 #### prettier.bracketSpacing (default: true)
97 Controls the printing of spaces inside object literals
99 #### prettier.jsxBracketSameLine (default: false)
101 If true, puts the `>` of a multi-line jsx element at the end of the last line instead of being alone on the next line
103 #### prettier.parser (default: 'babylon') - JavaScript only
105 Which parser to use. Valid options are 'flow' and 'babylon'.
107 #### prettier.semi (default: true)
109 Whether to add a semicolon at the end of every line (semi: true),
110 or only at the beginning of lines that may introduce ASI failures (semi: false)
112 #### prettier.useTabs (default: false)
114 If true, indent lines with tabs
116 #### prettier.proseWrap (default: 'preserve')
118 (Markdown) wrap prose over multiple lines.
120 #### prettier.arrowParens (default: 'avoid')
122 Include parentheses around a sole arrow function parameter
124 ### Coc specific settings
126 These settings are specific to Coc and need to be set in the Coc settings file. See the [documentation](https://github.com/neoclide/coc.nvim/wiki/Using-the-configuration-file) for how to do that.
128 #### prettier.formatterPriority (default: 1) - priority of formatter
130 Change it to `-1` if you don't want prettier to have higher priority than
131 formatter provided by other language server.
133 #### prettier.eslintIntegration (default: false) - JavaScript and TypeScript only
135 Use _[prettier-eslint](https://github.com/prettier/prettier-eslint)_ instead of _prettier_.
136 Other settings will only be fallbacks in case they could not be inferred from ESLint rules.
138 #### prettier.tslintIntegration (default: false) - JavaScript and TypeScript only
140 Use _[prettier-tslint](https://github.com/azz/prettier-tslint)_ instead of _prettier_.
141 Other settings will only be fallbacks in case they could not be inferred from TSLint rules.
143 #### prettier.stylelintIntegration (default: false) - CSS, SCSS and LESS only
145 Use _[prettier-stylelint](https://github.com/hugomrdias/prettier-stylelint)_ instead of _prettier_.
146 Other settings will only be fallbacks in case they could not be inferred from stylelint rules.
148 #### prettier.requireConfig (default: false)
150 Require a 'prettierconfig' to format
152 #### prettier.ignorePath (default: .prettierignore)
154 Supply the path to an ignore file such as `.gitignore` or `.prettierignore`.
155 Files which match will not be formatted. Set to `null` to not read ignore files. Restart required.
157 #### prettier.disableLanguages (default: ["vue"])
159 A list of languages IDs to disable this extension on. Restart required.
160 _Note: Disabling a language enabled in a parent folder will prevent formatting instead of letting any other formatter to run_
162 #### prettier.statusItemText (default: "Prettier")
164 Text of status item indicating current buffer can be formatted by prettier.
166 #### prettier.onlyUseLocalVersion (default: false)
168 Only use the version of prettier installed by the client, ignoring the version bundled with coc-prettier
170 #### prettier.disableSuccessMessage (default: false)
172 Disable the 'Formatted by prettier' message which is echoed every time a file is successfully formatted
174 ## Prettier resolution
176 This extension will use prettier from your project's local dependencies. Should prettier not be installed locally with your project's dependencies, a copy will be bundled with the extension.
178 ### ESLint and TSLint Integration
180 `prettier-eslint` and `prettier-tslint` are included with the installation of this extension. There is no need for a separate local or global install of either for functionality.
182 `eslint`, `tslint`, and all peer dependencies required by your specific configuration must be installed locally. Global installations will not be recognized.
186 Feel free to open issues or PRs!