Commit Graph

743 Commits (08e4e2c04c1b57ace85110c7e5c285848b62df9a)

Author SHA1 Message Date
Christopher Chedeau d6e3815c19 Allow breaking for logical expressions in member chains (#827)
I'm not really sure what a general rule is for those, but starting with LogicalExpressions should be good. Outside of identifiers, function calls and logical expressions, there aren't a lot of things you'd put there in real code anyway.

Fixes #822
2017-02-28 09:31:04 -08:00
Simon Lydell 25340671d3 Update list of related projects (#833) 2017-02-28 09:24:08 -08:00
Christopher Chedeau 61482662cc Migrate class comments to the beginning (#831)
Instead of trying to figure out a complicated way to preserve their correct position, it's easier to just migrate those comments before the class.

Fixes #693
Fixes #694
2017-02-28 11:23:15 -05:00
Christopher Chedeau 2ea1dbcb6a Fix indentation of a merged group (#828)
Printing a merged group indented was actually not the right fix. The right fix was to print them in a single line. It used to have this behavior when I was mutating the first group but now that I don't anymore I need to reproduce this condition.

Fixes #823
2017-02-28 10:55:32 -05:00
Christopher Chedeau c17bcabc0b Preserve new lines for comments after `=` (#830)
The `hasLeadingOwnLineComment` helper is going to be useful for other places where we just used `n.comments` as a proxy for it.

Fixes #660
2017-02-28 10:00:28 -05:00
Christopher Chedeau 4540f473e9 Put short body of arrow functions on the same line (#829)
By adding a group, we can avoid adding a newline if the expression fits in a single line.

Fixes #800
2017-02-27 17:18:43 -05:00
Christopher Chedeau edf2bde590 Fix trailing commas in docs (#825)
I also added support for parser dropdown and stop minifying the bundle so that the flow parser actually works.

Fixes #816
2017-02-27 17:02:41 -05:00
Spencer Dixon a59e2c652f Adds another preset to related projects (#820) 2017-02-27 16:50:38 -05:00
Christopher Chedeau 08b8a5f2e7 Do not put parenthesis around not named default export (#819)
We need to add parenthesis around function expressions if they are named otherwise the name leak, but if the function is not named then it's just superfluous.

The conditional change is due to a bad use of switch case where it would fall through the next one. We don't want parenthesis there.
2017-02-27 16:46:17 -05:00
Christopher Chedeau 443a5d6d66 Properly support `do` (#811)
The code that supported `do` was likely from some recast time and didn't work anymore.
2017-02-27 10:49:08 -05:00
Davy Duperron 04f09ddc80 Fix function call args (#809)
* Implement new heuristic for arguments in printArgumentsList function.

* Remove unwanted modification.

* Add new helper function.

* Update tests according.

* Add new tests for #682, #677, #253.

* Move heuristic in groupLastArg condition.

* Update tests.
2017-02-25 09:56:13 -08:00
Christopher Chedeau 9a447c05ec Correct link for travis 2017-02-24 15:56:13 -08:00
Christopher Chedeau 1b9234a8c4 Update flow to 0.40 (#808)
This fixes the bug with comments swapped between `/*` and `//`

Fixes #755
2017-02-24 15:46:20 -08:00
Davy Duperron b32ace8934 Fix function declaration params comments (#802)
* Add new handleFunctionDeclarationComments function.

* Add dangling comments printing for function params.

* Add new test case.

* Update tests.

* Refactor handleFunctionDeclarationComments to only addDanglingComment when no params.

* Remove unecessary helper function, only attach dangling comments when no params.

* Reset flow tests, no more regression.
2017-02-24 07:26:30 -08:00
James Long cea254857a Eagerly evaluate `ifBreak` when processing template literals (fixes #795) (#798) 2017-02-23 21:21:13 -08:00
Christopher Chedeau 2111f1152c Fix empty options (#803)
```js
// test.js
var prettier = require('./');
prettier.format('a=1');
```

```js
node test.js
// doesn't crash
```
2017-02-23 23:34:53 -05:00
Davy Duperron c8c1875fc8 Fix extra parens for update expressions (#796)
* Remove parens around UpdateExpression when parent is CallExpression.

* Add new test case.
2017-02-23 11:54:06 -08:00
Christopher Chedeau 7c4654b7a3 Run prettier on 0.19.0 (#793) 2017-02-23 09:57:51 -08:00
Christopher Chedeau 71a1ca8907 Update docs to 0.19.0 2017-02-23 09:55:03 -08:00
Christopher Chedeau e0cac2049d 0.19.0 2017-02-23 09:52:55 -08:00
Christopher Chedeau c9d2c17bc7 Fix tests on node 4
Turns out, if you don't put "use strict"; `const` behaves in a crazy way.
2017-02-23 09:47:06 -08:00
Christopher Chedeau 1d02ca7849 [RFC] Add parenthesis around && inside of || (#780)
It seems like precedence for this combination of operators is very unclear to people (myself included) and consistently adding parenthesis there would be good.

Fixes #773
2017-02-23 09:27:00 -08:00
Christopher Chedeau e50aaeccfb Introduce line-suffix-boundary (#750)
The idea is that if you reach the end of the `}` inside of a template literal, we have to flush the trailing comma, otherwise it would generate invalid code. We also need the same special case for JSX.

I don't like adding yet another type of document but it seems like the most elegant way to solve the problem.

Fixes #623
2017-02-23 09:26:26 -08:00
Davy Duperron 260a141dbe [WIP] Fix comments in template literals (#643)
* Add handleTemplateLiteralComment helper function.

* Fix handleTemplateLiteralComment function.

* Extend handleTemplateLiteralComment to deal with trailing comments 🚀.

* Add test.

* Make handle comments function naming more consistent, fix merge conflicts.

* Update tests.

* Add better comment injection in Template Literal.

* Pass options to attach function.

* Update tests to match new implementation.

* Fix let -> var in findExpressionIndexForComment for NodeJS v4.

* Reorder after merge conflicts.

* Drop old tests for dangling arrays.

* Replace redundant conditional by a boolean 🚀.

* Refactor implementation.
2017-02-23 09:23:56 -08:00
Christopher Chedeau ee0e839cb8 Do not put trailing commas for function declaration in es5 mode (#791)
Fixes #789
2017-02-23 09:01:19 -08:00
Brian Ng 543e62cd31 Revert babylon bump (#792) 2017-02-23 09:00:57 -08:00
James Long 5f78e78081 Do not format template literals (#749) 2017-02-23 09:00:29 -08:00
Christopher Chedeau 6b7aa83820 Group [0] at the end of the previous chain instead of beginning of next one (#784)
Fixes #775
2017-02-23 07:34:52 -08:00
Christopher Chedeau 694816517a Do not expand empty catch (#783)
I originally wanted to expand it but I think that it may not be a good decision because it's very common for them to be empty and you want it to take as little space as possible.

I tried to remove all those conditions but I think that there are valid places where we always want to expand like empty if/for/while loops.

Fixes #778
2017-02-23 07:29:05 -08:00
Christopher Chedeau c84027745b Add `this` for Member factory whitelist and remove softline (#782)
In addition to Observable, $ or _, we should also add `this` to the list of things that are likely factory and not objects you want to apply things on directly.

I added a way to make the function call break on its own line when it doesn't fit in one line and indent. But I think that only having the indentation is enough, having the call on its own line feels weird.

Fixes #777
2017-02-23 09:41:44 -05:00
Brian Ng 211deb527e Bump babylon & add test for async func decl (#790)
* Add test for async function declaration

* Bump babylon version
2017-02-23 09:32:20 -05:00
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