Commit Graph

459 Commits (8f9bb3a22374ba4f6efe0d425a6cbe10e5dd4067)

Author SHA1 Message Date
Christopher Chedeau 8f9bb3a223 Break inline object first in function arguments (#1453)
This is getting subtle where the groups need to be in a precise position but that works :)

Fixes #1409
2017-05-01 14:49:03 -07:00
Christopher Chedeau 54b8cac0a7 Reorder flow object props (#1451)
This is very sad, but we need to do this to get the correct result :(

Fixes #1448
2017-05-01 14:42:52 -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 acfb14f577 Don't break on empty arrays and objects (#1440)
We never want to break on those at it looks very weird. The reason why I didn't add this yet is because whenever it triggered in the past, the root cause was something else and it helped identify things to fix. But now the remaining ones I'm seeing are no longer underlying issues and they're just about this breaking unnecessarily, so we should just fix it.
2017-05-01 14:41:18 -07:00
Christopher Chedeau bafd72418e Don't break for unparenthesised single argument flow function (#1452)
This has been reported internally. It looks --very-- weird to have it indented the way it was.
2017-05-01 14:39:46 -07:00
Christopher Chedeau a335c26253 Add space around `=` for flow generics default arguments (#1476)
We have a space for function arguments and it looks weird without.
2017-05-01 14:39:15 -07:00
Christopher Chedeau 4b7d265000 Fix windows line ending on template literals (#1439)
Fixes #1432
2017-05-01 14:39:03 -07:00
Christopher Chedeau e39209386c Only add parenthesis on ternaries inside of arrow functions if doesn't break (#1450)
This was added in order to follow some eslint rule but it's only confusing when it doesn't break, when it breaks the indentation makes it clear what is happening and you don't need parenthesis.

Fixes #1379
2017-05-01 14:32:52 -07:00
Christopher Chedeau 93cad97b14 Preserve inline comment as last argument (#1390)
We already had the logic but only applied it for comments on their own line, we should also do it if they are inline.

Fixes #1380
2017-05-01 14:29:03 -07:00
Christopher Chedeau 314e96322c Add parenthesis for unusual nested ternaries (#1386)
All of the discussions around ternaries are for the form

```js
cond1 ? elem1_if : cond2 ? elem2_if : elem_else
```

but some of them are for the form

```js
cond1 ? cond2 ? elem2_if : elem2_else : elem1_else
```

which is more rare and would be good to call out by adding parenthesis.

```js
cond1 ? (cond2 ? elem2_if : elem2_else) : elem1_else
```

Note that we only want parenthesis if it's written inline, otherwise the indentation is good enough to understand the flow:

```js
cond1
  ? cond2 ? elem2_if : elem2_else
  : elem1_else
```
2017-05-01 14:28:36 -07:00
Christopher Chedeau 13f05fb763 Proper indentation for template literals (#1385)
Right now, expressions inside of template literals are have the level of indentation of the start of the template literal. But oftentimes, expressions are nested inside of template literals and therefore the expression should have this level of nesting.

The heuristic i'm using to decide when to use the template literal nesting is if it's not the first line and if there isn't another expression before on the same line.
2017-05-01 14:28:11 -07:00
Christopher Chedeau c521406385 [RFC] Do not indent calls with a single template literal argument (#873)
I'm not sure that this is a good idea. A current workaround is to remove the parenthesis.

Fixes #786
2017-05-01 14:27:00 -07:00
Danny Arnold 5ee0385d79 [WIP] add TSNamespaceExportDeclaration (#1459)
* add TSNamespaceExportDeclaration

* extract ast-types/fork

* add TSEnumDeclaration and TSEnumMember

* add TSImportEqualsDeclaration and TSExternalModuleReference

* add TSInterfaceDeclaration and type annotation to TSMethodSignature

* add TSModuleDeclaration, TSDeclareKeyword, TSModuleBlock and fix TSNamespaceExportDeclaration

* remove workaround
2017-05-01 09:25:49 -07:00
Danny Arnold bff2d48aa8 update typescript snapshots to account for #1464 (#1470) 2017-05-01 07:22:05 -07:00
Alessandro Di Felice bfe3161762 Break class expression returned by arrow call (#1464) 2017-04-30 17:49:31 -07:00
Lucas Azzola 7d1e24ea7d Add supertype tests and add TSAbstractClassProperty (#1467)
* feat(typescript): add supertype tests and add TSAbstractClassProperty

* chore(typescript): bump parser version

* fix(flow): allow both variance and accessibility mods
2017-04-30 17:41:19 -07:00
Christopher Chedeau 3161bd0787 Upgrade flow parser to 0.45 (#1447)
This fixes all the unicode issues and spacing between elements in array.

Fixes #1336
Fixes #1427
Fixes #770
2017-04-27 14:59:18 -07:00
Kevin Gibbons e75d3a4af3 Require '(a || b).c++' to have a preceding ; in no-semi style (#1443) 2017-04-27 14:00:53 -07:00
Kevin Gibbons 10a5f68a12 Require '::a.b' to have a preceding ; in no-semi style (#1442) 2017-04-27 14:00:04 -07:00
Brian Ng b2a092bd17 Allow flow declarations to break on StringLiteralTypeAnnotations (#1437)
* Allow flow declarations to break on StringLiteralTypeAnnotations

* canBreak
2017-04-27 11:21:42 -07:00
Lucas Azzola 7a02e9ad27 feat(typescript): add delcare modifier support for vars, classes and functions (#1436) 2017-04-27 09:37:42 -07:00
Brian Ng 9c826c2ed5 Inline nullable in flow generics (#1426) 2017-04-26 09:27:06 -07:00
Lucas Azzola fff743024c Add TSParameterProperty, TSAbstractClassDeclaration and TSAbstractMethodDefnition (#1410)
* feat(typescript): implement TSParameterProperty

* test(typescript): add TypeScript's classes/constructorDeclarations/constructorParameters tests

* feat(typescript): implement TSAbstractClassDeclaration and TSAbstractMethodDefinition

* test(typescript): add TypeScript's classes/classDeclarations/classAbstractKeyword tests

* fix(build): use join instead of spread operator

* fix(typescript): fix semicolon handling

* fix(typescript): handle accessibility modfiers in TSAbstractMethodDefinition

* test(typescript): remove invalid test results

* test(typescript): remove unimplemented abstract properties from tests

* test(typescript): add snapshots for abstract keyword newline behavior
2017-04-26 09:25:58 -07:00
Danny Arnold 0a7e462ad7 add TSMethodSignature (#1416) 2017-04-25 14:15:33 -07:00
Danny Arnold 90762bb111 fix VariableDeclarator not printing type parameters (#1415) 2017-04-25 14:08:30 -07:00
Davy Duperron c609a5415a [experimental] Add linting step in test pipeline (#1172)
* Add eslint as dev dep, reorder scripts.

* Add tests & docs to eslintignore.

* Add eslintcache to gitignore.

* Update yarn lock file 😽.

* Add linting step in the test pipeline.

* Add a set of really basic rules for linting.

* Fix linting 🚀.

* No need for .jsx files to be linted...

* Reorder rules alphabetically.

* Refine rules: drop styling ones, only keep what provides dead code elimination.

* Add no-console rule to be consistent along with the no-debugger one.

* Remove empty line.

* Add eslint-disable-next-line no-console where console log/warn/error are allowed.

* Drop no-console rule.

* Remove eslint-disable-next-line no-console comments.

* Remove linting step in Travis CI.

* Fix linting after merging current master.

* Run `npm test -- -u` after noticing one test was out of sync.

* Drop eslint references from previous implementation.

* Revert yarn lock file.

* Revert scripts ordering.

* Fix incorrect yarn lock file.
2017-04-25 09:48:56 -07:00
Christopher Chedeau a7319dbbbb Fix optional flow parenthesis (#1357)
In #1251, we now have a proper whitelist of all the types that should have parenthesis. Turns out, it included NullableTypeAnnotation which is `?a`. For `?a => void` this wasn't needed but for `(?(a => b)) => c` it was! It's better to always put it anyway if it's not just a simple literal.

I've added tests for all the combinations I could think of, so we'll catch regressions if they happen.

Fixes #1353
2017-04-24 16:58:30 -04:00
Danny Arnold 6f0cc31fdb add TSIntersectionType (#1395)
* add TSIntersectionType

* use same print implementation for flow and typescript
2017-04-23 10:27:40 -07:00
Danny Arnold 5f5566e4ef fix TSFunctionType failing on TypeParameters (#1394) 2017-04-23 10:17:03 -07:00
Danny Arnold 44e55f7fa7 add TSMappedType and TSTypeParameter (#1393)
* add TSMappedType and TSTypeParameter

* respect bracketSpacing in TSMappedType
2017-04-23 10:16:25 -07:00
Danny Arnold 150c701191 fix TSTypeReference not printing typeArguments (#1392) 2017-04-23 08:31:50 -07:00
Danny Arnold 15df9abf81 add TSTypeOperator (#1396) 2017-04-23 08:25:25 -07:00
Danny Arnold 95d505843e parent decides how to print type annotations (#1391) 2017-04-22 18:09:53 -07:00
Vinh Le d0e8976af8 Fix empty line in block with EmptyStatement (#1375)
* Fix empty line in block with EmptyStatement

* Update code per review
2017-04-22 07:57:52 -07:00
Brian Ng c0a0bf46bc Fix missing trailing commas on flow generics (#1381) 2017-04-21 13:57:21 -07:00
lemon79 96e5c889e3 fix do-while break (#1373)
* fix do-while break

* added test for long while statement

* update snapshot

* merged with prev changes
2017-04-21 08:03:53 -07:00
Danny Arnold 99e4bae321 add TSConstructorType (#1367)
* add TSConstructorType

* combine condition

* combine strings
2017-04-21 07:57:26 -07:00
Danny Arnold 9002379b70 add TSLastTypeNode and TSIndexedAccessType (#1370) 2017-04-20 18:01:34 -07:00
Brian Ng 93f040a9ea Skip trailing commas with FlowShorthandWithOneArg (#1364) 2017-04-20 14:46:41 -07:00
Danny Arnold d823fe6fca add printer branches for some TypeScript nodes (#1331)
* add TSNeverKeyword

* add TSUndefinedKeyword

* add TSSymbolKeyword

* add TSNonNullExpression

* add TSThisType

* add tests for simple typescript nodes
2017-04-19 15:41:18 -07:00
Christopher Chedeau bae08d4e7e Only break for conditionals (#1350)
We only want to break for && and ||, not for ===
2017-04-19 13:18:01 -07:00
Christopher Chedeau 007cfd9179 Fix duplicate comments in classes (#1349)
Turns out, you can't blindly print this node. We need a deeper fix but let's revert this fix for now.

Fixes #1348
2017-04-19 11:59:23 -07:00
Christopher Chedeau 3dc7562743 Don't inline paren at right of arguments (#1345)
Fixes #1338
2017-04-19 10:44:00 -07:00
Christopher Chedeau aafcf5f381 Break if () if conditional inside breaks (#1344)
Fixes #868
2017-04-19 10:43:48 -07:00
Christopher Chedeau 042e603a6e Fix arrow function parenthesis with comments in flow (#1339)
`leadingComment` and `trailingComment` are babylon-specific, we should use `comments` which is what prettier adds.

Fixes #1335
2017-04-19 10:43:31 -07:00
Simon Lydell 938f0e3404 Improve regex printing (#1341)
- Print the raw regex for Flow, just like for Babylon.
- Sort regex flags.

Fixes #1334.
2017-04-19 10:24:13 -07:00
Danny Arnold cb79d82569 add printer branch for TSFirstTypeNode (#1332)
* add TSFirstTypeNode

* add test for TSFirstTypeNode
2017-04-19 09:03:55 -07:00
Kevin Gibbons 565106dd63 Add parentheses for assignment as body of arrow (#1326) 2017-04-18 13:28:33 -07:00
Christopher Chedeau 8d03423d17 Avoid breaking arguments for last arg expansion (#1305)
We've had this issue since the beginning and I tagged it as 1.0 but haven't managed to fix it by then. We shouldn't allow things to break in the argument list if we are in the last argument expansion mode. It turns out that we now have all the building blocks needed to fix this:
- have a special way to flag when we are printing the last argument expansion in the code that prints the argument list
- have a way to remove all the softlines from the argument list

Fixes #1301
2017-04-18 08:40:08 -07:00
Christopher Chedeau 5995af25a3 Bail when traversing === groups (#1294)
This is the second part of the fix for the performance regression seen in #1250. In #1217, for correctness reasons, we're now traversing all the conditional groups. This means that we're now in O(n^2). But, in practice, many of those groups are === between each others. So we only need to recurse through one of the instances to know if it's going to break.

This makes the first example go from not terminating to being instant. The second one going from not terminating to taking ~1s. We can also make it instant by tweaking the printing phase, but that's for another PR.
2017-04-18 08:39:47 -07:00