Format docs with Prettier 1.13

master
Lucas Duailibe 2018-05-27 15:37:44 -03:00
parent 1a4dda73a9
commit 412b064df8
25 changed files with 817 additions and 818 deletions

File diff suppressed because it is too large Load Diff

View File

@ -10,12 +10,12 @@ yarn test
Here's what you need to know about the tests:
* The tests use [Jest snapshots](https://facebook.github.io/jest/docs/en/snapshot-testing.html).
* You can make changes and run `jest -u` (or `yarn test -u`) to update the snapshots. Then run `git diff` to take a look at what changed. Always update the snapshots when opening a PR.
* You can run `AST_COMPARE=1 jest` for a more robust test run. That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent.
* Each test folder has a `jsfmt.spec.js` that runs the tests. For JavaScript files, generally you can just put `run_spec(__dirname, ["babylon", "flow", "typescript"]);` there. This will verify that the output using each parser is the same. You can also pass options as the third argument, like this: `run_spec(__dirname, ["babylon"], { trailingComma: "es5" });`
* `tests/flow/` contains the Flow test suite, and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.js ../flow/tests/`.
* If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file and run it in an editor like VS Code.
- The tests use [Jest snapshots](https://facebook.github.io/jest/docs/en/snapshot-testing.html).
- You can make changes and run `jest -u` (or `yarn test -u`) to update the snapshots. Then run `git diff` to take a look at what changed. Always update the snapshots when opening a PR.
- You can run `AST_COMPARE=1 jest` for a more robust test run. That formats each file, re-parses it, and compares the new AST with the original one and makes sure they are semantically equivalent.
- Each test folder has a `jsfmt.spec.js` that runs the tests. For JavaScript files, generally you can just put `run_spec(__dirname, ["babylon", "flow", "typescript"]);` there. This will verify that the output using each parser is the same. You can also pass options as the third argument, like this: `run_spec(__dirname, ["babylon"], { trailingComma: "es5" });`
- `tests/flow/` contains the Flow test suite, and is not supposed to be edited by hand. To update it, clone the Flow repo next to the Prettier repo and run: `node scripts/sync-flow-tests.js ../flow/tests/`.
- If you would like to debug prettier locally, you can either debug it in node or the browser. The easiest way to debug it in the browser is to run the interactive `docs` REPL locally. The easiest way to debug it in node, is to create a local test file and run it in an editor like VS Code.
Run `yarn lint --fix` to automatically format files.

View File

@ -213,13 +213,13 @@ If it's using in a whitespace-sensitive language, e.g. markdown, you should use
For example:
* `useTabs`
* `tabWidth: 2`
* `<indent><align 2><indent><align 2>` -> `<tab><tab><tab><2 space>`
* `<indent><align 4><indent><align 2>` -> `<tab><tab><tab><2 space>`
* `tabWidth: 4`
* `<indent><align 2><indent><align 2>` -> `<tab><tab><tab><2 space>`
* `<indent><align 4><indent><align 2>` -> `<tab><tab><tab><2 space>`
- `useTabs`
- `tabWidth: 2`
- `<indent><align 2><indent><align 2>` -> `<tab><tab><tab><2 space>`
- `<indent><align 4><indent><align 2>` -> `<tab><tab><tab><2 space>`
- `tabWidth: 4`
- `<indent><align 2><indent><align 2>` -> `<tab><tab><tab><2 space>`
- `<indent><align 4><indent><align 2>` -> `<tab><tab><tab><2 space>`
### markAsRoot

View File

@ -35,8 +35,8 @@ prettier.formatWithCursor(" 1", { cursorOffset: 2 });
`resolveConfig` can be used to resolve configuration for a given source file, passing its path as the first argument. The config search will start at the file path and continue to search up the directory (you can use `process.cwd()` to start searching from the current directory). Or you can pass directly the path of the config file as `options.config` if you don't wish to search for it. A promise is returned which will resolve to:
* An options object, providing a [config file](configuration.md) was found.
* `null`, if no file was found.
- An options object, providing a [config file](configuration.md) was found.
- `null`, if no file was found.
The promise will be rejected if there was an error parsing the configuration file.
@ -51,9 +51,9 @@ prettier.resolveConfig(filePath).then(options => {
If `options.editorconfig` is `true` and an [`.editorconfig` file](http://editorconfig.org/) is in your project, Prettier will parse it and convert its properties to the corresponding prettier configuration. This configuration will be overridden by `.prettierrc`, etc. Currently, the following EditorConfig properties are supported:
* `indent_style`
* `indent_size`/`tab_width`
* `max_line_length`
- `indent_style`
- `indent_size`/`tab_width`
- `max_line_length`
Use `prettier.resolveConfig.sync(filePath [, options])` if you'd like to use sync version.
@ -61,8 +61,8 @@ Use `prettier.resolveConfig.sync(filePath [, options])` if you'd like to use syn
`resolveConfigFile` can be used to find the path of the Prettier's configuration file will be used when resolving the config (i.e. when calling `resolveConfig`). A promise is returned which will resolve to:
* The path of the configuration file.
* `null`, if no file was found.
- The path of the configuration file.
- `null`, if no file was found.
The promise will be rejected if there was an error parsing the configuration file.

View File

@ -110,8 +110,8 @@ This rewrites all processed files in place. This is comparable to the `eslint --
Change the level of logging for the CLI. Valid options are:
* `error`
* `warn`
* `log` (default)
* `debug`
* `silent`
- `error`
- `warn`
- `log` (default)
- `debug`
- `silent`

View File

@ -5,9 +5,9 @@ title: Configuration File
Prettier uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for configuration file support. This means you can configure prettier via:
* A `.prettierrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`.
* A `prettier.config.js` file that exports an object.
* A `"prettier"` key in your `package.json` file.
- A `.prettierrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`.
- A `prettier.config.js` file that exports an object.
- A `"prettier"` key in your `package.json` file.
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn't) found.

View File

@ -9,8 +9,8 @@ Atom users can simply install the [prettier-atom] package and use `Ctrl+Alt+F` t
Alternatively, you can use one the packages below, which behave similarly to [prettier-atom] but have a focus on minimalism.
* [mprettier](https://github.com/t9md/atom-mprettier)
* [miniprettier](https://github.com/duailibe/atom-miniprettier)
- [mprettier](https://github.com/t9md/atom-mprettier)
- [miniprettier](https://github.com/duailibe/atom-miniprettier)
## Emacs

View File

@ -5,14 +5,14 @@ title: What is Prettier?
Prettier is an opinionated code formatter with support for:
* JavaScript, including [ES2017](https://github.com/tc39/proposals/blob/master/finished-proposals.md)
* [JSX](https://facebook.github.io/jsx/)
* [Flow](https://flow.org/)
* [TypeScript](https://www.typescriptlang.org/)
* CSS, [Less](http://lesscss.org/), and [SCSS](http://sass-lang.com)
* [JSON](http://json.org/)
* [GraphQL](http://graphql.org/)
* [Markdown](http://commonmark.org/), including [GFM](https://github.github.com/gfm/)
- JavaScript, including [ES2017](https://github.com/tc39/proposals/blob/master/finished-proposals.md)
- [JSX](https://facebook.github.io/jsx/)
- [Flow](https://flow.org/)
- [TypeScript](https://www.typescriptlang.org/)
- CSS, [Less](http://lesscss.org/), and [SCSS](http://sass-lang.com)
- [JSON](http://json.org/)
- [GraphQL](http://graphql.org/)
- [Markdown](http://commonmark.org/), including [GFM](https://github.github.com/gfm/)
It removes all original styling[\*](#footnotes) and ensures that all outputted code conforms to a consistent style. (See this [blog post](http://jlongster.com/A-Prettier-Formatter))

View File

@ -17,10 +17,10 @@ Well, had Prettier been created around the same time as JavaScript itself was bo
Then there's a bunch of interesting cases.
* `--trailing-comma es5` was added to make it easier to use trailing commas in most environments without having to transpile (trailing function commas were added in ES2017).
* `--prose-wrap` is important to support all quirky markdown renderers in the wild.
* `--arrow-parens` was added after [huge demand](https://github.com/prettier/prettier/issues/812). Prettier has to strike a balance between ideal goals and listening to the community.
* `--jsx-bracket-same-line` was needed for a big company with a huge code base (Facebook), which backed the project when it got started, to be able to [adopt Prettier at all](https://github.com/prettier/prettier/pull/661#issuecomment-295770645).
- `--trailing-comma es5` was added to make it easier to use trailing commas in most environments without having to transpile (trailing function commas were added in ES2017).
- `--prose-wrap` is important to support all quirky markdown renderers in the wild.
- `--arrow-parens` was added after [huge demand](https://github.com/prettier/prettier/issues/812). Prettier has to strike a balance between ideal goals and listening to the community.
- `--jsx-bracket-same-line` was needed for a big company with a huge code base (Facebook), which backed the project when it got started, to be able to [adopt Prettier at all](https://github.com/prettier/prettier/pull/661#issuecomment-295770645).
Finally, perhaps the most interesting of them all is `--bracket-spacing`.
The truth is that not even [Prettier's creator knows exactly why it exists](https://github.com/prettier/prettier/issues/715#issuecomment-281096495). It was added super early on without much thought. It now serves as an example of the types of options we should avoid.

View File

@ -43,8 +43,8 @@ Print semicolons at the ends of statements.
Valid options:
* `true` - Add a semicolon at the end of every statement.
* `false` - Only add semicolons at the beginning of lines that may introduce ASI failures.
- `true` - Add a semicolon at the end of every statement.
- `false` - Only add semicolons at the beginning of lines that may introduce ASI failures.
| Default | CLI Override | API Override |
| ------- | ------------ | -------------- |
@ -56,8 +56,8 @@ Use single quotes instead of double quotes.
Notes:
* Quotes in JSX will always be double and ignore this setting.
* If the number of quotes outweighs the other quote, the quote which is less used will be used to format the string - Example: `"I'm double quoted"` results in `"I'm double quoted"` and `"This \"example\" is single quoted"` results in `'This "example" is single quoted'`.
- Quotes in JSX will always be double and ignore this setting.
- If the number of quotes outweighs the other quote, the quote which is less used will be used to format the string - Example: `"I'm double quoted"` results in `"I'm double quoted"` and `"This \"example\" is single quoted"` results in `'This "example" is single quoted'`.
| Default | CLI Override | API Override |
| ------- | ---------------- | --------------------- |
@ -69,9 +69,9 @@ Print trailing commas wherever possible when multi-line. (A single-line array, f
Valid options:
* `"none"` - No trailing commas.
* `"es5"` - Trailing commas where valid in ES5 (objects, arrays, etc.)
* `"all"` - Trailing commas wherever possible (including function arguments). This requires node 8 or a [transform](https://babeljs.io/docs/plugins/syntax-trailing-function-commas/).
- `"none"` - No trailing commas.
- `"es5"` - Trailing commas where valid in ES5 (objects, arrays, etc.)
- `"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 |
| -------- | ------------------------------------------------------ | ------------------------------------------------------ |
@ -83,8 +83,8 @@ Print spaces between brackets in object literals.
Valid options:
* `true` - Example: `{ foo: bar }`.
* `false` - Example: `{foo: bar}`.
- `true` - Example: `{ foo: bar }`.
- `false` - Example: `{foo: bar}`.
| Default | CLI Override | API Override |
| ------- | ---------------------- | ------------------------ |
@ -96,7 +96,7 @@ Put the `>` of a multi-line JSX element at the end of the last line instead of b
Valid options:
* `true` - Example:
- `true` - Example:
<!-- prettier-ignore -->
```
@ -108,7 +108,7 @@ Valid options:
</button>
```
* `false` - Example:
- `false` - Example:
<!-- prettier-ignore -->
```
@ -133,8 +133,8 @@ Include parentheses around a sole arrow function parameter.
Valid options:
* `"avoid"` - Omit parens when possible. Example: `x => x`
* `"always"` - Always include parens. Example: `(x) => x`
- `"avoid"` - Omit parens when possible. Example: `x => x`
- `"always"` - Always include parens. Example: `(x) => x`
| Default | CLI Override | API Override |
| --------- | ----------------------------------------------- | ----------------------------------------------- |
@ -146,8 +146,8 @@ Format only a segment of a file.
These two options can be used to format code starting and ending at a given character offset (inclusive and exclusive, respectively). The range will extend:
* Backwards to the start of the first line containing the selected statement.
* Forwards to the end of the selected statement.
- Backwards to the start of the first line containing the selected statement.
- Forwards to the end of the selected statement.
These options cannot be used with `cursorOffset`.
@ -164,13 +164,13 @@ Both the `babylon` and `flow` parsers support the same set of JavaScript feature
Built-in parsers:
* [`babylon`](https://github.com/babel/babel/tree/master/packages/babylon)
* [`flow`](https://github.com/facebook/flow/tree/master/src/parser)
* [`typescript`](https://github.com/eslint/typescript-eslint-parser) _Since v1.4.0_
* [`postcss`](https://github.com/postcss/postcss) _Since v1.4.0_
* [`json`](https://github.com/babel/babylon/tree/f09eb3200f57ea94d51c2a5b1facf2149fb406bf#babylonparseexpressioncode-options) _Since v1.5.0_
* [`graphql`](https://github.com/graphql/graphql-js/tree/master/src/language) _Since v1.5.0_
* [`markdown`](https://github.com/wooorm/remark/tree/master/packages/remark-parse) _Since v1.8.0_
- [`babylon`](https://github.com/babel/babel/tree/master/packages/babylon)
- [`flow`](https://github.com/facebook/flow/tree/master/src/parser)
- [`typescript`](https://github.com/eslint/typescript-eslint-parser) _Since v1.4.0_
- [`postcss`](https://github.com/postcss/postcss) _Since v1.4.0_
- [`json`](https://github.com/babel/babylon/tree/f09eb3200f57ea94d51c2a5b1facf2149fb406bf#babylonparseexpressioncode-options) _Since v1.5.0_
- [`graphql`](https://github.com/graphql/graphql-js/tree/master/src/language) _Since v1.5.0_
- [`markdown`](https://github.com/wooorm/remark/tree/master/packages/remark-parse) _Since v1.8.0_
[Custom parsers](api.md#custom-parser-api) are also supported. _Since v1.5.0_
@ -238,9 +238,9 @@ By default, Prettier will wrap markdown text as-is since some services use a lin
Valid options:
* `"always"` - Wrap prose if it exceeds the print width.
* `"never"` - Do not wrap prose.
* `"preserve"` - Wrap prose as-is. _available in v1.9.0+_
- `"always"` - Wrap prose if it exceeds the print width.
- `"never"` - Do not wrap prose.
- `"preserve"` - Wrap prose as-is. _available in v1.9.0+_
| Default | CLI Override | API Override |
| ------------ | ----------------------------------------------------------- | ----------------------------------------------------------- |

View File

@ -15,7 +15,7 @@ Plugins are automatically loaded if you have them installed in the same `node_mo
When plugins cannot be found automatically, you can load them with:
* The [CLI](./cli.md), via the `--plugin` and `--plugin-search-dir`:
- The [CLI](./cli.md), via the `--plugin` and `--plugin-search-dir`:
```bash
prettier --write main.foo --plugin-search-dir=./dir-with-plugins --plugin=./foo-plugin
@ -23,7 +23,7 @@ When plugins cannot be found automatically, you can load them with:
> Tip: You can set `--plugin` or `--plugin-search-dir` options multiple times.
* Or the [API](./api.md), via the `plugins` and `pluginSearchDirs` options:
- Or the [API](./api.md), via the `plugins` and `pluginSearchDirs` options:
```js
prettier.format("code", {
@ -39,26 +39,26 @@ Providing at least one path to `--plugin-search-dir`/`pluginSearchDirs` turns of
## Official Plugins
* [`@prettier/plugin-python`](https://github.com/prettier/plugin-python)
* [`@prettier/plugin-php`](https://github.com/prettier/plugin-php)
* [`@prettier/plugin-swift`](https://github.com/prettier/plugin-swift)
- [`@prettier/plugin-python`](https://github.com/prettier/plugin-python)
- [`@prettier/plugin-php`](https://github.com/prettier/plugin-php)
- [`@prettier/plugin-swift`](https://github.com/prettier/plugin-swift)
## Community Plugins
* [`prettier-plugin-elm`](https://github.com/gicentre/prettier-plugin-elm) by [**@giCentre**](https://github.com/gicentre)
* [`prettier-plugin-java`](https://github.com/thorbenvh8/prettier-java) by [**@thorbenvh8**](https://github.com/thorbenvh8)
* [`prettier-plugin-pg`](https://github.com/benjie/prettier-plugin-pg) by [**@benjie**](https://github.com/benjie)
* [`prettier-plugin-ruby`](https://github.com/iamsolankiamit/prettier-ruby) by [**@iamsolankiamit**](https://github.com/iamsolankiamit)
- [`prettier-plugin-elm`](https://github.com/gicentre/prettier-plugin-elm) by [**@giCentre**](https://github.com/gicentre)
- [`prettier-plugin-java`](https://github.com/thorbenvh8/prettier-java) by [**@thorbenvh8**](https://github.com/thorbenvh8)
- [`prettier-plugin-pg`](https://github.com/benjie/prettier-plugin-pg) by [**@benjie**](https://github.com/benjie)
- [`prettier-plugin-ruby`](https://github.com/iamsolankiamit/prettier-ruby) by [**@iamsolankiamit**](https://github.com/iamsolankiamit)
## Developing Plugins
Prettier plugins are regular JavaScript modules with five exports:
* `languages`
* `parsers`
* `printers`
* `options`
* `defaultOptions`
- `languages`
- `parsers`
- `printers`
- `options`
- `defaultOptions`
### `languages`

View File

@ -23,8 +23,8 @@ Prettier maintains the way your string is escaped. For example, `"🙂"` won't b
It turns out that empty lines are very hard to automatically generate. The approach that Prettier takes is to preserve empty lines the way they were in the original source code. There are two additional rules:
* Prettier collapses multiple blank lines into a single blank line.
* Empty lines at the start and end of blocks (and whole files) are removed. (Files always end with a single newline, though.)
- Prettier collapses multiple blank lines into a single blank line.
- Empty lines at the start and end of blocks (and whole files) are removed. (Files always end with a single newline, though.)
### Multi-line objects
@ -142,7 +142,7 @@ Prettier only _prints_ code. It does not transform it. This is to limit the scop
Here are a few examples of things that are out of scope for Prettier:
* Turning single- or double-quoted strings into template literals or vice versa.
* Adding/removing `{}` and `return` where they are optional.
* Turning `?:` into `if`-`else` statements.
* Sorting and hoisting `import`s. (Sorting is unsafe because of side effects, which would violate the [correctness](#correctness) goal.)
- Turning single- or double-quoted strings into template literals or vice versa.
- Adding/removing `{}` and `return` where they are optional.
- Turning `?:` into `if`-`else` statements.
- Sorting and hoisting `import`s. (Sorting is unsafe because of side effects, which would violate the [correctness](#correctness) goal.)

View File

@ -5,33 +5,33 @@ title: Related Projects
## ESLint Integrations
* [`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier) plugs Prettier into your ESLint workflow
* [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) turns off all ESLint rules that are unnecessary or might conflict with Prettier
* [`prettier-eslint`](https://github.com/prettier/prettier-eslint) passes `prettier` output to `eslint --fix`
* [`prettier-standard`](https://github.com/sheerun/prettier-standard) uses `prettier` and `prettier-eslint` to format code with standard rules
* [`prettier-standard-formatter`](https://github.com/dtinth/prettier-standard-formatter) passes `prettier` output to `standard --fix`
- [`eslint-plugin-prettier`](https://github.com/prettier/eslint-plugin-prettier) plugs Prettier into your ESLint workflow
- [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) turns off all ESLint rules that are unnecessary or might conflict with Prettier
- [`prettier-eslint`](https://github.com/prettier/prettier-eslint) passes `prettier` output to `eslint --fix`
- [`prettier-standard`](https://github.com/sheerun/prettier-standard) uses `prettier` and `prettier-eslint` to format code with standard rules
- [`prettier-standard-formatter`](https://github.com/dtinth/prettier-standard-formatter) passes `prettier` output to `standard --fix`
## TSLint Integrations
* [`tslint-plugin-prettier`](https://github.com/ikatyang/tslint-plugin-prettier) runs Prettier as a TSLint rule and reports differences as individual TSLint issues
* [`tslint-config-prettier`](https://github.com/alexjoverm/tslint-config-prettier) use TSLint with Prettier without any conflict
* [`prettier-tslint`](https://github.com/azz/prettier-tslint) passes `prettier` output to `tslint --fix`
- [`tslint-plugin-prettier`](https://github.com/ikatyang/tslint-plugin-prettier) runs Prettier as a TSLint rule and reports differences as individual TSLint issues
- [`tslint-config-prettier`](https://github.com/alexjoverm/tslint-config-prettier) use TSLint with Prettier without any conflict
- [`prettier-tslint`](https://github.com/azz/prettier-tslint) passes `prettier` output to `tslint --fix`
## stylelint Integrations
* [`prettier-stylelint`](https://github.com/hugomrdias/prettier-stylelint) passes `prettier` output to `stylelint --fix`
* [`stylelint-config-prettier`](https://github.com/shannonmoeller/stylelint-config-prettier) turns off all rules that are unnecessary or might conflict with Prettier.
- [`prettier-stylelint`](https://github.com/hugomrdias/prettier-stylelint) passes `prettier` output to `stylelint --fix`
- [`stylelint-config-prettier`](https://github.com/shannonmoeller/stylelint-config-prettier) turns off all rules that are unnecessary or might conflict with Prettier.
## Forks
* [`prettier-miscellaneous`](https://github.com/arijs/prettier-miscellaneous) `prettier` with a few minor extra options
- [`prettier-miscellaneous`](https://github.com/arijs/prettier-miscellaneous) `prettier` with a few minor extra options
## Misc
* [`neutrino-preset-prettier`](https://github.com/SpencerCDixon/neutrino-preset-prettier) allows you to use Prettier as a Neutrino preset
* [`prettier_d`](https://github.com/josephfrazier/prettier_d.js) runs Prettier as a server to avoid Node.js startup delay. It also supports configuration via `.prettierrc`, `package.json`, and `.editorconfig`.
* [`Prettier Bookmarklet`](https://prettier.glitch.me/) provides a bookmarklet and exposes a REST API for Prettier that allows to format CodeMirror editor in your browser
* [`prettier-github`](https://github.com/jgierer12/prettier-github) formats code in GitHub comments
* [`rollup-plugin-prettier`](https://github.com/mjeanroy/rollup-plugin-prettier) allows you to use Prettier with Rollup
* [`markdown-magic-prettier`](https://github.com/camacho/markdown-magic-prettier) allows you to use Prettier to format JS [codeblocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) in Markdown files via [Markdown Magic](https://github.com/DavidWells/markdown-magic)
* [`pretty-quick`](https://github.com/azz/pretty-quick) formats your changed files with Prettier
- [`neutrino-preset-prettier`](https://github.com/SpencerCDixon/neutrino-preset-prettier) allows you to use Prettier as a Neutrino preset
- [`prettier_d`](https://github.com/josephfrazier/prettier_d.js) runs Prettier as a server to avoid Node.js startup delay. It also supports configuration via `.prettierrc`, `package.json`, and `.editorconfig`.
- [`Prettier Bookmarklet`](https://prettier.glitch.me/) provides a bookmarklet and exposes a REST API for Prettier that allows to format CodeMirror editor in your browser
- [`prettier-github`](https://github.com/jgierer12/prettier-github) formats code in GitHub comments
- [`rollup-plugin-prettier`](https://github.com/mjeanroy/rollup-plugin-prettier) allows you to use Prettier with Rollup
- [`markdown-magic-prettier`](https://github.com/camacho/markdown-magic-prettier) allows you to use Prettier to format JS [codeblocks](https://help.github.com/articles/creating-and-highlighting-code-blocks/) in Markdown files via [Markdown Magic](https://github.com/DavidWells/markdown-magic)
- [`pretty-quick`](https://github.com/azz/pretty-quick) formats your changed files with Prettier

View File

@ -29,8 +29,8 @@ autocmd BufWritePre *.js Neoformat
You can also make Vim format your code more frequently, by setting an `autocmd` for other events. Here are a couple of useful ones:
* `TextChanged`: after a change was made to the text in Normal mode
* `InsertLeave`: when leaving Insert mode
- `TextChanged`: after a change was made to the text in Normal mode
- `InsertLeave`: when leaving Insert mode
For example, you can format on both of the above events together with `BufWritePre` like this:

View File

@ -19,13 +19,13 @@ To automatically format your files using `prettier` on save, you can use a file
Go to _Preferences | Tools | File Watchers_ and click **+** to add a new watcher. Lets name it **Prettier**.
* **File Type**: _JavaScript_ (or _Any_ if you want to run `prettier` on all files)
* **Scope**: _Project Files_
* **Program**: full path to `.bin/prettier` or `.bin\prettier.cmd` in the project's `node_module` folder. Or, if Prettier is installed globally, select `prettier` on macOS and Linux or `C:\Users\user_name\AppData\Roaming\npm\prettier.cmd` on Windows (or whatever `npm prefix -g` returns).
* **Arguments**: `--write [other options] $FilePathRelativeToProjectRoot$`
* **Output paths to refresh**: `$FilePathRelativeToProjectRoot$`
* **Working directory**: `$ProjectFileDir$`
* **Auto-save edited files to trigger the watcher**: Uncheck to reformat on Save only.
- **File Type**: _JavaScript_ (or _Any_ if you want to run `prettier` on all files)
- **Scope**: _Project Files_
- **Program**: full path to `.bin/prettier` or `.bin\prettier.cmd` in the project's `node_module` folder. Or, if Prettier is installed globally, select `prettier` on macOS and Linux or `C:\Users\user_name\AppData\Roaming\npm\prettier.cmd` on Windows (or whatever `npm prefix -g` returns).
- **Arguments**: `--write [other options] $FilePathRelativeToProjectRoot$`
- **Output paths to refresh**: `$FilePathRelativeToProjectRoot$`
- **Working directory**: `$ProjectFileDir$`
- **Auto-save edited files to trigger the watcher**: Uncheck to reformat on Save only.
![Example](/docs/assets/webstorm/file-watcher-prettier.png)
@ -41,9 +41,9 @@ Make sure that the ESLint integration is enabled in _Preferences | Languages & F
Go to _Preferences | Tools | External Tools_ and click **+** to add a new tool. Lets name it **Prettier**.
* **Program**: `prettier` on macOS and Linux or `C:\Users\user_name\AppData\Roaming\npm\prettier.cmd` on Windows (or whatever `npm prefix -g` returns), if Prettier is installed globally
* **Parameters**: `--write [other options] $FilePathRelativeToProjectRoot$`
* **Working directory**: `$ProjectFileDir$`
- **Program**: `prettier` on macOS and Linux or `C:\Users\user_name\AppData\Roaming\npm\prettier.cmd` on Windows (or whatever `npm prefix -g` returns), if Prettier is installed globally
- **Parameters**: `--write [other options] $FilePathRelativeToProjectRoot$`
- **Working directory**: `$ProjectFileDir$`
> If Prettier is installed locally in your project, replace the path in **Program** with `$ProjectFileDir$/node_modules/.bin/prettier` on macOS and Linux or `$ProjectFileDir$\node_modules\.bin\prettier.cmd` on Windows.

View File

@ -9,53 +9,53 @@ By far the biggest reason for adopting Prettier is to stop all the on-going deba
So why choose the "Prettier style guide" over any other random style guide? Because Prettier is the only "style guide" that is fully automatic. Even if Prettier does not format all code 100% the way you'd like, it's worth the "sacrifice" given the unique benefits of Prettier, don't you think?
* “We want to free mental threads and end discussions around style. While sometimes fruitful, these discussions are for the most part wasteful.”
* “Literally had an engineer go through a huge effort of cleaning up all of our code because we were debating ternary style for the longest time and were inconsistent about it. It was dumb, but it was a weird on-going "great debate" that wasted lots of little back and forth bits. It's far easier for us all to agree now: just run Prettier, and go with that style.”
* “Getting tired telling people how to style their product code.”
* “Our top reason was to stop wasting our time debating style nits.”
* “Having a githook set up has reduced the amount of style issues in PRs that result in broken builds due to ESLint rules or things I have to nit-pick or clean up later.”
* “I don't want anybody to nitpick any other person ever again.”
* “It reminds me of how Steve Jobs used to wear the same clothes every day because he has a million decisions to make and he didn't want to be bothered to make trivial ones like picking out clothes. I think Prettier is like that.”
- “We want to free mental threads and end discussions around style. While sometimes fruitful, these discussions are for the most part wasteful.”
- “Literally had an engineer go through a huge effort of cleaning up all of our code because we were debating ternary style for the longest time and were inconsistent about it. It was dumb, but it was a weird on-going "great debate" that wasted lots of little back and forth bits. It's far easier for us all to agree now: just run Prettier, and go with that style.”
- “Getting tired telling people how to style their product code.”
- “Our top reason was to stop wasting our time debating style nits.”
- “Having a githook set up has reduced the amount of style issues in PRs that result in broken builds due to ESLint rules or things I have to nit-pick or clean up later.”
- “I don't want anybody to nitpick any other person ever again.”
- “It reminds me of how Steve Jobs used to wear the same clothes every day because he has a million decisions to make and he didn't want to be bothered to make trivial ones like picking out clothes. I think Prettier is like that.”
## Helping Newcomers
Prettier is usually introduced by people with experience in the current codebase and JavaScript but the people that disproportionally benefit from it are newcomers to the codebase. One may think that it's only useful for people with very limited programming experience, but we've seen it quicken the ramp up time from experienced engineers joining the company, as they likely used a different coding style before, and developers coming from a different programming language.
* “My motivations for using Prettier are: appearing that I know how to write JavaScript well.”
* “I always put spaces in the wrong place, now I don't have to worry about it anymore.”
* “When you're a beginner you're making a lot of mistakes caused by the syntax. Thanks to Prettier, you can reduce these mistakes and save a lot of time to focus on what really matters.”
* “As a teacher, I will also tell to my students to install Prettier to help them to learn the JS syntax and have readable files.”
- “My motivations for using Prettier are: appearing that I know how to write JavaScript well.”
- “I always put spaces in the wrong place, now I don't have to worry about it anymore.”
- “When you're a beginner you're making a lot of mistakes caused by the syntax. Thanks to Prettier, you can reduce these mistakes and save a lot of time to focus on what really matters.”
- “As a teacher, I will also tell to my students to install Prettier to help them to learn the JS syntax and have readable files.”
## Writing code
What usually happens once people are using Prettier is that they realize that they actually spend a lot of time and mental energy formatting their code. With Prettier editor integration, you can just press that magic key binding and poof, the code is formatted. This is an eye opening experience if anything else.
* “I want to write code. Not spend cycles on formatting.”
* “It removed 5% that sucks in our daily life - aka formatting”
* “We're in 2017 and it's still painful to break a call into multiple lines when you happen to add an argument that makes it go over the 80 columns limit :(“
- “I want to write code. Not spend cycles on formatting.”
- “It removed 5% that sucks in our daily life - aka formatting”
- “We're in 2017 and it's still painful to break a call into multiple lines when you happen to add an argument that makes it go over the 80 columns limit :(“
## Easy to adopt
We've worked very hard to use the least controversial coding styles, went through many rounds of fixing all the edge cases and polished the getting started experience. When you're ready to push Prettier into your codebase, not only should it be painless for you to do it technically but the newly formatted codebase should not generate major controversy and be accepted painlessly by your co-workers.
* “It's low overhead. We were able to throw Prettier at very different kinds of repos without much work.”
* “It's been mostly bug free. Had there been major styling issues during the course of implementation we would have been wary about throwing this at our JS codebase. I'm happy to say that's not the case.”
* “Everyone runs it as part of their pre commit scripts, a couple of us use the editor on save extensions as well.”
* “It's fast, against one of our larger JS codebases we were able to run Prettier in under 13 seconds.”
* “The biggest benefit for Prettier for us was being able to format the entire code base at once.”
- “It's low overhead. We were able to throw Prettier at very different kinds of repos without much work.”
- “It's been mostly bug free. Had there been major styling issues during the course of implementation we would have been wary about throwing this at our JS codebase. I'm happy to say that's not the case.”
- “Everyone runs it as part of their pre commit scripts, a couple of us use the editor on save extensions as well.”
- “It's fast, against one of our larger JS codebases we were able to run Prettier in under 13 seconds.”
- “The biggest benefit for Prettier for us was being able to format the entire code base at once.”
## Clean up an existing codebase
Since coming up with a coding style and enforcing it is a big undertaking, it often slips through the cracks and you are left working on inconsistent codebases. Running Prettier in this case is a quick win, the codebase is now uniform and easier to read without spending hardly any time.
* “Take a look at the code :) I just need to restore sanity.”
* “We inherited a ~2000 module ES6 code base, developed by 20 different developers over 18 months, in a global team. Felt like such a win without much research.”
- “Take a look at the code :) I just need to restore sanity.”
- “We inherited a ~2000 module ES6 code base, developed by 20 different developers over 18 months, in a global team. Felt like such a win without much research.”
## Ride the hype train
Purely technical aspects of the projects aren't the only thing people look into when choosing to adopt Prettier. Who built and uses it and how quickly it spreads through the community has a non-trivial impact.
* “The amazing thing, for me, is: 1) Announced 2 months ago. 2) Already adopted by, it seems, every major JS project. 3) 7000 stars, 100,000 npm downloads/mo”
* “Was built by the same people as React & React Native.”
* “I like to be part of the hot new things.”
* “Because soon enough people are gonna ask for it.”
- “The amazing thing, for me, is: 1) Announced 2 months ago. 2) Already adopted by, it seems, every major JS project. 3) 7000 stars, 100,000 npm downloads/mo”
- “Was built by the same people as React & React Native.”
- “I like to be part of the hot new things.”
- “Because soon enough people are gonna ask for it.”

View File

@ -6,7 +6,6 @@ const path = require("path");
const shell = require("shelljs");
const rootDir = path.join(__dirname, "..");
const staticDir = path.join(rootDir, "website/static");
const docs = path.join(rootDir, "website/static/lib");
function pipe(string) {

View File

@ -604,11 +604,11 @@ same behavior as the original source. You shouldn't be afraid of running
prettier on your entire codebase. In order to ensure this, we are doing a lot of
things:
* Have an automated way to ensure that prettier is outputting valid code.
* Use it against large codebases such as Facebook, all of CDNjs and the many
- Have an automated way to ensure that prettier is outputting valid code.
- Use it against large codebases such as Facebook, all of CDNjs and the many
people in the community using it.
* Run extensive fuzzing using [eslump](https://github.com/lydell/eslump).
* Making every report of such issue as high-pri and fixed right away.
- Run extensive fuzzing using [eslump](https://github.com/lydell/eslump).
- Making every report of such issue as high-pri and fixed right away.
If you are unlucky enough to see one, please report it so that we can fix it and
you can use `// prettier-ignore` to get you unblocked.

View File

@ -22,17 +22,17 @@ Now, the entire Facebook codebase is way bigger than this and it's not feasible
Running prettier on a piece of code is a pretty expensive operation, it makes your pull request look bad because of a lot of unrelated changes and it causes merge conflicts for all the outstanding pull requests. So **once a file has been formatted, you should do everything to make sure it remains formatted**.
* When pretty-printing a file, add `@format` to the first block comment like `@flow`.
* Have a lint rule with autofix that checks if the file is correctly pretty printed when `@format` is present.
* When running Nuclide, it's going to show as an inline warning and have a fix button.
* When sending a pull request, it's going to show the lint failing with a [Yn] prompt that you can just press enter.
* Update the default code templates to add `@format` to the header.
* When you run code formatting via cmd-shift-c inside of Nuclide, automatically insert the `@format` header.
* Disable all the stylistic rules like max-len when `@format` is in the header.
* Have script to run prettier through an entire folder with everything configured as a one line operation.
* Have a good guide to help people that want to convert their codebase over with instructions and best practices.
* When pushing a new release of prettier, also run it through all the files with `@format` in order to avoid getting warnings afterwards.
* Add tracking for the number of files with `@format` over time.
- When pretty-printing a file, add `@format` to the first block comment like `@flow`.
- Have a lint rule with autofix that checks if the file is correctly pretty printed when `@format` is present.
- When running Nuclide, it's going to show as an inline warning and have a fix button.
- When sending a pull request, it's going to show the lint failing with a [Yn] prompt that you can just press enter.
- Update the default code templates to add `@format` to the header.
- When you run code formatting via cmd-shift-c inside of Nuclide, automatically insert the `@format` header.
- Disable all the stylistic rules like max-len when `@format` is in the header.
- Have script to run prettier through an entire folder with everything configured as a one line operation.
- Have a good guide to help people that want to convert their codebase over with instructions and best practices.
- When pushing a new release of prettier, also run it through all the files with `@format` in order to avoid getting warnings afterwards.
- Add tracking for the number of files with `@format` over time.
We finally got all those things wired up 1.5 weeks ago and the reception has been insane. Many people from various teams converted their codebase to prettier on their own. As of today, 15% of Facebook codebase has been converted over!

View File

@ -47,7 +47,7 @@ package.json
The last big friction point from people trying to adopt prettier was around how JSX was being printed. We went through all the issues that were raised and made a bunch of changes:
* Arrow Function Expressions returning JSX will now add parens when the JSX breaks
- Arrow Function Expressions returning JSX will now add parens when the JSX breaks
<!-- prettier-ignore -->
```jsx
@ -65,7 +65,7 @@ const Component = props => (
);
```
* Conditional expressions within (or containing) JSX are formatted in a different way using parenthesis
- Conditional expressions within (or containing) JSX are formatted in a different way using parenthesis
<!-- prettier-ignore -->
```jsx
@ -92,7 +92,7 @@ const Component = props => (
</div>
```
* JSX in logical expressions (|| or &&) is always wrapped in parens when the JSX breaks
- JSX in logical expressions (|| or &&) is always wrapped in parens when the JSX breaks
<!-- prettier-ignore -->
```jsx

View File

@ -154,65 +154,65 @@ Previously, there was no way via the API to resolve configuration for a source f
### PRs merged in this release
* [**Update README.md**](https://github.com/prettier/prettier/pull/2690) by [@ikatyang](https://github.com/ikatyang)
* [**Fix config file finding when using stdin**](https://github.com/prettier/prettier/pull/2692) by [@lydell](https://github.com/lydell)
* [**docs(readme): add and sort cli options**](https://github.com/prettier/prettier/pull/2700) by [@levithomason](https://github.com/levithomason)
* [**Add Transloadit as a user**](https://github.com/prettier/prettier/pull/2706) by [@kvz](https://github.com/kvz)
* [**Ensure parens around LogicalExpression inside ExperimentalSpreadProperty**](https://github.com/prettier/prettier/pull/2710) by [@existentialism](https://github.com/existentialism)
* [**Fix printing declare modifier for TS enum**](https://github.com/prettier/prettier/pull/2711) by [@existentialism](https://github.com/existentialism)
* [**Handle +/- before numbers in CSS**](https://github.com/prettier/prettier/pull/2713) by [@xtian](https://github.com/xtian)
* [**Add Tradeshift as a user**](https://github.com/prettier/prettier/pull/2719) by [@sampi](https://github.com/sampi)
* [**feat(resolve-config): add `.sync()` method**](https://github.com/prettier/prettier/pull/2722) by [@ikatyang](https://github.com/ikatyang)
* [**refactor(bin): use `resolveConfigFile.sync()`**](https://github.com/prettier/prettier/pull/2728) by [@ikatyang](https://github.com/ikatyang)
* [**refactor(cli): separate files and make it pure as possible**](https://github.com/prettier/prettier/pull/2730) by [@ikatyang](https://github.com/ikatyang)
* [**Fix cosmiconfig dependency branch**](https://github.com/prettier/prettier/pull/2731) by [@josephfrazier](https://github.com/josephfrazier)
* [**Upgrade chalk to v2.1.0**](https://github.com/prettier/prettier/pull/2732) by [@josephfrazier](https://github.com/josephfrazier)
* [**Add CLI option '--config-precedence'**](https://github.com/prettier/prettier/pull/2733) by [@mitermayer](https://github.com/mitermayer)
* [**Normalize CSS case**](https://github.com/prettier/prettier/pull/2736) by [@lydell](https://github.com/lydell)
* [**Make run-external-typescript-tests.js cross-platform**](https://github.com/prettier/prettier/pull/2737) by [@lydell](https://github.com/lydell)
* [**test(integration): add more tests**](https://github.com/prettier/prettier/pull/2738) by [@ikatyang](https://github.com/ikatyang)
* [**chore(deps): remove devDependency `cross-spawn`**](https://github.com/prettier/prettier/pull/2739) by [@ikatyang](https://github.com/ikatyang)
* [**Ignore some things in coverage**](https://github.com/prettier/prettier/pull/2741) by [@lydell](https://github.com/lydell)
* [**Generalize run-external-typescript-tests.js**](https://github.com/prettier/prettier/pull/2742) by [@lydell](https://github.com/lydell)
* [**Improve lint-staged setup example by adding more filetypes**](https://github.com/prettier/prettier/pull/2746) by [@MoOx](https://github.com/MoOx)
* [**fixes dynamic imports**](https://github.com/prettier/prettier/pull/2748) by [@rkurbatov](https://github.com/rkurbatov)
* [**Refactor error handling**](https://github.com/prettier/prettier/pull/2750) by [@azz](https://github.com/azz)
* [**chore(github): add issue template**](https://github.com/prettier/prettier/pull/2755) by [@ikatyang](https://github.com/ikatyang)
* [**Fix: TypeScript never keyword (fixes [#2718](https://github.com/prettier/prettier/pull/2718))**](https://github.com/prettier/prettier/pull/2756) by [@JamesHenry](https://github.com/JamesHenry)
* [**Group last argument if it's an empty object with a comment**](https://github.com/prettier/prettier/pull/2758) by [@duailibe](https://github.com/duailibe)
* [**Use `files:` over `types:` in pre-commit configuration**](https://github.com/prettier/prettier/pull/2759) by [@asottile](https://github.com/asottile)
* [**refactor(runPrettier): reduce duplicate code**](https://github.com/prettier/prettier/pull/2764) by [@ikatyang](https://github.com/ikatyang)
* [**Change when to print ternaries in JSX mode**](https://github.com/prettier/prettier/pull/2768) by [@duailibe](https://github.com/duailibe)
* [**Fix chained logical expressions with objects/array/etc inlined**](https://github.com/prettier/prettier/pull/2770) by [@duailibe](https://github.com/duailibe)
* [**Add option to require @prettier or @format pragma**](https://github.com/prettier/prettier/pull/2772) by [@wbinnssmith](https://github.com/wbinnssmith)
* [**chore(build): update ISSUE_TEMPLATE.md before publish**](https://github.com/prettier/prettier/pull/2776) by [@ikatyang](https://github.com/ikatyang)
* [**Fix break on conditional expressions inside return**](https://github.com/prettier/prettier/pull/2779) by [@duailibe](https://github.com/duailibe)
* [**Support graphql(schema, `query`)**](https://github.com/prettier/prettier/pull/2781) by [@azz](https://github.com/azz)
* [**fix(prettierignore): support absolute filename**](https://github.com/prettier/prettier/pull/2783) by [@ambar](https://github.com/ambar)
* [**Keep conditional expressions in one line on method chains**](https://github.com/prettier/prettier/pull/2784) by [@duailibe](https://github.com/duailibe)
* [**fix(build): update ISSUE_TEMPLATE using regex `?:` instead of `?!`**](https://github.com/prettier/prettier/pull/2785) by [@ikatyang](https://github.com/ikatyang)
* [**Break closing paren of ConditionalExpression in member chains**](https://github.com/prettier/prettier/pull/2786) by [@duailibe](https://github.com/duailibe)
* [**fix webstorm integration guide**](https://github.com/prettier/prettier/pull/2796) by [@xsburg](https://github.com/xsburg)
- [**Update README.md**](https://github.com/prettier/prettier/pull/2690) by [@ikatyang](https://github.com/ikatyang)
- [**Fix config file finding when using stdin**](https://github.com/prettier/prettier/pull/2692) by [@lydell](https://github.com/lydell)
- [**docs(readme): add and sort cli options**](https://github.com/prettier/prettier/pull/2700) by [@levithomason](https://github.com/levithomason)
- [**Add Transloadit as a user**](https://github.com/prettier/prettier/pull/2706) by [@kvz](https://github.com/kvz)
- [**Ensure parens around LogicalExpression inside ExperimentalSpreadProperty**](https://github.com/prettier/prettier/pull/2710) by [@existentialism](https://github.com/existentialism)
- [**Fix printing declare modifier for TS enum**](https://github.com/prettier/prettier/pull/2711) by [@existentialism](https://github.com/existentialism)
- [**Handle +/- before numbers in CSS**](https://github.com/prettier/prettier/pull/2713) by [@xtian](https://github.com/xtian)
- [**Add Tradeshift as a user**](https://github.com/prettier/prettier/pull/2719) by [@sampi](https://github.com/sampi)
- [**feat(resolve-config): add `.sync()` method**](https://github.com/prettier/prettier/pull/2722) by [@ikatyang](https://github.com/ikatyang)
- [**refactor(bin): use `resolveConfigFile.sync()`**](https://github.com/prettier/prettier/pull/2728) by [@ikatyang](https://github.com/ikatyang)
- [**refactor(cli): separate files and make it pure as possible**](https://github.com/prettier/prettier/pull/2730) by [@ikatyang](https://github.com/ikatyang)
- [**Fix cosmiconfig dependency branch**](https://github.com/prettier/prettier/pull/2731) by [@josephfrazier](https://github.com/josephfrazier)
- [**Upgrade chalk to v2.1.0**](https://github.com/prettier/prettier/pull/2732) by [@josephfrazier](https://github.com/josephfrazier)
- [**Add CLI option '--config-precedence'**](https://github.com/prettier/prettier/pull/2733) by [@mitermayer](https://github.com/mitermayer)
- [**Normalize CSS case**](https://github.com/prettier/prettier/pull/2736) by [@lydell](https://github.com/lydell)
- [**Make run-external-typescript-tests.js cross-platform**](https://github.com/prettier/prettier/pull/2737) by [@lydell](https://github.com/lydell)
- [**test(integration): add more tests**](https://github.com/prettier/prettier/pull/2738) by [@ikatyang](https://github.com/ikatyang)
- [**chore(deps): remove devDependency `cross-spawn`**](https://github.com/prettier/prettier/pull/2739) by [@ikatyang](https://github.com/ikatyang)
- [**Ignore some things in coverage**](https://github.com/prettier/prettier/pull/2741) by [@lydell](https://github.com/lydell)
- [**Generalize run-external-typescript-tests.js**](https://github.com/prettier/prettier/pull/2742) by [@lydell](https://github.com/lydell)
- [**Improve lint-staged setup example by adding more filetypes**](https://github.com/prettier/prettier/pull/2746) by [@MoOx](https://github.com/MoOx)
- [**fixes dynamic imports**](https://github.com/prettier/prettier/pull/2748) by [@rkurbatov](https://github.com/rkurbatov)
- [**Refactor error handling**](https://github.com/prettier/prettier/pull/2750) by [@azz](https://github.com/azz)
- [**chore(github): add issue template**](https://github.com/prettier/prettier/pull/2755) by [@ikatyang](https://github.com/ikatyang)
- [**Fix: TypeScript never keyword (fixes [#2718](https://github.com/prettier/prettier/pull/2718))**](https://github.com/prettier/prettier/pull/2756) by [@JamesHenry](https://github.com/JamesHenry)
- [**Group last argument if it's an empty object with a comment**](https://github.com/prettier/prettier/pull/2758) by [@duailibe](https://github.com/duailibe)
- [**Use `files:` over `types:` in pre-commit configuration**](https://github.com/prettier/prettier/pull/2759) by [@asottile](https://github.com/asottile)
- [**refactor(runPrettier): reduce duplicate code**](https://github.com/prettier/prettier/pull/2764) by [@ikatyang](https://github.com/ikatyang)
- [**Change when to print ternaries in JSX mode**](https://github.com/prettier/prettier/pull/2768) by [@duailibe](https://github.com/duailibe)
- [**Fix chained logical expressions with objects/array/etc inlined**](https://github.com/prettier/prettier/pull/2770) by [@duailibe](https://github.com/duailibe)
- [**Add option to require @prettier or @format pragma**](https://github.com/prettier/prettier/pull/2772) by [@wbinnssmith](https://github.com/wbinnssmith)
- [**chore(build): update ISSUE_TEMPLATE.md before publish**](https://github.com/prettier/prettier/pull/2776) by [@ikatyang](https://github.com/ikatyang)
- [**Fix break on conditional expressions inside return**](https://github.com/prettier/prettier/pull/2779) by [@duailibe](https://github.com/duailibe)
- [**Support graphql(schema, `query`)**](https://github.com/prettier/prettier/pull/2781) by [@azz](https://github.com/azz)
- [**fix(prettierignore): support absolute filename**](https://github.com/prettier/prettier/pull/2783) by [@ambar](https://github.com/ambar)
- [**Keep conditional expressions in one line on method chains**](https://github.com/prettier/prettier/pull/2784) by [@duailibe](https://github.com/duailibe)
- [**fix(build): update ISSUE_TEMPLATE using regex `?:` instead of `?!`**](https://github.com/prettier/prettier/pull/2785) by [@ikatyang](https://github.com/ikatyang)
- [**Break closing paren of ConditionalExpression in member chains**](https://github.com/prettier/prettier/pull/2786) by [@duailibe](https://github.com/duailibe)
- [**fix webstorm integration guide**](https://github.com/prettier/prettier/pull/2796) by [@xsburg](https://github.com/xsburg)
### Issues resolved in this release
* [**Document missing CLI options**](https://github.com/prettier/prettier/issues/2698) reported by [@levithomason](https://github.com/levithomason)
* [**Formatting of Spread Properties differs between Babylon and TypeScript**](https://github.com/prettier/prettier/issues/2708) reported by [@mariusschulz](https://github.com/mariusschulz)
* [**Removal of the `declare` modifier from `enum`**](https://github.com/prettier/prettier/issues/2709) reported by [@mariusschulz](https://github.com/mariusschulz)
* [**Decimal formatting doesn't get all decimals in a rule.**](https://github.com/prettier/prettier/issues/2712) reported by [@itsgreggreg](https://github.com/itsgreggreg)
* [**Use resolveConfigFile.sync in the CLI**](https://github.com/prettier/prettier/issues/2726) reported by [@azz](https://github.com/azz)
* [**CSS: Normalize case (lower vs upper) on stuff**](https://github.com/prettier/prettier/issues/2653) reported by [@lydell](https://github.com/lydell)
* [**Dynamic import with webpackChunkName comment fails**](https://github.com/prettier/prettier/issues/1489) reported by [@pbomb](https://github.com/pbomb)
* [**TypeScript: never as type parameter causes error: unknown type: undefined**](https://github.com/prettier/prettier/issues/2718) reported by [@hccampos](https://github.com/hccampos)
* [**commented object values**](https://github.com/prettier/prettier/issues/2617) reported by [@sylvainbaronnet](https://github.com/sylvainbaronnet)
* [**Configuring pre-commit for jsx, TypeScript, tsx**](https://github.com/prettier/prettier/issues/2745) reported by [@reywright](https://github.com/reywright)
* [**JSX ternaries include parens**](https://github.com/prettier/prettier/issues/2729) reported by [@jasonLaster](https://github.com/jasonLaster)
* [**Chained Short Circuit Conditionals in JSX**](https://github.com/prettier/prettier/issues/2714) reported by [@brycehill](https://github.com/brycehill)
* [**Support @prettier pragma comment**](https://github.com/prettier/prettier/issues/2397) reported by [@ajhyndman](https://github.com/ajhyndman)
* [**No indentation after breaking return statement**](https://github.com/prettier/prettier/issues/2777) reported by [@jwbay](https://github.com/jwbay)
* [**Support graphql() fn and so make 2nd arg prettier**](https://github.com/prettier/prettier/issues/2780) reported by [@brikou](https://github.com/brikou)
* [**prettierignore: cannot use absolute filename**](https://github.com/prettier/prettier/issues/2782) reported by [@ambar](https://github.com/ambar)
* [**Weird JavaScript format**](https://github.com/prettier/prettier/issues/2775) reported by [@maxime1992](https://github.com/maxime1992)
- [**Document missing CLI options**](https://github.com/prettier/prettier/issues/2698) reported by [@levithomason](https://github.com/levithomason)
- [**Formatting of Spread Properties differs between Babylon and TypeScript**](https://github.com/prettier/prettier/issues/2708) reported by [@mariusschulz](https://github.com/mariusschulz)
- [**Removal of the `declare` modifier from `enum`**](https://github.com/prettier/prettier/issues/2709) reported by [@mariusschulz](https://github.com/mariusschulz)
- [**Decimal formatting doesn't get all decimals in a rule.**](https://github.com/prettier/prettier/issues/2712) reported by [@itsgreggreg](https://github.com/itsgreggreg)
- [**Use resolveConfigFile.sync in the CLI**](https://github.com/prettier/prettier/issues/2726) reported by [@azz](https://github.com/azz)
- [**CSS: Normalize case (lower vs upper) on stuff**](https://github.com/prettier/prettier/issues/2653) reported by [@lydell](https://github.com/lydell)
- [**Dynamic import with webpackChunkName comment fails**](https://github.com/prettier/prettier/issues/1489) reported by [@pbomb](https://github.com/pbomb)
- [**TypeScript: never as type parameter causes error: unknown type: undefined**](https://github.com/prettier/prettier/issues/2718) reported by [@hccampos](https://github.com/hccampos)
- [**commented object values**](https://github.com/prettier/prettier/issues/2617) reported by [@sylvainbaronnet](https://github.com/sylvainbaronnet)
- [**Configuring pre-commit for jsx, TypeScript, tsx**](https://github.com/prettier/prettier/issues/2745) reported by [@reywright](https://github.com/reywright)
- [**JSX ternaries include parens**](https://github.com/prettier/prettier/issues/2729) reported by [@jasonLaster](https://github.com/jasonLaster)
- [**Chained Short Circuit Conditionals in JSX**](https://github.com/prettier/prettier/issues/2714) reported by [@brycehill](https://github.com/brycehill)
- [**Support @prettier pragma comment**](https://github.com/prettier/prettier/issues/2397) reported by [@ajhyndman](https://github.com/ajhyndman)
- [**No indentation after breaking return statement**](https://github.com/prettier/prettier/issues/2777) reported by [@jwbay](https://github.com/jwbay)
- [**Support graphql() fn and so make 2nd arg prettier**](https://github.com/prettier/prettier/issues/2780) reported by [@brikou](https://github.com/brikou)
- [**prettierignore: cannot use absolute filename**](https://github.com/prettier/prettier/issues/2782) reported by [@ambar](https://github.com/ambar)
- [**Weird JavaScript format**](https://github.com/prettier/prettier/issues/2775) reported by [@maxime1992](https://github.com/maxime1992)
---

View File

@ -33,8 +33,8 @@ foo => {};
This lead to the [most commented thread](https://github.com/prettier/prettier/issues/812) in our issue tracker. Prettier now has the `--arrow-parens` option (`arrowParens` in the config) that can assume two values today:
* `"avoid"` - (default) preserve the behavior that omits parens when possible
* `"always"` - always includes parens
- `"avoid"` - (default) preserve the behavior that omits parens when possible
- `"always"` - always includes parens
#### JSX fragment syntax ([#3237](https://github.com/prettier/prettier/pull/3237)) by [@duailibe](https://github.com/duailibe)
@ -117,9 +117,9 @@ CSS is mostly case insensitive, so Prettier has been lowercasing stuff for a whi
It's taken a while, but Prettier will finally respect your `.editorconfig` file. This includes:
* `indent_style`
* `indent_size`/`tab_width`
* `max_line_length`
- `indent_style`
- `indent_size`/`tab_width`
- `max_line_length`
The `prettier` CLI respects `.editorconfig` by default, but you can opt out with `--no-editorconfig`.
However, the API _doesn't_ respect `.editorconfig` by default, in order to avoid potential editor integration issues (see [here](https://github.com/prettier/prettier/pull/3255#discussion_r152259674) for details). To opt in, add `editorconfig: true` to the `prettier.resolveConfig` options.

View File

@ -78,9 +78,9 @@ Using plugins is as simple as installing them via `npm`/`yarn`, and running Pret
There are three official plugins under development:
* [`@prettier/plugin-python`](https://github.com/prettier/prettier-python)
* [`@prettier/plugin-php`](https://github.com/prettier/prettier-php)
* [`@prettier/plugin-swift`](https://github.com/prettier/prettier-swift)
- [`@prettier/plugin-python`](https://github.com/prettier/prettier-python)
- [`@prettier/plugin-php`](https://github.com/prettier/prettier-php)
- [`@prettier/plugin-swift`](https://github.com/prettier/prettier-swift)
All three of these plugins are still under active development and aren't ready to throw production code at, but keep an eye on them as they're progressing!
@ -410,8 +410,8 @@ $ prettier --loglevel silent --write test.js
We've fixed up the behavior of the CLI when it comes to ignored files. Previously when a file was ignored by `.prettierignore`, the CLI would ouput nothing. This affected editor integrations. The behaviour is now:
* With `--write`, don't read or write to the ignored file.
* Without `--write`, read the ignored file and output as-is.
- With `--write`, don't read or write to the ignored file.
- Without `--write`, read the ignored file and output as-is.
### Editor Integrations

View File

@ -12,9 +12,9 @@ After more than 200 merged pull requests since mid December 2017, we're happy to
Adding support for a new language to Prettier requires two things:
* A parser, which turns your source code into an abstract syntax tree (AST). Since Prettier is written in JavaScript, we're using [php-parser](https://github.com/glayzzle/php-parser), which is a PHP parser written in JS.
- A parser, which turns your source code into an abstract syntax tree (AST). Since Prettier is written in JavaScript, we're using [php-parser](https://github.com/glayzzle/php-parser), which is a PHP parser written in JS.
* A printer, that turns the AST into a special format called `doc` that Prettier requires to do its magic. It is basically your source code plus some information about where linebreaks can be added, how it should be indented, and so on.
- A printer, that turns the AST into a special format called `doc` that Prettier requires to do its magic. It is basically your source code plus some information about where linebreaks can be added, how it should be indented, and so on.
While we could benefit from existing work on the parsing side, the printer had to be developed from scratch to support all of PHP's various AST node types. Our first alpha release today means that we are confident that the printer can re-print your code without breaking it.
@ -44,7 +44,7 @@ For our first stable release, the following milestones still have to be reached:
Are you excited about Prettier for PHP? Then we'd love you to help us reach our first stable release by
* Trying it on your code base
* [Reporting any issues](https://github.com/prettier/plugin-php/issues) you find with it
* Contributing ([how to get started](https://github.com/prettier/plugin-php/blob/master/CONTRIBUTING.md))
* Spreading the word 😉
- Trying it on your code base
- [Reporting any issues](https://github.com/prettier/plugin-php/issues) you find with it
- Contributing ([how to get started](https://github.com/prettier/plugin-php/blob/master/CONTRIBUTING.md))
- Spreading the word 😉

View File

@ -39,8 +39,8 @@ Read more about it in the [docs](https://prettier.io/docs/en/browser.html).
In Prettier 1.12 and earlier, when running Prettier on a file without a file extension, Prettier would assume the file contained JavaScript. This lead to a couple of confusing bugs, namely:
* If you ran prettier on your `.git` directory, it would reformat files and break your git repo.
* If you tried to run prettier on html files, it would sometimes throw an error, but other times parse the HTML as JSX, and format it as if it was JSX (which was often unsafe).
- If you ran prettier on your `.git` directory, it would reformat files and break your git repo.
- If you tried to run prettier on html files, it would sometimes throw an error, but other times parse the HTML as JSX, and format it as if it was JSX (which was often unsafe).
In Prettier 1.13, we are changing this behavior. If Prettier cannot determine what language a file is from its extension, and the user has not manually specified a parser to use, Prettier will skip the file.
@ -294,21 +294,21 @@ These JS features were already supported when using the default Babylon parser,
New features added to Flow are now supported by Prettier:
* inline interfaces
- inline interfaces
<!-- prettier-ignore -->
```ts
type A = interface { p: string};
```
* explicit type arguments
- explicit type arguments
<!-- prettier-ignore -->
```ts
fnCall<string>("name");
```
* proto modifier syntax
- proto modifier syntax
<!-- prettier-ignore -->
```ts
@ -323,11 +323,11 @@ A new feature added in TypeScript 2.9 for describing the shapes of a module impo
```ts
// Input
export const x:import( "./foo" )={x:0,y:0};
export const x: import("./foo") = { x: 0, y: 0 };
export let y:import("./foo2" ).Bar.I={a:"",b:0};
export let y: import("./foo2").Bar.I = { a: "", b: 0 };
export let shim:typeof import( "./foo2")={Bar: Bar2};
export let shim: typeof import("./foo2") = { Bar: Bar2 };
// Output with Prettier 1.13
export const x: import("./foo") = { x: 0, y: 0 };