Fix docs code style (#7937)
This commit is contained in:
1 parent
54766f11a2
commit
096c28f080
4 files changed
+38
-34
No files matched your search
+3
-3
@@ -52,14 +52,14 @@ prettier --check "src/**/*.js"
|
||||
|
||||
Console output if all files are formatted:
|
||||
|
||||
```
|
||||
```console
|
||||
Checking formatting...
|
||||
All matched files use Prettier code style!
|
||||
```
|
||||
|
||||
Console output if some of the files require re-formatting:
|
||||
|
||||
```
|
||||
```console
|
||||
Checking formatting...
|
||||
src/fileA.js
|
||||
src/fileB.js
|
||||
@@ -192,7 +192,7 @@ _abc.css_
|
||||
|
||||
_shell_
|
||||
|
||||
```bash
|
||||
```console
|
||||
$ cat abc.css | prettier --stdin-filepath abc.css
|
||||
.name {
|
||||
display: none;
|
||||
|
||||
+14
-14
@@ -80,8 +80,8 @@ Valid options:
|
||||
- `"preserve"` - Respect the input use of quotes in object properties.
|
||||
|
||||
| Default | CLI Override | API Override |
|
||||
| ------------- | -------------------------------------------------------------------- | -------------------------------------------------------------------- |
|
||||
| `"as-needed"` | <code>--quote-props <as-needed|consistent|preserve></code> | <code>quoteProps: "<as-needed|consistent|preserve>"</code> |
|
||||
| ------------- | ----------------------------------------------- | ----------------------------------------------- |
|
||||
| `"as-needed"` | `--quote-props <as-needed|consistent|preserve>` | `quoteProps: "<as-needed|consistent|preserve>"` |
|
||||
|
||||
## JSX Quotes
|
||||
|
||||
@@ -104,8 +104,8 @@ Valid options:
|
||||
- `"all"` - Trailing commas wherever possible (including function arguments). This requires node 8 or a [transform](https://babeljs.io/docs/plugins/syntax-trailing-function-commas/).
|
||||
|
||||
| Default | CLI Override | API Override |
|
||||
| ------- | ------------------------------------------------------ | ------------------------------------------------------ |
|
||||
| `"es5"` | <code>--trailing-comma <es5|none|all></code> | <code>trailingComma: "<es5|none|all>"</code> |
|
||||
| ------- | --------------------------------- | --------------------------------- |
|
||||
| `"es5"` | `--trailing-comma <es5|none|all>` | `trailingComma: "<es5|none|all>"` |
|
||||
|
||||
## Bracket Spacing
|
||||
|
||||
@@ -129,7 +129,7 @@ Valid options:
|
||||
- `true` - Example:
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```
|
||||
```jsx
|
||||
<button
|
||||
className="prettier-class"
|
||||
id="prettier-id"
|
||||
@@ -141,7 +141,7 @@ Valid options:
|
||||
- `false` - Example:
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```
|
||||
```jsx
|
||||
<button
|
||||
className="prettier-class"
|
||||
id="prettier-id"
|
||||
@@ -167,8 +167,8 @@ Valid options:
|
||||
- `"avoid"` - Omit parens when possible. Example: `x => x`
|
||||
|
||||
| Default | CLI Override | API Override |
|
||||
| ---------- | ----------------------------------------------- | ----------------------------------------------- |
|
||||
| `"always"` | <code>--arrow-parens <always|avoid></code> | <code>arrowParens: "<always|avoid>"</code> |
|
||||
| ---------- | ------------------------------- | ------------------------------- |
|
||||
| `"always"` | `--arrow-parens <always|avoid>` | `arrowParens: "<always|avoid>"` |
|
||||
|
||||
At first glance, avoiding parentheses may look like a better choice because of less visual noise.
|
||||
However, when Prettier removes parentheses, it becomes harder to add type annotations, extra arguments or default values as well as making other changes.
|
||||
@@ -293,8 +293,8 @@ Valid options:
|
||||
- `"preserve"` - Wrap prose as-is. _First available in v1.9.0_
|
||||
|
||||
| Default | CLI Override | API Override |
|
||||
| ------------ | ----------------------------------------------------------- | ----------------------------------------------------------- |
|
||||
| `"preserve"` | <code>--prose-wrap <always|never|preserve></code> | <code>proseWrap: "<always|never|preserve>"</code> |
|
||||
| ------------ | -------------------------------------- | -------------------------------------- |
|
||||
| `"preserve"` | `--prose-wrap <always|never|preserve>` | `proseWrap: "<always|never|preserve>"` |
|
||||
|
||||
## HTML Whitespace Sensitivity
|
||||
|
||||
@@ -311,8 +311,8 @@ Valid options:
|
||||
- `"ignore"` - Whitespaces are considered insensitive.
|
||||
|
||||
| Default | CLI Override | API Override |
|
||||
| ------- | ------------------------------------------------------------------------ | ----------------------------------------------------------------------- |
|
||||
| `"css"` | <code>--html-whitespace-sensitivity <css|strict|ignore></code> | <code>htmlWhitespaceSensitivity: "<css|strict|ignore>"</code> |
|
||||
| ------- | --------------------------------------------------- | -------------------------------------------------- |
|
||||
| `"css"` | `--html-whitespace-sensitivity <css|strict|ignore>` | `htmlWhitespaceSensitivity: "<css|strict|ignore>"` |
|
||||
|
||||
## Vue files script and style tags indentation
|
||||
|
||||
@@ -362,5 +362,5 @@ Valid options:
|
||||
(mixed values within one file are normalised by looking at what's used after the first line)
|
||||
|
||||
| Default | CLI Override | API Override |
|
||||
| ------- | ----------------------------------------------------------- | ---------------------------------------------------------- |
|
||||
| `"lf"` | <code>--end-of-line <lf|crlf|cr|auto></code> | <code>endOfLine: "<lf|crlf|cr|auto>"</code> |
|
||||
| ------- | --------------------------------- | -------------------------------- |
|
||||
| `"lf"` | `--end-of-line <lf|crlf|cr|auto>` | `endOfLine: "<lf|crlf|cr|auto>"` |
|
||||
+17
-15
@@ -13,7 +13,7 @@ See the [vim-prettier](https://github.com/prettier/vim-prettier) readme for inst
|
||||
|
||||
The best way to install Neoformat is with your favorite plugin manager for Vim, such as [vim-plug](https://github.com/junegunn/vim-plug):
|
||||
|
||||
```
|
||||
```vim
|
||||
Plug 'sbdchd/neoformat'
|
||||
```
|
||||
|
||||
@@ -21,7 +21,7 @@ Run `:Neoformat` or `:Neoformat prettier` in a supported file to run Prettier.
|
||||
|
||||
To have Neoformat run Prettier on save:
|
||||
|
||||
```
|
||||
```vim
|
||||
autocmd BufWritePre *.js Neoformat
|
||||
```
|
||||
|
||||
@@ -32,7 +32,7 @@ You can also make Vim format your code more frequently, by setting an `autocmd`
|
||||
|
||||
For example, you can format on both of the above events together with `BufWritePre` like this:
|
||||
|
||||
```
|
||||
```vim
|
||||
autocmd BufWritePre,TextChanged,InsertLeave *.js Neoformat
|
||||
```
|
||||
|
||||
@@ -40,7 +40,7 @@ See `:help autocmd-events` in Vim for details.
|
||||
|
||||
It's recommended to use a [config file](configuration.md), but you can also add options in your `.vimrc`:
|
||||
|
||||
```
|
||||
```vim
|
||||
autocmd FileType javascript setlocal formatprg=prettier\ --single-quote\ --trailing-comma\ es5
|
||||
" Use formatprg when available
|
||||
let g:neoformat_try_formatprg = 1
|
||||
@@ -54,7 +54,7 @@ ALE requires either Vim 8 or Neovim as ALE makes use of the asynchronous abiliti
|
||||
|
||||
The best way to install ALE is with your favorite plugin manager for Vim, such as [vim-plug](https://github.com/junegunn/vim-plug):
|
||||
|
||||
```
|
||||
```vim
|
||||
Plug 'dense-analysis/ale'
|
||||
```
|
||||
|
||||
@@ -64,7 +64,7 @@ ALE will try to use Prettier installed locally before looking for a global insta
|
||||
|
||||
Enable the Prettier fixer for the languages you use:
|
||||
|
||||
```
|
||||
```vim
|
||||
let g:ale_fixers = {
|
||||
\ 'javascript': ['prettier'],
|
||||
\ 'css': ['prettier'],
|
||||
@@ -73,7 +73,7 @@ let g:ale_fixers = {
|
||||
|
||||
ALE supports both _linters_ and _fixers_. If you don't specify which _linters_ to run, **all available tools for all supported languages will be run**, and you might get a correctly formatted file with a bunch of lint errors. To disable this behavior you can tell ALE to run only linters you've explicitly configured (more info in the [FAQ](https://github.com/dense-analysis/ale/blob/ed8104b6ab10f63c78e49b60d2468ae2656250e9/README.md#faq-disable-linters)):
|
||||
|
||||
```
|
||||
```vim
|
||||
let g:ale_linters_explicit = 1
|
||||
```
|
||||
|
||||
@@ -81,13 +81,13 @@ You can then run `:ALEFix` in a JavaScript or CSS file to run Prettier.
|
||||
|
||||
To have ALE run Prettier on save:
|
||||
|
||||
```
|
||||
```vim
|
||||
let g:ale_fix_on_save = 1
|
||||
```
|
||||
|
||||
It's recommended to use a [config file](configuration.md), but you can also add options in your `.vimrc`:
|
||||
|
||||
```
|
||||
```vim
|
||||
let g:ale_javascript_prettier_options = '--single-quote --trailing-comma es5'
|
||||
```
|
||||
|
||||
@@ -96,26 +96,28 @@ let g:ale_javascript_prettier_options = '--single-quote --trailing-comma es5'
|
||||
Prettier extension for [coc.nvim](https://github.com/neoclide/coc.nvim) which requires neovim or vim8.1.
|
||||
Install coc.nvim with your favorite plugin manager, such as [vim-plug](https://github.com/junegunn/vim-plug):
|
||||
|
||||
```
|
||||
```vim
|
||||
Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
|
||||
```
|
||||
|
||||
And install coc-prettier by command:
|
||||
|
||||
```
|
||||
```vim
|
||||
CocInstall coc-prettier
|
||||
```
|
||||
|
||||
Setup `Prettier` command in your `init.vim` or `.vimrc`
|
||||
|
||||
```
|
||||
```vim
|
||||
command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile')
|
||||
```
|
||||
|
||||
Update your `coc-settings.json` for languages that you want format on save.
|
||||
|
||||
```
|
||||
"coc.preferences.formatOnSaveFiletypes": ["css", "Markdown"],
|
||||
```json
|
||||
{
|
||||
"coc.preferences.formatOnSaveFiletypes": ["css", "Markdown"]
|
||||
}
|
||||
```
|
||||
|
||||
[coc-prettier](https://github.com/neoclide/coc-prettier) have same configurations of [prettier-vscode](https://github.com/prettier/prettier-vscode), open `coc-settings.json` by `:CocConfig` to get autocompletion support.
|
||||
@@ -124,7 +126,7 @@ Update your `coc-settings.json` for languages that you want format on save.
|
||||
|
||||
If you want something really bare-bones, you can create a custom key binding. In this example, `gp` (mnemonic: "get pretty") is used to run prettier (with options) in the currently active buffer:
|
||||
|
||||
```
|
||||
```vim
|
||||
nnoremap gp :silent %!prettier --stdin-filepath % --trailing-comma all --single-quote<CR>
|
||||
```
|
||||
|
||||
|
||||
@@ -5,14 +5,16 @@ title: Watching For Changes
|
||||
|
||||
If you prefer to have prettier watch for changes from the command line you can use a package like [onchange](https://www.npmjs.com/package/onchange). For example:
|
||||
|
||||
```
|
||||
```bash
|
||||
npx onchange '**/*.js' -- npx prettier --write {{changed}}
|
||||
```
|
||||
|
||||
or add the following to your `package.json`
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"prettier-watch": "onchange '**/*.js' -- prettier --write {{changed}}"
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
Reference in new issue
Block a user