Commit Graph

971 Commits (c8f255d6d574054e170692f3bc09683334a011cb)

Author SHA1 Message Date
Christopher Chedeau c8f255d6d5 Port a handful of heuristics we had to work on typescript nodes as well (#1735) 2017-05-25 16:49:25 -07:00
Christopher Chedeau 267c6edaf5 Inline import type (#1729)
A long time ago I introduced the ability to break for import statements. Then, later on, we removed the ability for require to break and go over the 80 column mark. In order to be consistent, we should do the same for import statements as well.
2017-05-25 16:27:04 -07:00
Christopher Chedeau d06c46d045 Break on implements instead of extends (#1730)
There can often be something that breaks inside of `extends` so it's looking weird to break twice. It now only breaks on `implements` and make sure to put each element on its own line.

Fixes #1520
2017-05-25 16:26:56 -07:00
Christopher Chedeau ffc1b3702e Remove parenthesis for JSX inside of arrow functions (#1733)
I didn't intend for putting parenthesis there in the first place but it slept through. Since it was going to trigger a ton of changes I held up changing it, but I feel like we need to do it sooner than later otherwise we're not going to be able to do it. A lot of people writing functional components are going to be very happy about this change :)
2017-05-25 16:26:49 -07:00
Christopher Chedeau fe49650700 Inline | null and | void (#1734)
TypeScript doesn't have the concept of `?` for nullable options and instead you have to write `| null` and `| void`. This is annoying to have it use the long form, so we're now inlining them.

While working on this, I found out a few issues with the way we deal with those:
- We only align objects if the parent is a union. This means that if you have `Array<{ object }>`, the object is not aligned properly. The fix is to move the alignment logic to the union, and not the child.
- When doing so, it messes up with the comment alignment, so we have to manually handle children comment printing in the union code.

It doesn't yet fix #1727 because the hardcoded type names are different, i'll follow up in a PR.
2017-05-25 16:26:40 -07:00
Christopher Chedeau 62679f20f0 Indent conditions inside of !() (#1731)
This has been a longstanding issue and I thought it would be hard to do, but turns out it is pretty easy!

Fixes #774
2017-05-25 16:26:34 -07:00
Christopher Chedeau 198ba3c065 Force \n for multiple variable declarations (#1723)
This keeps being requested and we're not using it at Facebook, so I don't particularly care which way it should be printed. We now force multiline if there's at least one declaration with a value. We don't want to break all the variables that are just declared.

Fixes #1607
2017-05-25 16:26:26 -07:00
Christopher Chedeau 9a93822bbc Use the same breaking rules for assignment and object values (#1721)
Fixes #1417
Fixes #1604
2017-05-24 18:19:15 -07:00
Christopher Chedeau 449bc41316 Use expandLast for nested arrow functions (#1720)
We don't always want to automatically forward this option but we can always forward it to `n.body`. If it's an arrow function, it's doing the intended behavior, otherwise, it's not going to ignore it and not forward it. What we don't want is for arrow -> blockStatement -> arrow to get it, but we're good.

Fixes #1652
2017-05-24 18:19:07 -07:00
Joseph Frazier 9d7515907e Pass entire text through formatWithShebang() to format() (#1718)
* Verify shebang tests against Babylon as well as Flow/Typescript

* Pass entire text through formatWithShebang() to format()

That way, we won't have to do any arithmetic on range and cursor
locations when there is a shebang. See here for details:

https://github.com/prettier/prettier/pull/1637#issuecomment-303846507

This required changing comment printing such that comments that are
actually shebangs are just ignored.

* Add curly brace after `if`

See https://github.com/prettier/prettier/pull/1718#discussion_r118382574
2017-05-24 18:59:25 -04:00
Joseph Frazier 7344a37b5c Enforce braces after `if`/etc (#1719)
See https://github.com/prettier/prettier/pull/1718#discussion_r118382742
2017-05-24 15:57:05 -07:00
Christopher Chedeau a6068c0532 Temporary fix comments inside of flow type spread (#1716)
This is breaking on fb code. While benjamn/ast-types#221 is getting merged in ast-type, we can add it in prettier so it fixes the issue.

Fixes #1632
2017-05-24 15:21:30 -07:00
Joseph Frazier 71a39d2512 Ignore docs/prettier.min.js when searching with ag/ripgrep/sift (#1717)
This makes it easier to search through the code without getting
irrelevant results. It uses a .ignore file in order to cover at least
the three tools mentioned in the title. See the discussion here:

https://news.ycombinator.com/item?id=12568822
2017-05-24 15:21:21 -07:00
Simon Lydell 01b953c580 Saying "Coming soon" doesn't really help anyway 2017-05-24 23:06:04 +02:00
Simon Lydell 4babc032cb Make it easier to find the WebStorm guide 2017-05-24 22:59:55 +02:00
Dara Hak 1f378b9755 Replace JetBrains with WebStorm in README.md (#1715)
The links are clearly about the WebStorm IDE and JetBrains is just the company's name.
This can be confusing for users.
2017-05-24 13:33:32 -07:00
Christopher Chedeau a53c609f8f Add .flowconfig (#1711)
I have no intention of using flow to type prettier but adding this file makes Nuclide run flow and get jump to definition and some datatips for what it can infer.
2017-05-24 13:20:25 -07:00
Christopher Chedeau 58194e5375 Fix empty lines with comments between switch cases (#1709)
The function isPreviousLineEmpty comment doesn't skip comments (on purpose, see comment above that method :P) so the detection is messed up. Turns out, it's easier to just use isNextLineEmpty like everywhere else.

Fixes #1708
2017-05-24 13:20:05 -07:00
Christopher Chedeau 5a9bea1c2f Fix comments inside of template literals (#1713)
We completely butcher comments inside of template literals. The fix is to not be able to attach comments to TemplateExpression nodes and to avoid comments that are ine one expression to be moved to another expression. We now have the boundary to prevent outputting invalid code.

Fixes #1617
2017-05-24 13:19:56 -07:00
Christopher Chedeau 5d3a750b92 Put JSX comments inside of the parenthesis (#1712)
This is very unfortunate that we have to change the generic function that prints code but we want the JSXElement node to handle its comments printing itself in order to write them inside of the parenthesis instead of outside.

Fixes #555
2017-05-24 13:19:47 -07:00
Christopher Chedeau 7f1006056e Indent based on whitespace only for templates (#1714)
I implemented indenting based on any character that's before the `${` but it was not the right behavior. Instead people want to indent based on the indentation of this line. It's easy to fix :)

Fixes parts of #1626
2017-05-24 13:19:34 -07:00
Christopher Chedeau 78ba808322 Initial CSS support (#1636)
I wanted to see how hard it would be to add support for CSS inside of prettier. Turns out, it's not that hard. I spent a few hours printing post-css values and getting all the stylefmt unit tests to not throw.
2017-05-24 10:52:12 -07:00
Simon Lydell 0adeadb16e Link to node-glob's "glob primer"
As mentioned in #1707.
2017-05-24 18:17:31 +02:00
Michał Pierzchała 09df0fbe15 Extract contributing guide into separate document (#1702) 2017-05-24 08:32:20 -07:00
Michał Pierzchała 3a431d3fe7 Document --with-node-modules flag (#1701) 2017-05-24 03:25:45 -07:00
Christopher Chedeau 1df1389764 Add parenthesis for as inside of class extends (#1699)
Looks like we didn't properly support it for all the binary operators :p
2017-05-23 18:39:01 -07:00
Christopher Chedeau 7cd0b78fe7 Properly add parenthesis for as inside of binary expression (#1698)
The binary logic doesn't work if the node isn't a binary or logical expression
2017-05-23 18:36:14 -07:00
Christopher Chedeau cd60e020c3 Add support for TSQualifiedType in ast-types (#1696)
The comment doesn't print in the right location so there's likely more types missing but at least it's not crashing anymore
2017-05-23 18:18:46 -07:00
Christopher Chedeau a446cf18ce Add parenthesis for ternary inside of as (#1697) 2017-05-23 18:18:34 -07:00
Christopher Chedeau 44d02b8680 Support empty declare module (#1693) 2017-05-23 17:13:47 -07:00
Christopher Chedeau 5671f32c07 Handle comments at the beginning of ClassProperty value (#1692)
We didn't call the helper that handles this use case
2017-05-23 17:13:40 -07:00
Christopher Chedeau 9af859f0b2 Fix master 2017-05-23 17:13:01 -07:00
Christopher Chedeau 8ad31635b6 Make the comment chain comment detection more robust (#1691)
I kept adding places where comments could be but more use cases kept creeping in. So now this is a holistical approach, we check all the comments that can be between two nodes. This way we should be good to go :)
2017-05-23 16:31:10 -07:00
Christopher Chedeau f8ff7e5cd2 Add TSArrayType to ast-types (#1690) 2017-05-23 16:31:01 -07:00
Christopher Chedeau 7ab73e688d Add parenthesis around arrow functions in a cast (#1689) 2017-05-23 16:30:47 -07:00
Christopher Chedeau 474eed0ecb Do not add double space for export function without body with a comment (#1688) 2017-05-23 16:30:35 -07:00
Michał Pierzchała 7a0df958dc Ignore node_modules when running prettier from CLI (#1683)
* Ignore node_modules by default

* Add integration test suite for --with-node-modules CLI arg

* Refactor tests to snapshots

* Disable eslint for purposely faulty files

* Fix node 4

* Fix prettier

* Gitignore only top-level node_modules
2017-05-23 14:19:04 -07:00
Christopher Chedeau cf716e5538 Handle trailing comments in member chains (#1686) 2017-05-23 13:58:52 -07:00
Christopher Chedeau 47d9686402 Do not indent for switch case with `;` (#1687)
The indentation detection didn't discard empty statements
2017-05-23 13:58:43 -07:00
Christopher Chedeau bcc3eb9272 Add TSTupleType to ast-types (#1685)
Otherwise this throws
2017-05-23 13:14:30 -07:00
Christopher Chedeau 1e351436da Add parenthesis for binary expression inside of as (#1682) 2017-05-23 13:14:22 -07:00
Christopher Chedeau f69c5496c6 Break if the first group has an end of line comment (#1681)
This was unstable
2017-05-23 13:14:13 -07:00
Christopher Chedeau c46f230a40 Fix TSAbstractClass base (#1676)
This lets the comment traversal code discover it
2017-05-23 12:34:40 -07:00
Christopher Chedeau c2007ef2a4 Handle TypeScript decorators (#1678)
See this issue for creating the same decorators as babylon ( https://github.com/eslint/typescript-eslint-parser/issues/250 ), in the meantime, this is making a ton of files in vscode crash. So we can just support both :)
2017-05-23 12:33:54 -07:00
Christopher Chedeau 069df25475 Fix last comment of import (#1677)
We used to use isBlock as a heuristic but the real thing we want is to know if the comment is on its own line. Now it works with both :)
2017-05-23 12:33:46 -07:00
Christopher Chedeau 19486bdd17 Add parenthesis for ternaries inside of a cast (#1680) 2017-05-23 12:33:32 -07:00
Christopher Chedeau f50e42d8e9 Do not put softline before TSImportEqualsDeclaration (#1679)
I'm not sure why it was there but it makes the transform not stable
2017-05-23 12:33:26 -07:00
Christopher Chedeau e37ea2c1f6 Add expression node in TSAsExpression (#1675)
This lets the comment traversal code discover it
2017-05-23 12:33:18 -07:00
Christopher Chedeau 2c5dd4cc04 Print typescript class generics (#1673)
This is the only issue with the typescript codebase itself :)
2017-05-23 12:33:10 -07:00
Christopher Chedeau fc88aa185b Add parenthesis around binary expression inside of update expression (#1672)
This is not valid code but TypeScript parses it. It's easy to fix so might as well so we have one less failing test.
2017-05-23 12:33:03 -07:00