Skip to content

Tweak rationale.md and remove outdated/incorrect stuff - #3853

Merged
lydell merged 3 commits into
prettier:masterfrom
lydell:docs
Feb 1, 2018
Merged

lydell merged 3 commits into
prettier:masterfrom
lydell:docs

Conversation

@lydell

@lydell lydell commented Jan 31, 2018

Copy link
Copy Markdown
Member

No description provided.

@j-f1 j-f1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread docs/rationale.md Outdated
### 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!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…output valid code that…

(remove JavaScript and)

Comment thread docs/rationale.md Outdated
### 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.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the singleQuote option

Comment thread docs/rationale.md Outdated
### 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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two additional rules

Comment thread docs/rationale.md Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prettier collapses multiple blank lines into a single blank line.

Comment thread docs/rationale.md Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

… However, we always place a newline at the end of every file.

Comment thread docs/rationale.md Outdated
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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single- or double-quoted strings

Comment thread docs/rationale.md Outdated
* 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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if-else statements

@j-f1 j-f1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bah, wrong button

@j-f1 j-f1 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more little tiny nit:

Comment thread docs/rationale.md Outdated
### 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, Prettier’s printing algorithm prints expressions on a single line.

instead of the first sentence

@lydell
lydell merged commit 0c6253d into prettier:master Feb 1, 2018
@lydell
lydell deleted the docs branch February 1, 2018 06:47
@lock lock Bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Jan 18, 2019
@lock lock Bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants