Repository navigation
Tweak rationale.md and remove outdated/incorrect stuff - #3853
Merged
Merged
Conversation
j-f1
approved these changes
Jan 31, 2018
| ### Whitespace: indentation and line breaks | ||
|
|
||
| This is the core of Prettier. The formatting rules are going to be explained in a later section. | ||
| The first requirement of Prettier is to output valid JavaScript and code that has the exact same behavior as before formatting. Please report any code where Prettier fails to follow these correctness rules — that's a bug which needs to be fixed! |
Member
There was a problem hiding this comment.
…output valid code that…
(remove JavaScript and)
| ### Strings | ||
|
|
||
| Prettier enforces double quotes by default, but has a setting for enforcing single quotes instead. There are two exceptions: | ||
| Double or single quotes? Prettier chooses the one which results in the fewest number of escapes. `"It's gettin' better!"`, not `'It\'s gettin\' better!'`. In case of a tie, Prettier defaults to double quotes (but that can be changed via the [quotes](options.html#quotes) option.) |
| ### Empty lines | ||
|
|
||
| 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. The only constraint is that Prettier disallows several empty lines in a row. They are collapsed to a single one. | ||
| 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 to additional rules: |
| 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. The only constraint is that Prettier disallows several empty lines in a row. They are collapsed to a single one. | ||
| 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 to additional rules: | ||
|
|
||
| * Prettier disallows several empty lines in a row. They are collapsed into a single one. |
Member
There was a problem hiding this comment.
Prettier collapses multiple blank lines into a single blank line.
| 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 to additional rules: | ||
|
|
||
| * Prettier disallows several empty lines in a row. They are collapsed into a single one. | ||
| * Empty lines at the start and end of blocks (and whole files) are removed. |
Member
There was a problem hiding this comment.
… However, we always place a newline at the end of every file.
| Here are a few examples of things that are out of scope for Prettier: | ||
|
|
||
| * Turning single/double quotes into template literals or vice versa. | ||
| * Turning single/double quoted strings into template literals or vice versa. |
| * Turning single/double quotes into template literals or vice versa. | ||
| * Turning single/double quoted strings into template literals or vice versa. | ||
| * Adding/removing `{}` and `return` where they are optional. | ||
| * Turning `?:` into `if then else`. |
j-f1
requested changes
Jan 31, 2018
| ### Multi-line objects | ||
|
|
||
| It is tempting to collapse an object to a single line if it fits, but there are times when it is better for sibling/cousin keys to stay vertically aligned—see [object lists], [nested configs], [stylesheets], and [keyed methods]. To avoid unfavorable collapsing, Prettier simply formats any object as multi-line if it appears as such in the original source code. This is the same strategy used by [elm-format] for multi-line records. | ||
| Prettier's printing algorithm prints stuff in a single line if it fits by default. Objects are used for a lot of different things in JavaScript, though, and sometimes it really helps readability if they stay muliline. See [object lists], [nested configs], [stylesheets] and [keyed methods], for example. We haven't been able to find a good rule for all those cases, so Prettier instead keeps objects multiline if there's a newline anywhere inside it in the original source code. A consequence of this is that long singleline objects are automatically expanded, but short multiline objects are never collapsed. |
Member
There was a problem hiding this comment.
By default, Prettier’s printing algorithm prints expressions on a single line.
instead of the first sentence
j-f1
approved these changes
Jan 31, 2018
suchipi
approved these changes
Feb 1, 2018
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.