Commit Graph

626 Commits (a502bf9f4552b726ebb0c6b5436b915556b5f653)

Author SHA1 Message Date
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
Christopher Chedeau 9ef8c709bb fix_tests 2017-03-09 08:59:23 -08:00
Brian Ng b8bdb6c243 Inline BinaryExpressions inside JSXExpression (#965) 2017-03-09 07:59:53 -08:00
Christopher Chedeau 35bd29be2c Stabilize comment after object label (#958)
This is the largest firing unstability on the Facebook codebase.

Fixes #906
2017-03-09 07:55:35 -08:00
Christopher Chedeau ee1717e7b7 Make comments around empty parenthesis be inside (#957)
The logic was already implemented in #802 but for a single case. I just added all the cases added in the awesome @umidbekkarimov

Fixes #956
2017-03-09 07:55:18 -08:00
Christopher Chedeau c2aacae54c Fix `in` inside of a for in a nested way (#954)
Fixes #907
2017-03-08 17:09:37 -08:00
Alex Rattray 24c314da01 Recursively find leading comments inside ReturnStatements (#955) 2017-03-08 17:06:18 -08:00
Karl O'Keeffe 68a39454af Do not break long `describe` calls (#953)
This ensures that `describe` calls in test suites are whitelisted in the same way as `it` and `test` and never break across lines.
2017-03-08 13:24:28 -08:00
James Henry 72456bf06f [WIP] TypeScript Parser (#915)
* WIP immediate feedback

* typescript parser is drop-in replacement for flow parser

* Add new TypeScript Parser snapshots where drop-in replacement possible

* Snapshot updates after rebasing

* Remove unnecessary stripping of properties on TypeScript parser AST

* Remove annotated issues

* Move TS dependencies to dev for now
2017-03-08 13:18:13 -08:00
Kevin Gibbons dc2fa2cdd0 Fix #951: properly parenthesize ** expressions (#952) 2017-03-08 13:11:53 -08:00
Bill Mill f5ede513eb update the README to add a pre-commit hook (#944)
* update the README to add a pre-commit hook

* remove comments

* better wording

* better quoting

* consistent prettier binary

* move the tr and fix the quoting

* fix quotes one last time
2017-03-07 19:55:43 -08:00
Kevin Gibbons 7443f4cbd6 Parenthesize function expressions in expression position (#941)
* refactor needsParens for function expressions

* snapshots

* comment
2017-03-07 18:53:42 -08:00
Alex Rattray 50602aecbb [JSX] Break if opening element breaks (#942) 2017-03-07 17:19:05 -08:00
Kevin Gibbons 06987e9948 cleanup needsParens (#935) 2017-03-07 14:43:05 -08:00
Davy Duperron 1b6ddf9a7f Fix binary op as body in arrow expression (#921)
* Implement new logic for wrapping binary op in arrowFunctionExpression.

* Add new test cases.

* Reuse new helper function in order to fix #917.

* Add new test case.

* Extend heuristic to dive deeper into mixed types.

* Add new test.

* Enhance logic to cover more cases.

* Add new test cases.

* Disable Flow as it gets BindExpression as an unexpected token.

* Simplify getCombinedDeepest function.

* Add missing case.

* Extract all conditions in switch cases to one top level condition.

* Refactor implementation to make it cleaner and also handle ExpressionStatement.

* Update related test cases.

* Add new test case.

* Make condition less expensive.

* Clean up unecessary conditions, simplify condition involving startsWithOpenCurlyBrace.

* Update and add new test cases for better coverage.

* Remove unecessary condition, refactor canBeFirstInStatement to drop some useless parens.

* Update test cases accordingly 🚀.
2017-03-07 13:24:47 -08:00
Patrick Camacho 513b57db3a Update README.md (#928)
typo fix
2017-03-07 11:38:58 -08:00
Davy Duperron 008ac1c479 Fix files with comments only (#813)
* Add new handleOnlyComments function.

* Update tests.

* Update test as the printer forces a trailing newline if there were any contents.

* Implement a different heuristic.

* Update tests.

* Add directives checking in handleOnlyComments function.

* Add directives checking in handleOnlyComments function (amend to retrigger CI).

* Remove duplicate.
2017-03-07 11:02:45 -08:00
Andrey Okonetchnikov 3045829a61 Update lint-staged docs to use husky for less config. (#923) 2017-03-07 09:53:00 -08:00