Commit Graph

421 Commits (dc93bdc983b9caa43aaee7efdba792f5d304dbc1)

Author SHA1 Message Date
Karl O'Keeffe bfd5fa4515 Add doc debug printing for line-suffix-boundary (#1158) 2017-04-07 14:15:35 -07:00
Christopher Chedeau 41dee70795 Allow to break after = for strings (#1142)
This is not a general fix but it solves some issues that people are seeing where prettier goes > 80 columns.

Fixes #1141
Also fixes part of #1110
2017-04-07 10:51:02 -07:00
Christopher Chedeau f69b26081f Stabilize VariableDeclarator comments (#1130)
Fixes #932
2017-04-07 07:57:44 -07:00
Rafael Hengles 170e4d558a Refactored option to indent with tabs (#1026)
Refactored option to indent with tabs
2017-04-06 22:49:37 -04:00
Lucas Duailibe 8e9fb43841 Fix trailing comment on switch case (#1136)
* Fix trailing comment on switch case

* Use unshift and add another test case
2017-04-05 16:27:14 -07:00
Alex Rattray d0666c3da4 Fix leading comment inside returned SequenceExpression (#1133) 2017-04-05 13:41:35 -07:00
Christopher Chedeau bab9b5b93a Remove trailing spaces 2017-04-05 13:28:02 -07:00
Joseph Savona fe5de43cd7 Fix printing of Flow type number literals (#1128) (#1132) 2017-04-05 13:22:23 -07:00
Lucas Duailibe 69879e23bc Print comment after key (#1131) 2017-04-05 13:10:10 -07:00
Christopher Chedeau 926f9c4dfb Handle unconventional newlines (#1050)
The `\r` test has had to be deleted because jest doesn't properly save and parse the snapshot back.

Fixes #883
2017-04-05 10:54:39 -07:00
Eric Clemmons 61ad2f1d34 "// prettier-ignore" position within comments doesn't matter (#1126)
* // prettier-ignore can be within any part of the comment block

* Add test for // prettier-ignore being anywhere within comments
2017-04-05 10:51:20 -07:00
Eric Clemmons def91efd16 Support "// prettier-ignore" in comment blocks (#1125)
* // prettier-ignore has to be last comment

* Add test for #1109
2017-04-05 10:08:08 -07:00
Christopher Chedeau 1578e180f4 Add support for flow type spread in .43 and babylon beta8 (#1064)
Fixes https://twitter.com/ryyppy/status/844116626467438592
2017-04-04 14:52:16 -07:00
Christopher Chedeau 6c9cb86a6d Ability for interface to break (#1060)
We break on `class` before `extends` but didn't for `interface`. Now we do in the same way. Also TIL that `interface` was an actual keyword in JavaScript :P
2017-04-04 14:25:17 -07:00
Simon Lydell 96b0a33cff Fix printing of exact object flow type annotations (#1114)
Fixes #1089.
2017-04-03 10:24:36 -07:00
Christopher Chedeau 60816af4ce Add support for currying (#1066)
If you write your code in a functional way where you have an arrow function for each argument, it looks better for them to be inline. I can't imagine any case where it would be used in a different way if we limit to a single argument.

Fixes #1065
2017-03-22 13:33:28 -07:00
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
Simon Lydell e7312ad7b2 Remove mutation in `printBinaryishExpressions` (#1067) 2017-03-21 14:49:08 -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
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 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
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
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
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
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
David Hong 411f0fb6e7 Print line/mixed comments on new lines inside JSXEmptyExpression (#985) 2017-03-10 18:23:11 -08:00