Commit Graph

478 Commits (f73ae2978e0a0940483b96fcc53e17d402653d10)

Author SHA1 Message Date
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
Christopher Chedeau 1fed39ae30 Print line-suffix in --debug-print-doc (#676)
I was trying to debug #620 and got confused that it didn't show `//comment1`. Turns out we just fail silently if we can't print a node type. I added support for `line-suffix` and throw if we encounter a node type that we can't print.
2017-02-13 09:46:44 -05:00
Christopher Chedeau c5bfdae5d8 Fix dangling comments for arrays (#665)
It was missing a softline. I copy and pasted the dangling handling for objects.

Fixes #624
2017-02-12 23:09:39 -05:00
Ilya Panasenko 8a27e121ed fix typo in JetBrains External Tool config readme (#679) 2017-02-12 17:45:49 -08:00
Christopher Chedeau 6632b95497 Preserve blank lines inside of objects (#606)
We already preserve blank lines inside of classes but not objects. It's still very common to have objects that represent classes (React.createClass) and having the same behavior there seems like a good idea. It does make the snapshot tests look better!

Fixes #554
2017-02-09 11:08:58 -05:00
Christopher Chedeau 0287cadc62 Run prettier 0.16.0 on the codebase (#631) 2017-02-09 10:44:56 -05:00
Christopher Chedeau 4a00bc33a5 Put short elements at right of single binary expression on same line (#605)
I've been trying to come up with a heuristic to stop putting small elements on a new line and I just realized that all the cases I found out only involved a single binary expression. If there's only a single operation, we can just put them on the same line (if it fits) and it's not going to look weird.

We do the same thing for MemberExpression where we only break if there are more than one ".".

Fixes #583
Fixes #503
2017-02-09 10:44:03 -05:00
Christopher Chedeau cda7650e27 Do not indent binary expressions inside of if (#604)
* Do not indent binary expressions inside of if

The reason why the indent has been added is to support the

```js
var x = a ||
  b;
```

use case where we need a level of indentation. But inside of a `if` it just looks strange

```js
if (
  a ||
    b
) {
```

because the parent already indented the first line.

Fixes #567

* Tweak logic to make more explicit
2017-02-09 10:36:05 -05:00
Umidbek Karimov 97fd8a8d81 Log filename with [update] or [ignore] flags during `--write` process. (#584)
* Make `--write` logs more informative.

* Add format duration to logs.

* Use colors instead of [ignore] and [update] labels.

* Remove `colors` dependency.

* Use `chalk` to colorize logs.

* Print filename before `format` and add duration info later.

* Print filename before read error.
2017-02-07 14:03:48 -05:00
Alex Rattray 91d4f400a4 [JSX] jsx-whitespace breaks with parent (fixes #622) (#626) 2017-02-07 13:47:34 -05:00
Nathan Friedly 79d537a3b0 test on current release of node.js (#595) 2017-02-07 12:46:39 -05:00
Christopher Chedeau a051545fcb Preserve empty line before last comment (#594)
We want to preserve an empty line before the last comment. It is added as a trailing comment of the node and adding the same logic to detect if the next line is empty is working.

Fixes #566
2017-02-07 12:41:49 -05:00
James Long 05637a73d3 Update snapshots 2017-02-07 12:15:36 -05:00
James Long 2ff937acdd Fix formatting in readme 2017-02-07 10:42:54 -05:00
James Long a3a6834a05 Expand vim instructions 2017-02-07 10:42:18 -05:00
Christopher Chedeau 6a05a55852 Remove last trailing line for directives-only files (#609)
* Remove last trailing line for directives-only files

There are two hardlines that are added that do not need to.

- The first one is when there's an empty line afterwards, we want to remove it. The solution I opted for to fix this one is to trimRight the originalText so that globally it's never going to return yes for the isNextLineEmpty.
- The second one is at the end of Program, but we already printed it inside of the directive itself, so we can just add a condition to make sure it's only printed when there's a body or a comment, but not a directive.

Fixes #527

* Add comment
2017-02-07 10:39:04 -05:00
Christopher Chedeau 4df5250f74 Add --debug-check cli option (#627)
This let's you run `pp(x) === pp(pp(x))` across an entire codebase quickly. I think it's small enough that we can merge it in to master while we are nailing down all the issues.

You can see the output in #610
2017-02-07 10:04:44 -05:00
Alex Rattray ee593bb645 [JSX] Fix spurious newline (fixes #614) (#628) 2017-02-07 09:58:25 -05:00
Christopher Chedeau 98d04d8c70 0.16.0 2017-02-05 18:28:20 -08:00
Christopher Chedeau b42e865c61 Print dangling on ast on all the paths 2017-02-04 18:53:47 -08:00
Christopher Chedeau 7abd6f5f9b Fix single indented JSX comment (#596)
This one was pretty annoying to figure out but now it's working. All the crazy comments I could throw at jsx seems to be working fine now :)

Fixes #543
2017-02-04 21:37:18 -05:00
Christopher Chedeau 153bf4cad9 Remove first line special case (#597)
If you removed it before #561, it would trigger an exception in the globalPreceding branch. But now that we don't have this hack anymore, it works fine.

Fixes #543
2017-02-04 21:36:48 -05:00
Christopher Chedeau df831d7b59 Fix files with only comments on the flow parser (#598)
Babylon has a two top level nodes: File and Program whereas flow just has Program. This causes two things two happen that prevents comments from being displayed:

1) Because there's a single node, none of following/preceding/enclosing exist. We ran into a TOOD case that we now need to fill. We just need to attach comments to the only node we have: the ast.

2) Both the raw comments and the computed comments are set on the `.comments` field of the object, however, it is being reset after calling `attach`, so we lose the computed comments :( The fix is to use a local variable and delete the comments before calling `attach`.
2017-02-04 21:36:29 -05:00
Christopher Chedeau c07329b4ef Do not attach comments to EmptyStatement (#599)
Since we don't print EmptyStatement, we don't want to attach comments to them. I've tried actually printing the EmptyStatement but it messes up a ton of other things.
2017-02-04 21:32:51 -05:00
Christopher Chedeau 77bf64c6b1 Print CallExpression comments inside of memberChain (#600)
I made sure that MemberExpressions where printed correctly but didn't do the same for CallExpression. Now it is! It is a bit less straightforward because the comments for the root CallExpression have already been printed, so we need to extract the first call out.

(This is the last place where we drop comments on the test suite, we can start enabling throwing when comments are dropped!)
2017-02-04 21:31:54 -05:00
Christopher Chedeau fb9629ca7f Better support try/catch comments (#607)
Uses the same technique as for if/then/else. Added a helper function to make it easier.

Fixes #601
2017-02-04 21:25:29 -05:00
Christopher Chedeau 91087e1e84 Use arrow function when inputted that way for flow objects (#608)
Omg, after 10 unsuccessful tries, I finally managed to get it working! The deciding factor was a trick by @mroch <3

Fixes #310
2017-02-04 21:23:37 -05:00
Davy Duperron 8c66e44db1 Fix use strict as expression statement (#602)
* Add parentheses if node is StringLiteral surrounded by ExpressionStatement :tools:.

* Add new test.

* Update tests to run against Babylon, plus no regression case.

* Split actual test and no regression test in two files.

* Disable Flow till facebook/flow#3234 is merged.
2017-02-04 13:16:24 -08:00
Christopher Chedeau 6b74de3716 Remove test.js and put it back in the gitignore 2017-02-03 14:37:13 -08:00
Christopher Chedeau 3b66af3d60 Remove the concept of globalPrecedingNode (#561)
The original motivation for this change is trying to fix #560 where the comment was attached to the JSXText node instead of the JSXExpressionContainer because it used the globalPrecedingNode. In general, I don't think that it is very safe to attach a comment to a random node just because it happened to be before.

I tried to delete the globalPrecedingNode codepath and I think that it actually improves the results. I'll add inline comments in the pull request to explain the various changes.

Fixes #560
2017-02-03 13:56:06 -08:00
Christopher Chedeau 0924e7f3dc Break long imports (#590)
Fixes #576
2017-02-03 16:19:14 -05:00
Christopher Chedeau e623668183 Make all the member expressions but the last one part of the first group (#589)
Fixes #587
2017-02-03 16:18:54 -05:00
Christopher Chedeau 57ab92ed33 Support dangling comments in ClassBody (#570)
Comments were dropped there
2017-02-03 16:16:32 -05:00
Christopher Chedeau 4bd194e2ce Use breakParent inside of last arrow expansion (#559)
Fixes #549
Fixes #553
2017-02-03 16:15:21 -05:00
Christopher Chedeau b2a8f2de56 Add parenthesis around single argument arrow if comments (#573)
Fixes #568
2017-02-03 16:14:40 -05:00