Commit Graph

45 Commits (master)

Author SHA1 Message Date
Ika 4af3dd4b07
test: improve snapshots (#5521)
- before
  ```
  ${input}${"~".repeat(printWidth)}
  ${output}
  ```
- after
  ```
  ===options===
  ${options}
  ${" ".repeat(printWidth)}| printWidth
  ====input====
  ${input}
  ===output====
  ${output}
  =============
  ```
2018-11-25 16:21:14 +08:00
Simen Bekkhus 51b7c02e12 Upgrade jest to 22 (#4782)
* chore: upgrade Jest

* chore: update snapshots

* chore: lock down babel dependency using invalid syntax

* 2 args to test.skip

* use jest 22 for now

* Revert "2 args to test.skip"

This reverts commit 691fdc3f99e320f2303958f2b503f7b4c93fa455.

* remove snapshot name from matcher

* fix standalone tests skips
2018-07-03 03:06:29 -03:00
Lucas Duailibe a4da6e6c8e
Inline _ or $ in the root of a method chain (#4621) 2018-06-01 12:51:06 -03:00
Lucas Duailibe a6db391556
Short rule should only apply to the first identifier (#4575) 2018-05-27 21:52:42 -03:00
Lucas Duailibe ea01781d8c
Only break chains with short names if inside ExpressionStatement (#4505) 2018-05-18 21:44:15 -03:00
Adam Pearce 09ac476a32 Nicer line wrapping for d3 (#4285)
* d3 counts as a constructor

* adds test

* Tweak wording

* docs: fix linting

* updates test

* no $ special case

* renames function

* shorter function name

* removes trailing white space
2018-04-24 06:54:45 -04:00
Lucas Duailibe f119d4a90f
Change run_spec to have explicit parser list (#3356) 2017-11-30 03:31:52 -03:00
Lucas Duailibe 979b86944d Consider [0] to be part of the first member group 2017-11-02 14:42:13 -02:00
Christopher Chedeau 777090ca99
Make the factory detection handle multiple elements (#3112)
This was only accounting for a single element in the first group. Now it handles arbitrary elements. Only the last element being capitalized matters.

This fixes one issue in #3107
2017-10-27 09:05:40 -07:00
Lucas Duailibe 878412c680 Break parens for binaries in member expression (#2958)
* Break parens for binaries in member expression

* Add test case

* Update snapshot
2017-10-22 17:29:13 -06:00
Chris Voll 4a6b61aaf3 fix: support sequential CallExpressions in member chains (#2990)
* fix: support sequential CallExpressions in member chains

fixes #2832

* test: add additional test cases for sequential CallExpressions

* test: regenerate method-chain snapshot
2017-10-08 12:12:17 +11:00
Lucas Duailibe 902f7f0339 Use same logic for binary chain 2017-09-10 15:00:52 -06:00
Lucas Duailibe bd78572b19 Break closing paren of ConditionalExpression in member chains 2017-09-10 15:00:52 -06:00
Lucas Duailibe 955a2c1472 Keep conditional expressions in one line on method chains (#2784)
Fixes #2775.

This commit will make conditional expressions to match the behavior of
logical expression in method chains:

```js
(a ? b : c).map()

// if the conditional fits in oneline
(a ? b : c)
  .map()

// if the conditional doesn't fit
(a
  ? b
  : c)
  .map()
```
2017-09-10 08:34:55 -07:00
Lucas Azzola 2e828de76f Print 3 or more chained calls on multiple lines (#2673) 2017-08-27 09:44:44 -07:00
Lucas Azzola dd84559991 Merge computed MemberExpression in member chain (#2670) 2017-08-26 05:35:05 -07:00
Lucas Azzola 77f0c05d2a fix(method-chain): break on non-literal computed member expression, fixes #2075 (#2087) 2017-06-10 07:47:22 -07:00
Christopher Chedeau 924363193b Check if the next group has comments (#2040)
Fixes #1958
Fixes #1959
2017-06-07 15:20:11 -07:00
Christopher Chedeau 3264da9cab Fix leading comment (#1920)
It turns out that leading comment is attached to the CallExpression which is the last one and not the first one if they fit in a single line, so we want to not check that one.

Fixes #1892
2017-06-02 15:50:43 -07:00
Lucas Azzola 2a58e6bc06 test(typescript): enable typescript-verify on most tests (#1781) 2017-05-27 17:57:07 -07:00
Christopher Chedeau 8ad31635b6 Make the comment chain comment detection more robust (#1691)
I kept adding places where comments could be but more use cases kept creeping in. So now this is a holistical approach, we check all the comments that can be between two nodes. This way we should be good to go :)
2017-05-23 16:31:10 -07:00
Christopher Chedeau cf716e5538 Handle trailing comments in member chains (#1686) 2017-05-23 13:58:52 -07:00
Christopher Chedeau f69c5496c6 Break if the first group has an end of line comment (#1681)
This was unstable
2017-05-23 13:14:13 -07:00
Christopher Chedeau c99a877b9f Do not break on [0] (#1441)
In practice, we never want to break on `[0]`. By not doing that, it forces prettier to find a more suitable break placement.

Fixes #1418
2017-05-01 14:41:34 -07:00
Christopher Chedeau 97c662b87b Do not inline member expressions as part of assignments (#1256)
This is a regression from #1036 and #1188.

Fixes #1241
Fixes #1236
2017-04-13 20:09:00 -04:00
Christopher Chedeau 4a4e1817be Do not merge member chain if there's a comment in-between (#1218)
Fixes #1198
2017-04-12 17:26:58 -07:00
Jan Kassens b82220b20f Prittier printing of snapshots (#1190)
This uses a custom snapshot serializer to reduce escaping in snapshot files and
make them easier to read.

Snapshot serializers are documented here:
https://facebook.github.io/jest/docs/configuration.html#snapshotserializers-array-string
2017-04-12 13:41:51 -07:00
Christopher Chedeau 523f64ff14 Add ability to break for top member expression (#1036)
It turns out that the top member expression doesn't go through the member chain logic. Let's give it the ability to break for now.

Fixes #1031
2017-04-11 11:37:35 -07:00
Christopher Chedeau e0eb438e7b Add newline for bracket-less arrow functions that return calls (#927)
I've tried a lot of places where to fix this and this is the only one that gives correct results. This is likely not exhaustive but works for that use case. It's been reported twice in issues and I've seen it happen a few other times so we probably want to get it fixed.

Fixes #922
Fixes #797
2017-04-11 08:50:49 -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
ChristianHersevoort 4f7ae4815b Make it clear what parser was used in each snapshot (#1068) 2017-03-21 14:47:23 -07: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 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
Alex Rattray 24c314da01 Recursively find leading comments inside ReturnStatements (#955) 2017-03-08 17:06:18 -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
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
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 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 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
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
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 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 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 d0bc2991f6 Reimplement MemberExpression printing (#469)
There are currently three issues related to suboptimal rendering of MemberExpression chains. The previous implementation was trying to flatten only a single group at the same time, but it didn't work well because we didn't have the full context to be able to make decisions.

In this implementation, I'm going through the entire chain at the same time and group it into logical units and make decisions based on this. It solves all the problems I can think of and if we need to tweak it in the future, it should be easy.

Fixes #268
Fixes #212
Fixes #21
2017-01-31 12:32:42 -08:00
Christopher Chedeau 3375cfe605 Move tests around (#454)
* new_tests

* move_all_clobbered_tests

* remove all the tests that no longer exist

* re-run flow tests

* Move all the flow tests to tests/flow and prettier to tests/

* Move prettier tests to their own folders

* Add jsfmt files

* run prettier snapshot tests
2017-01-24 14:35:37 -08:00