Commit Graph

512 Commits (0241d97b7783276e34b44234d8b1858ba14eb0b4)

Author SHA1 Message Date
Christopher Chedeau 0241d97b77 Do not attach comments to EmptyStatements in try/catch (#763)
We skip EmptyStatement when generating the list of preceding/enclosing/following nodes but didn't do the same for the exceptions.

Fixes #695
2017-02-22 17:43:29 -05:00
Brian Ng 9c558bfe71 Remove extra parens around ternary arguments of a new call (#776) 2017-02-22 10:28:52 -08:00
Rogelio Guzman e039ca888a Upgrade to Jest 19.0.1 (#779) 2017-02-22 10:28:17 -08:00
Rogelio Guzman d45e157563 Upgrade to Jest 19 (#762)
* Upgrade to Jest 19

* Use exact versions for Jest
2017-02-21 13:59:19 -08:00
Umidbek Karimov 278b489f38 Use double quotes in script wildcards to support windows `cmd.exe`. (#761) 2017-02-21 07:49:07 -08:00
Christopher Chedeau 5cc21c5498 Correctly place trailing comments in conditionals (#754)
Previously we would blindly put leading comments of the next expression, but we didn't account for a real trailing comment. By checking if the leadingNode is on the same line, we can correctly put it there when needed

Fixes #685
2017-02-20 20:25:30 -05:00
Davy Duperron d613f92f60 Fix missing comments in assignment pattern (#704)
* Add handleAssignmentPatternComments helper function.

* Add new tests 🎉.

* Remove unecessary arg in function.

* Reorder it.

* Experimental fix for key comments in the printComments function.

* Pull master and switch to @vjeux implementation.

* Fix bad rebase.

* Add additional checking for enclosingNode in handleObjectProperty function.
2017-02-20 07:39:08 -08:00
Davy Duperron 01b0692307 Fix leading & operators in flow types (#738)
* Add new logic for & op as IntersectionTypeAnnotation.

* Update flow tests accordingly.

* Update flow types perf tests.

* Remove op variable.
2017-02-20 07:18:39 -08:00
Davy Duperron de8873ab23 Add missing explanatory comment in ForStatement case (#748)
* Add missing explanatory comment in ForStatement case :notepad-spiral:.

* Update comment 🚀.
2017-02-20 10:15:46 -05:00
James Long 77f6f4de68 Add note about trailingComma option in versions 0.18.0 and below 2017-02-20 09:33:22 -05:00
Davy Duperron c32e0339d0 Fix missing dangling comments in for loop (#742)
* Add dangling comments printing in for loops.

* Add new tests.

* Simplify implementation by moving dangling comments upfront.

* Update tests accordingly.
2017-02-20 09:17:10 -05:00
Christopher Chedeau 135a3dd0a7 Remove extra parenthesis around await inside of unary expression (#745)
Big props to @bakkot for mentioning that yield shouldn't be applied the same treatment.

Fixes #728
2017-02-20 09:14:33 -05:00
Davy Duperron 0f34fb91eb Fix missing dangling comments in arrays (#744)
* Add missing dangling comments printing in arrays.

* Update tests accordingly.
2017-02-19 17:25:18 -08:00
Davy Duperron 1affecc1a0 Fix missing dangling comment in exports (#741)
* Add missing dangling comment injection.

* Update tests.

* Add code comment.
2017-02-19 14:39:09 -08:00
Davy Duperron f106b1ec97 Fix await ternary parenthesis (#740)
* Add missing case.

* Update tests.
2017-02-19 14:31:54 -08:00
James Long 9399c1b656 Update README with valid trailingComma options 2017-02-18 08:58:34 -05:00
James Long 5d131027ce Make trailing-comma option support 2 different modes (#641)
* Make trailing-comma option support 2 different modes

* Add deprecation warning

* Add deprecation warning to API
2017-02-17 22:44:55 -05:00
Vincent Voyer 417279cacd docs(README): use yarn add for consistency (#734)
Other places we say we default to yarn but then we use npm, was confusing a bit.
2017-02-17 11:10:07 -08:00
Christopher Chedeau 848dfa3505 0.18.0 2017-02-16 09:28:26 -08:00
Christopher Chedeau e30482d440 Fix trailing new lines preservation (#724)
There is an off by one error which made the algorithm not work all the time. In many cases, it actually is the opposite, so whenever you save, it adds/removes that line. I noticed it during the --debug-check run on our codebase but didn't investigate.

Fixes #723
2017-02-16 09:56:12 -05:00
Christopher Chedeau 330b136cec re-run snapshot tests 2017-02-15 21:21:09 -08:00
Christopher Chedeau 00e5014e00 Align boolean inside of arrow functions (#691)
We already do it for if/... but it looks weird for arrow function body.
2017-02-15 20:00:02 -08:00
Christopher Chedeau b93a207bb2 Run prettier on 0.17.0 2017-02-15 19:56:11 -08:00
Christopher Chedeau d8c242891b Do not put \n inside of empty object method bodies (#706)
Fixes #703
2017-02-15 20:52:54 -05:00
Christopher Chedeau 7046d978a4 [RFC] Preserve new lines between array elements (#707)
This has come up many times in the past and while going through the fb codebase, there are a few instances where we group array elements logically using empty lines and it's a shame that they are gone.
2017-02-15 20:52:28 -05:00
Andrey Okonetchnikov 291871df53 docs: Add pre-commit hook with 🚫💩 lint-staged section to the README (#714) 2017-02-15 20:52:03 -05:00
Tom McKearney 0e399f0414 [Docs]: update Readme to reference VS extension (#720)
Added a link to Mads Kristensen's new VS extension for prettier
2017-02-15 20:51:34 -05:00
Brian Ng e0f82cd7d9 Ensure importKind is printed (#718) 2017-02-15 12:56:34 -08:00
Christopher Chedeau 1b37cb0365 [RFC] Remove parenthesis object special case (#689)
I've started the discussion around it but I think that it was a mistake. It feels weird to add parenthesis on object values sometimes but not others. I think that it's best to let prettier do its work on staying under 80 columns based on the rules we added.
2017-02-15 10:20:37 -05:00
Christopher Chedeau 0c00290dd3 Inline objects & arrays as right part of a boolean expression (#692)
This is a common pattern to write default values.
2017-02-15 09:41:06 -05:00
Christopher Chedeau 9a5090a473 Do not inline new as last argument (#705)
We inline function definitions but we shouldn't inline new expressions,

835befebf5 introduced both call expressions and new expressions. Call expressions have been removed but looks like new haven't.
2017-02-15 09:37:01 -05:00
Brandon Mills eda26398e5 [Docs] Use replaceState API when demo code changes (#710)
In the current demo, every time the code in the left panel is changed,
the new code is stored in the URL hash, which pushes a new history
entry. This effectively "breaks" the back button. This change calls
`history.replaceState` instead, so a single click of the back button
will return the browser to whatever page was open before navigating to
the demo.
2017-02-14 21:02:17 -08:00
Christopher Chedeau 74fb4a43b1 0.17.1 2017-02-14 13:47:46 -08:00
Umidbek Karimov 997de74553 Use `readline` api to manipulate `process.stdout` output. (#687)
* User `readline` api to manipulate `process.stdout` output.

* Revert "prettification".
2017-02-14 13:44:14 -08:00
Alex Rattray f73ae2978e [JSX] Don't add newline following newline (#690) 2017-02-14 13:41:51 -08:00
Christopher Chedeau f3d64b0ffc fix --debug-check 2017-02-13 19:25:28 -08:00
Christopher Chedeau fbba7db6e2 0.17.0 2017-02-13 19:11:05 -08:00
Christopher Chedeau 162ae7b51f [RFC] Introduce prettier-ignore-next (#671)
This was surprisingly easy to write!

Technically, it doesn't ignore the next line but the next expression or block but I'm guessing that people are already used to `// eslint-disable-next-line` so it's going to be an easier learning curve.

Fixes #120
2017-02-13 21:58:50 -05:00
Davy Duperron b661fecd9c Fix comments in return statement argument (#657)
* Extend ReturnStatement case to better handle comments in argument 🎉.

* Update test.

* Add missing space between return and left parenthese.

* Fix current tests and add new tests.

* Do not break one-liner returns.

* Revert specific test.

* Patch from #683.
2017-02-13 18:35:42 -08:00
Christopher Chedeau d09e455a71 Always put a hardline before dangling comment (#675)
In #563 it looked odd that there was no space before `//`, it turns out that we don't automatically go to the new line for dangling comments. I think that we just should no matter what, so this is what this diff does.

Fixes #563
2017-02-13 20:08:58 -05:00
Christopher Chedeau 4dca78dbed Add option for putting > on the last line in jsx (#661)
Feel free to suggest a better name for the option. Otherwise it works great :)

Fixes #654
2017-02-13 12:57:05 -05:00
Davy Duperron 1415040263 [WIP] Fix Flow DeclareTypeAlias (#669)
* Inject source text into printAstToDoc function.

* Add getNodeSource helper function.

* Fix Flow drawback with missing DeclareTypeAlias by checking the node source.

* Add new test.

* Fix getNodeSource helper function.

* Revert text injection.

* Refactor DeclareTypeAlias printing.

* Drop expensive getNodeSource helper function 🗑️.

* Refactor declareTypeAlias case in printer.

* Update tests.

* Implement the same logic for DeclareInterface.

* Update the tests.

* Fix missing semicolons and typo.

* Put Flow specific node detection code into own helper function 🚀.

* Refactor isFlowNodeStartingWithDeclare helper function.

* Simplify isFlowNodeStartingWithDeclare helper function.

* Rename test spec.

* Update tests.
2017-02-13 09:17:20 -08:00
Christopher Chedeau ec6ffbe063 Properly support member chains comments (#668)
When there is a comment right before the first `.`, we want to force break such that the comment is printed on its own line.

Note: this needs to be based on-top of #667 as it always indent the first `.`

Fixes #613
2017-02-13 09:05:18 -08:00
Christopher Chedeau c4b83c7653 Ensure that all comments are printed (#571)
This currently fails for 20 tests. I'm putting this up as a pull request so we can merge it once all the comments are properly printed :)
2017-02-13 09:04:21 -08:00
Davy Duperron 76982ee2f7 Fix Flow union type annotations indentation (#650)
* Add prettier indentation for UnionTypeAnnotation in ObjectTypeAnnotation.

* Update tests accordingly.

* Fix indentation.

* Update a bunch of tests 🚀.

* Switch to a more consistent indentation.

* Fix tests to match new indentation 🚀.
2017-02-13 09:03:56 -08:00
Christopher Chedeau 1a8e97f92b Fix trailing commas with a trailing comment (#664)
The reason why trailing comments on a line work with commas is because of a special `lineSuffix` document that delays printing the content until a \n is printed. But `lineSuffix` only worked for pure string. By making it work with arbitrary documents we can fix trailing commas with trailing comments.

Fixes #538
2017-02-13 10:13:16 -05:00
Christopher Chedeau 287db4a9b6 Stabilize comments inside of ternaries (#666)
Now, all the variations of comments in ternaries are printed the same way.

Fixes #617
2017-02-13 10:12:31 -05:00
Christopher Chedeau 3464092cc4 Soft break the first member of a chain (#667)
Before, we would always concatenate the first `.call()` if the identifier started with a capital letter, but we do want to break if the content of the call doesn't fit in one line.

Fixes #639
2017-02-13 10:07:33 -05:00
Christopher Chedeau abbf0b4c81 Stabilize comments inside of if/then/else before { (#672)
We already have the logic for fixing if/then/else comments but those ones are triggering another codepath.

Fixes #618
2017-02-13 09:55:54 -05:00
Christopher Chedeau 76e599ec97 Avoid unneeded parenthesis for colon with comments (#673)
Because the group was too high up, the comment would be taken into consideration to determine the size and it would break and add parenthesis. Adding a group where we actually want the ifBreak seems to be passing all the existing tests and fixes this edge case.

Fixes #655
2017-02-13 09:55:09 -05:00