Commit Graph

743 Commits (08e4e2c04c1b57ace85110c7e5c285848b62df9a)

Author SHA1 Message Date
Christopher Chedeau dd792a2b22 Fix tests 2017-03-22 10:20:42 -07:00
Christopher Chedeau dc0fbf7822 Special logic for flow intersection (#1018)
We started using the same logic for union and intersection but then added a special case for `a & {}`. It turns out that they should be handled completely differently in practice.

The heuristic i'm using is if you go from object to non-object or vis-versa, then inline, otherwise go to the next line and indent (like &&).

Fixes #864
Fixes #1017
2017-03-22 10:01:34 -07:00
Christopher Chedeau 04eba07aab Hug on single object destructuring function (#1022)
This is very common for stateful react functional components. It also matches last object expansion. I think that we should only do that for a single argument in function definitions though, unlike the last for function calls.

Fixes #1019
2017-03-22 09:58:33 -07:00
Brian Ng d8a64dec6c Remove a few node types (#1075)
* Remove NumericLiteralTypeAnnotation

* Remove ExistentialTypeParam
2017-03-22 09:51:36 -07:00
Brian Ng 42910424a1 Fix parsing flow variance on babylon 7 (#1069)
* Enable babylon on variance tests

* Fix parsing flow variance in babylon 7
2017-03-22 09:37:26 -07:00
Davy Duperron dfd42d8306 Fix class method comments (#1074)
* Add new helper function for printing ClassBody comments.

* Update tests.
2017-03-22 09:26:27 -07:00
Brian Ng 41977c293e Add support for ForOfStatement with await flag (#1073)
* Enable babylon on flow async_iteration tests

* Add support for ForOfStatement with await flag
2017-03-22 09:23:57 -07:00
Christopher Chedeau c3199359b0 Revert "Improve snapshot naming" (#1070)
* Revert "Remove mutation in `printBinaryishExpressions` (#1067)"

This reverts commit e7312ad7b2.

* Revert "Make it clear what parser was used in each snapshot (#1068)"

This reverts commit 4f7ae4815b.
2017-03-21 17:38:28 -07:00
Simon Lydell e7312ad7b2 Remove mutation in `printBinaryishExpressions` (#1067) 2017-03-21 14:49:08 -07:00
ChristianHersevoort 4f7ae4815b Make it clear what parser was used in each snapshot (#1068) 2017-03-21 14:47:23 -07:00
Christopher Chedeau ce6e897950 [RFC] Fix comment location for binary expressions (#1043)
The root cause is that we're calling `printComments` with an empty string, meaning that the leading/trailing comments are not correctly inserted at the right location.

So, the way to fix it is to call `p => concat(parts)` but because we're mutating the array in place, it doesn't work. We need to mutate it and create a copy. But, the root call is actually checking the shape of the parts array which our code is now breaking...

```js
          // Don't include the initial expression in the indentation
          // level. The first item is guaranteed to be the first
          // left-most expression.
          parts.length > 0 ? parts[0] : "",
```

The consequence is that binary expressions are no longer indented if the first expression has a comment (but now it places the comment properly!), which seems like a good trade-off.

I'm not sure if we should merge this one or instead refactor this code such that it doesn't rely on mutation and looking at the shape of the printed tree. `printMemberChain` is a good thing to reference for inspiration.

Fixes #946
2017-03-21 12:13:13 -07:00
Erick Romero 24f9cc3a71 Vim readme (#1058)
* Moved Vim info to its own editor folder, started drafting new README

* Finished first draft, ready for PR

* Testing Readme layout

* Removed vim folder
2017-03-20 22:12:10 -07:00
Davy Duperron 389d9d0fad Fix unstable comments in assignment pattern (#1055)
* Add handleAssignmentPatternComments print function.

* Add new test cases.
2017-03-20 18:49:42 -07:00
Christopher Chedeau 553966345a Fix comment sorting location (#1038)
Right now it's only doing one test for begin/end, but in the issue #1037, we have two nodes that have the same start but different end. The current implementation incorrectly sorts them and the identifier ends up being before the container and therefore the comment search doesn't recurse into it.

Fixes #1037
2017-03-20 10:21:54 -07:00
Christopher Chedeau e88e76cf92 Do not use more than one file descriptor at a time (#1048)
@cpojer made a great suggestion to use `fs.readFileSync` instead of the async version. prettier is CPU-bound and if you want parallelism you can spin up many instances of prettier.

Fixes #994
2017-03-20 10:14:33 -07:00
Christopher Chedeau 569791a57a Update babylon to 7.0.0-beta.4 (#1047)
Fixes #700
2017-03-20 12:46:31 -04:00
Christopher Chedeau b012f7531e Fix comments inside of ObjectPattern (#1045)
ast-types was missing a type, I sent a PR on ast-type ( https://github.com/benjamn/ast-types/pull/211 ) which was merged and released (thanks @benjamn for being super quick!). So I'm upgrading ast-types and add the test in this PR.

Fixes #1007
2017-03-20 12:42:07 -04:00
Christopher Chedeau a502bf9f45 Add ability for flow generics to break (#1041)
While looking at an instability on the React codebase ( ba1299acc2 (diff-2550aa3d377452ae29361f5e53c51c10) ), I realized that we don't let them break which makes the code look weird.

So I added the ability for them to break :)
2017-03-20 12:35:30 -04:00
Christopher Chedeau 82d6e0b4ab Unrestrict flow union comments check (#1040)
I was being very careful by checking all the surrounding types but it actually turns out we want this behavior all the time.

Fixes #931
2017-03-20 12:33:42 -04:00
Christopher Chedeau a9185cb30e Stabilize comment on member chain with three elements (#1039)
We already had a special case for it for a group of 2 elements but now that we are also going in this codepath for 3 if we merge, then we need to do the same here.

Fixes #930
2017-03-20 12:32:49 -04:00
Christopher Chedeau f656db7728 update-yarn-lock 2017-03-19 08:54:17 -07:00
Rasmus Eneman e41ed4955d [WIP] Add some typescript tests (#1033)
* Add some typescript tests

* fix: Remove extraneous colon in type parameter constraint

* style: Add missing newline at EOF in TS tests

* feat: Pretty print typescript object type annotations

* feat: Pretty print TSFunctionType

* fix: Type annotations was missing on class properties

* Add a new batch of tests

* Bump typescript-eslint-parser

* Add a new batch of tests and fix a syntax error in previous

* Bump typescript-eslint-parser
2017-03-19 08:06:52 -07:00
Christopher Chedeau c749ddd508 Add parens around return for binaryish expressions (#870)
It looks better when the first element is aligned with the rest and this is consistent with the way we render `if` test.

Fixes #866
2017-03-18 19:35:09 -07:00
Royce Townsend 9eb389b9f4 Group first arg for inline functions (#947)
* Group first arg for inline functions

* Group first arg. Unless there are comments.

* Group first arg. Allow second arg to be empty object/array.

This implementation has a side effect of disallowing empty objects/arrays in the should group last arg heuristic.
2017-03-18 11:20:07 -07:00
James Long eeae443b43 Separate `if` and `else` groups (fixes #616) (#1032) 2017-03-17 14:02:35 -07:00
Christopher Chedeau dc52a71923 Inline class expressions for bracket-less arrow functions (#1023)
I could go either way but it doesn't seem a big deal to inline them. I don't expect it to be very common anyway

Fixes #990
2017-03-17 14:01:17 -04:00
Christopher Chedeau 328a5be284 Hide typescript parser from static analysis (#1024)
Adding typescript broke the docs build and is causing issues with create-react-app bundler. Let's use a small hack to hide it from static analysis, but still works in node.

Fixes #986
2017-03-17 14:00:43 -04:00
Christopher Chedeau 16ed595086 Preserve comment position for last arg or method (#1025)
In #856, it handled a bunch of cases but missed class methods

Fixes #905
2017-03-17 14:00:01 -04:00
Christopher Chedeau 35547993d4 Add breakParent support for willBreak (#674)
* Add breakParent support for willBreak

Fixes #615

* Update snapshots from previous commit
2017-03-17 13:51:22 -04:00
Davy Duperron 748dcbf70d Fix import declaration comments (#1030)
* Add handleImportDeclarationComments function.

* Fix indent.

* Update test cases accordingly.

* Implement better heuristic for adding comments.

* Make the test case more exhaustive.
2017-03-17 08:11:43 -07:00
Davy Duperron dde8463ad9 Fix additional empty line switch case comment (#936)
* Refactor condition in printStatementSequence, add new helper function.

* Add new test cases.

* Move logic in SwitchCase case.

* Revert unrelated changes, remove unecessary variables.

* Use util.getLast helper function.

* Move variables out of the loop.

* Simplify code.

* Fix mapping with mutated path.
2017-03-17 08:08:36 -07:00
Hampus Ohlsson 76e26f08a0 Fix dot notation in decorators (#1029) 2017-03-16 13:27:20 -07:00
Davy Duperron 440ddc2e1a Remove unused code. (#1028) 2017-03-16 13:26:44 -07:00
Adam Stankiewicz 60b6d6fc56 Mention prettier-standard package (#1010) 2017-03-16 10:33:23 -07:00
Davy Duperron 915967b974 No parenthesis for Flow shorthand with one arg (#972)
* Implement checking for not printing the parens in this case.

* Add test case.

* Remove parent type checking.

* Fix test accordingly.

* Refactor to a better heuristic.

* Add new test cases.

* Fix implementation.

* Fix unnecessary function call.

* Add new test cases 🚀.

* Use isObjectTypePropertyAFunction and create isTypeAnnotationAFunction.

* Add missing space.

* Add new test cases.
2017-03-16 10:32:59 -07:00
Walter Breakell a9c84e536a Enable yarn caching in .travis.yml (#1016) 2017-03-15 20:23:03 -07:00
Christopher Chedeau 3a80345e0c re-run snapshot tests 2017-03-15 18:54:34 -07:00
Brian Ng b8a7e5166b Add parens for ConditionalExpression inside JSXSpreadAttribute (#1015) 2017-03-15 18:52:31 -07:00
Davy Duperron c82bb4e003 Fix exports (#998)
* Fix printExportDeclaration function.

* Update tests accordingly.

* Remove commented line.

* Run npm test -- -u to update and fix tests.
2017-03-15 16:29:15 -07:00
Christopher Chedeau 7105f972b4 [RFC] Add softline to assignment of binary expressions (#871)
Printing the first line of a binary expression next to the `=` leads to weird cases where the first expression is parenthesised and doens't read well with chained conditionals as they don't align well. This makes it behave the same was as `if` tests.

Fixes #863
2017-03-15 09:45:40 -07:00
Dan Harper 332babe77d Fix single optional arrow param printing (#1002) 2017-03-15 09:38:13 -07:00
Brian Ng a2b560887c Add support for breaks in TupleTypeAnnotation (#1003) 2017-03-15 09:35:22 -07:00
Sean Grove 2b93bf4f30 Use correct print-width argument (#1006) 2017-03-15 09:30:58 -07:00
Christopher Chedeau 36a1d12f47 Do not respect newlines for object destructuring pattern (#981)
This was intended for object expressions. I tried to remove it for ObjectTypeAnnotation but it changes a ton of stuff as it's used all over the place in many different contexts. We should clean it up but in a later PR :)

Fixes part of #975
2017-03-14 18:36:35 -07:00
Simen Bekkhus 0fc8584827 Update repo links (#993) 2017-03-13 14:39:54 -07:00
David Hong 411f0fb6e7 Print line/mixed comments on new lines inside JSXEmptyExpression (#985) 2017-03-10 18:23:11 -08:00
Christopher Chedeau 0aa3617689 Fix for of/in comment on its own line around in/of (#901)
This is pretty edge case-y so i'm taking the easy way out.

Fixes #886
2017-03-09 11:10:55 -08:00
Brian Ng d034564481 Remove parens from chained assignments (#967) 2017-03-09 09:17:16 -08:00
Christopher Chedeau 344401c038 0.22.0 2017-03-09 09:15:40 -08:00
Christopher Chedeau d39facc022 Only allow same-line arrow-less body for explicit nodes (#966)
In practice, trying to allow calls to be inlined is causing a lot of code to look very weird and unstable as seen by the four issues this is fixing. It also requires us to add a conditional group and do hackery around it.

Fixes #959
Fixes #760
Fixes #615
Fixes #625
2017-03-09 09:08:12 -08:00