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`
61 ### Prettier's Settings
63 Settings will be read from (listed by priority):
65 1. [Prettier configuration file](https://prettier.io/docs/en/configuration.html)
68 Or if no prettier configuration file exist
71 1. Coc prettier's settings (described below with their default)
73 #### prettier.printWidth (default: 80)
75 Fit code within this line limit
77 #### prettier.tabWidth (default: 2)
79 Number of spaces it should use per tab
81 #### prettier.singleQuote (default: false)
83 If true, will use single instead of double quotes
85 #### prettier.trailingComma (default: 'none')
87 Controls the printing of trailing commas wherever possible. Valid options:
89 - "none" - No trailing commas
90 - "es5" - Trailing commas where valid in ES5 (objects, arrays, etc)
91 - "all" - Trailing commas wherever possible (function arguments)
93 #### prettier.bracketSpacing (default: true)
95 Controls the printing of spaces inside object literals
97 #### prettier.jsxBracketSameLine (default: false)
99 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
101 #### prettier.parser (default: 'babylon') - JavaScript only
103 Which parser to use. Valid options are 'flow' and 'babylon'.
105 #### prettier.semi (default: true)
107 Whether to add a semicolon at the end of every line (semi: true),
108 or only at the beginning of lines that may introduce ASI failures (semi: false)
110 #### prettier.useTabs (default: false)
112 If true, indent lines with tabs
114 #### prettier.proseWrap (default: 'preserve')
116 (Markdown) wrap prose over multiple lines.
118 #### prettier.arrowParens (default: 'avoid')
120 Include parentheses around a sole arrow function parameter
122 ### Coc specific settings
124 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-configuration-file) for how to do that.
126 #### prettier.formatterPriority (default: 1) - priority of fomatter
128 Change it to `-1` if you don't want prettier to have higher priority than
129 formatter provided by other language server.
131 #### prettier.eslintIntegration (default: false) - JavaScript and TypeScript only
133 Use _[prettier-eslint](https://github.com/prettier/prettier-eslint)_ instead of _prettier_.
134 Other settings will only be fallbacks in case they could not be inferred from ESLint rules.
136 #### prettier.tslintIntegration (default: false) - JavaScript and TypeScript only
138 Use _[prettier-tslint](https://github.com/azz/prettier-tslint)_ instead of _prettier_.
139 Other settings will only be fallbacks in case they could not be inferred from TSLint rules.
141 #### prettier.stylelintIntegration (default: false) - CSS, SCSS and LESS only
143 Use _[prettier-stylelint](https://github.com/hugomrdias/prettier-stylelint)_ instead of _prettier_.
144 Other settings will only be fallbacks in case they could not be inferred from stylelint rules.
146 #### prettier.requireConfig (default: false)
148 Require a 'prettierconfig' to format
150 #### prettier.ignorePath (default: .prettierignore)
152 Supply the path to an ignore file such as `.gitignore` or `.prettierignore`.
153 Files which match will not be formatted. Set to `null` to not read ignore files. Restart required.
155 #### prettier.disableLanguages (default: ["vue"])
157 A list of languages IDs to disable this extension on. Restart required.
158 _Note: Disabling a language enabled in a parent folder will prevent formatting instead of letting any other formatter to run_
160 #### prettier.statusItemText (default: "Prettier")
162 Text of status item indicating current buffer can't be formatted by prettier.
164 ## Prettier resolution
166 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.
168 ### ESLint and TSLint Integration
170 `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.
172 `eslint`, `tslint`, and all peer dependencies required by your specific configuration must be installed locally. Global installations will not be recognized.
176 Feel free to open issues or PRs!