Commit Graph

211 Commits (1916966910d30756073a04426a8b40bab543b148)

Author SHA1 Message Date
James Henry 1143619600
chore: update typescript-estree to new package name (#5799) 2019-01-28 19:46:51 -05:00
Simen Bekkhus 565731668f fix: do not format callbacks with arguments as React hooks (#5778)
Ref: https://github.com/prettier/prettier/pull/5608#issuecomment-455860396
2019-01-22 00:26:39 +08:00
James Henry 8ac0a731a4
chore: update typescript-estree to 18.0.0 (#5750) 2019-01-12 17:02:16 -05:00
James Henry ef6386015d fix: update typescript and typescript-estree to latest (#5728) 2019-01-12 11:10:52 +08:00
makepost 94eab666c4 fix(javascript): skip .connect() method when composing fun (#5739) 2019-01-10 12:20:15 -07:00
Wei-Wei Wu 91c20f7fbe Rename "babylon" with "babel" (#5647) 2018-12-27 21:05:19 +08:00
Brian Ng 8e612f05a0
Add support for class private methods (#5637) 2018-12-14 09:45:26 -06:00
Ika 419559e964
fix(javascript): correct indentation for expression in root template (#5607) 2018-12-12 09:52:23 +08:00
Jed Fox fa7eafaa6d
Add support for the React `useEffect` hook (#5608)
* Add support for the React `useEffect` hook

* Format

* Format

* [Refactor] remove unnecessary condition

`canHaveTrailingComma` is defined as `I(lastElem && ...)`, which will always be true when `lastElem === null`.

* Use a hacky method to allow the array to break

* Revert "[Refactor] remove unnecessary condition"

This reverts commit 91906ba22438afa0fe5e10c64a1fcf3cfa484ff3.

* Add tests for `React.useEffect` form
2018-12-10 06:09:20 -05:00
Ika 952bc0cc03
fix: get rid of CRLF (#5494) 2018-12-08 18:28:29 +08:00
Ika 3cd1d003c0
fix(typescript): do not throw errors on bigint keyword (#5577)
- fix `Error: unknown type: "TSBigIntKeyword"`
- bump typescript to stable version
2018-11-30 10:12:32 +08:00
Ika 0534735c2f
fix(vue): tweak semicolon for single expression in event bindings (#5519) 2018-11-29 09:28:35 +08:00
Christopher Chedeau 0af81c7695
Improve union types with leading comments (#5575)
We're running into this issue at Facebook because `// flowfixme` ignores the very next line, but in this case an empty line is added in-between which breaks the fixme.

Ideally the solution is to avoid adding a newline and we'd call it a day. Unfortunately it is tricky to implement in this particular case. The comment is already printed, including its \n. Yet, we want to indent the block and the only way to convince the doc printer to do so is to add an indent group --before-- the \n is printed, otherwise it's just going to indent on the next \n.

So this PR changes the output from one bad way to another, but the new way has the benefit of not breaking flow for Facebook, which makes our internal teams happier.

Note that the way we print the same construct with `&` is broken in the same way as with this PR. https://prettier.io/playground/#N4Igxg9gdgLgprEAuc0DOMAEBbAngNQEMAbAVzkwF5MAKME4+4xhpl5tmgDgHYA2LgE5+g3gP5CRY6cL6iJE2fL4BKJAB0ombTt17tAegOYAwhGzYEMTftu7oFAGSYYAdwjOYACwBOTzABWACYA1gAeXgBmxCFowVEA5jEBaEGJyV6pIdEBCZkhQQGJIcQpXkGRCSFFWaWRXlWlaOWVwZElCUUlAZgqANwgADQgEAAOMACW6MighD4+EK4ACnMIaMgghABuEBNBQyAARj6EYCFwMADKo6cTUAnIMD7kw14w2MQA6l4T8Gg3YDglzWvwmW1+uA2YDQ62GdzQcB8MCWJwS2EIyEiJARwxSYQAQiczhdLoRLAAZO5wTHYuC4tBhS53JJwACKpAg8BpxBxIBuPgRPg2h0Ih1wxGgB1GPjuME+e28yC4AAZhtKIAjPidRhtpXBBVtqcM-ABHUgTPwowhojFILE8ukgBHYCaPZ6OtDM4hsjlcu204YwUXyoKKpAAJkDJwmxGZZgstpAUAcB1ICIAKqL1v6HQBfXNAA

Fixes #5572
2018-11-28 10:30:51 -08:00
Ika 05ad885c3c
feat(typescript): support BigInt (#5546) 2018-11-27 16:53:34 +08:00
Ika 3a5bbf5fd2
fix(typescript): do not change `module` into `namespace` and break/hug their body correctly (#5551) 2018-11-26 13:34:35 +08:00
Ika 66ada24961
feat(angular): do not print colon for ngIf (#5542) 2018-11-25 15:43:40 +08:00
Ika 5c479cc55f
fix(typescript): do not add invalid semi for construct in interface with prettier-ignore (#5469) 2018-11-14 21:35:37 +08:00
Ika 57b057cfa2
fix(typescript): inline method decorators should stay inlined (#5444) 2018-11-14 10:13:35 +08:00
Ika 6cedf7d5d9
fix(flow,ts): consistent interface and remove unnecessary indent for extends (#5432) 2018-11-11 00:15:18 +08:00
Ika 8b1260a770
fix(javascript): inline property decorator should stay inline (part 2) (#5423) 2018-11-10 16:44:33 +08:00
Adrian 6dcc7ed575 fix(javascript): handle createSelector as function composition (#5430)
fixes #5285
2018-11-09 17:55:57 -07:00
Ika 469a831619
fix(mdx): treat jsx codeblock same as in markdown (#5391) 2018-11-09 09:47:05 +08:00
Ika fd8ec95e0a
fix(javascript): do not apply test call formatting to arrow without body (#5366) 2018-11-08 14:00:42 +08:00
Ika 4b51907b87
fix(javascript): inline property decorator should stay inline (#5364)
Fixes the `@action` part in #5360
2018-11-07 17:21:03 +08:00
Ika 514b6d3741 Bump Prettier dependency to 1.15.0 2018-11-07 09:12:25 +08:00
Ika a4e8aaf7a1
fix(jsx): do not move trailing char to the next line as leading char (#5354) 2018-11-07 07:41:34 +08:00
Ika 40f46740f6
fix(jsx): consistent quotes in JSX expression (#5349) 2018-11-06 15:38:50 +08:00
Ika b6691ba615
fix(javascript): no regression for jsx in arrow function in jsx (#5343) 2018-11-06 15:38:30 +08:00
Ika 02f9802119
fix(javascript): no regression for ternary#test alignment (#5333) 2018-11-05 17:07:57 +08:00
Stefan Mirea e17512adcd Add an option to print single quotes in JSX (#4798)
* feat(option-singleQuote-jsx): Added jsSingleQuote

* feat(option-singleQuote-jsx): Refactored to use a simple jsxSingleQuote flag

* feat(option-singleQuote-jsx): Fixed borked rebase

* feat(option-singleQuote-jsx): Updated snapshots

* feat(option-singleQuote-jsx): Resolved pending comments

* feat(option-singleQuote-jsx): Removed assert

* Fixed merge conflicts

* Updated snapshots after merge conflicts
2018-11-04 16:36:00 -05:00
Ika 5e8a4a115a
feat: support HTML/Vue/Angular (#5259) 2018-11-04 23:03:07 +08:00
Simon Lydell 275b0543c8
Never put spaces to the right of stars in indentable block comments (#5330)
Fixes #5323. Previously we added space after `/*` _on the first line
only,_ but the intent is to only fix the indentation of comments, not
changing their "contents". Besides, this was inconsistent with the
handling of every following line. Finally, it broke `/*!` comments which
some minifiers look for to know which (license) comments to keep.

People can use https://eslint.org/docs/rules/spaced-comment to enforce
when to start comments with spaces.
2018-11-03 20:53:24 +01:00
Jordan Brown b861448dbf Pretty print inexact (#5304) 2018-10-26 21:05:42 +03:00
Aquib Master 1234ceb1d6 Fix flow extends not breaking out into new lines (#5244) 2018-10-25 10:49:53 -04:00
Ashwin Bhat 253716dd49 Fix Flow generic comment positioning (#5290)
* add test for ensuring that calls with zero arguments look right
2018-10-25 08:44:16 -04:00
Jed Fox 6a174654a4 Fix indentation of block comments where every line starts with a star (#5206)
Previously this was done only for JSDoc comments. Now it's done in a few additional cases.
2018-10-23 21:04:24 +02:00
Ashwin Bhat 4d4fab39fe Add support for flow typecast comments (#5280)
* Add support for flow typecast comments

* Allow whitespace between comment start and colon

Also rename flow-comments.js to utils.js

* fix bug where type annotations could be accidentally created

* use better regex in detecting flow comment whitespace

* fix comment in utils.js

* simplify conditionals and improve comments

* fix lint error
2018-10-23 10:46:20 -04:00
Lucas Duailibe 62e4654e60
Respect original text decorator order (#5207) 2018-10-17 14:14:59 -03:00
Lucas Duailibe 00004daf84
Break nested TSConditionalType (#5272) 2018-10-15 13:35:37 -03:00
Suchipi 0fa34b2c63 Print nested ternaries differently (#5039) 2018-10-14 12:45:37 -03:00
Lucas Duailibe c7093cb3e4
Add ASI protection for TSNonNullExpression (#5262) 2018-10-13 20:03:51 -03:00
Jed Fox 65b2454dd8
Improved object-break heuristic (#5205) 2018-10-12 12:45:30 -04:00
Lucas Duailibe ed6a2d9055
Prevent JSX from breaking a logical expression chain (#5092) 2018-10-10 14:11:37 -03:00
Lucas Duailibe b5fd382fe8
Inline the arguments of an arrow function in the body is conditional expression (#5209) 2018-10-08 19:28:58 -03:00
Lucas Duailibe ce952fc8c1
Fix printing of catch clause with a comment (#5202) 2018-10-08 14:18:30 -03:00
Lucas Duailibe 303f344bff
Keep decorators inline if they were written inline (#5188) 2018-10-08 11:00:43 -03:00
Lucas Duailibe 31c92a7237
Fix comment in variable declarator (#5190) 2018-10-05 08:40:16 -03:00
Brian Ng 2283efb437
Fix parens around ternary inside OptionalMemberExpression (#5179) 2018-10-02 20:45:15 -05:00
Onur Temizkan cc83a27a3e fix(typescript) Do not add extra semicolon to TSMethodSignature when prettier-ignore is used (#5140) (#5160) 2018-09-29 06:13:17 -04:00
Toru Kobayashi 3e05f210bb fix(js): quote property name as es5 compatible (#5157) 2018-09-28 13:51:34 -03:00
Onur Temizkan d7e96adac0 fix(js) Break args when second arg is a ternary (#5046) (#5151) 2018-09-27 16:50:33 -04:00
James Henry 81cf08118e
Drop-in replacement: typescript-estree for typescript-eslint-parser (#5139) 2018-09-25 15:44:21 -04:00
Jed Fox 59720392c3
Add support for timeouts passed as integers to test functions (#5085)
* Add support for timeouts passed as integers to test functions

* ;
2018-09-13 06:08:47 -04:00
Ika f7a6625d84
fix(typescript): no-semi for class props with modifiers (#5083) 2018-09-13 11:14:21 +08:00
Lucas Duailibe b020a5606f
Keep simple JSXOpeningTag's unbroken (#5078) 2018-09-11 11:15:50 -03:00
Ika 4d488e8b81
fix: no false positive for arrow function in jsx expression (#5063) 2018-09-07 09:39:59 +08:00
Lucas Duailibe 87376f93f3
Inline Generics with a single identifier (#5066) 2018-09-06 14:44:21 -03:00
Ika 50c9115632
feat: add printer.preprocess (#5041)
Sometimes we need to transform the ast to make it easier to print, but it's currently done in the parser (markdown and yaml), which leads the output ast harder to use for external users (custom parser), adding `printer.preprocess` can solve this issue.

And also this way we could move the trailing newline for json from `ast-to-doc.js` to `language-js`.
2018-09-03 23:27:50 +08:00
Eric Sakmar 6288704c41 format jest calls like regular calls (#5011) 2018-09-03 10:15:23 -03:00
Yulia Galuzo 0c7c1bfde4 fix: splitting jsx text correctly (#5006)
Fixes: #4941
2018-09-02 19:59:28 +02:00
Felix Wu e86f08555a Bugfix/ Don't inline pipeline operator with leading ownline comment (#5015)
* don't inline pipeline operator with leading ownline comment

* Add tests for comments surrounded with binary expressions

* Add babylon test for ownlinecomment with pipeline operator
2018-09-01 18:38:19 -04:00
Malcolm Groves d480858f01 Fix ternary format in function call (#4368)
* Fix ternary format in fn call

* Formatted to align with linter

* Update jsfmt.spec.js.snap

* Update jsfmt.spec.js.snap

* test: remove obsolete snapshot
2018-08-15 13:29:04 -04:00
TitanSnow 2de54dc4d8 remove redundant ASI protection for BindExpression (#4970) 2018-08-13 22:17:28 +08:00
Adrian Leonhard c83d5b15e7 Fix #4886 and add test. (#4954) 2018-08-08 09:24:25 -06:00
Brian Ng 1391891ef6 Print ObjectTypeInternalSlot with both flow/babel parsers (#4869)
* Print ObjectTypeInternalSlot with both flow/babel parsers

* chore: update to flow-parser@0.78.0

* test: update snapshot
2018-08-08 09:21:39 -06:00
Suchipi 418a04bf2b
Revert this/super blacklist for function composition heuristic (#4936) 2018-08-08 09:18:46 -06:00
Ika 308863e061
fix(typescript): no invalid output for ImportType in TypeReference (#4939) 2018-08-07 18:53:11 +08:00
Christopher Chedeau 3b3240bdb8
[assignment] proper group (#4932)
If you have

```js
a = b
```

we used to do

```js
group[a = b]
```

which works most of the time but has the unfortunate side effect that if the left part breaks, we're going to break the `=` as well. So you get

```js
{
  a
} = \n
  b
```

What this PR does it to add a group

```js
group[a group[= b]]
```

so that if the right hand side fits in one line, it should stay that way.

Note that there's a change with a comment being move but I think that it's fine. If I remember correctly, this test was to make sure that we didn't print invalid code, not that it had to be respected (that comment position is not something we really want to support in the first place).

Fixes #4645
2018-08-02 20:26:31 -07:00
Suchipi 3bfaf6626c
Never inline decorators, unless they're lone parameter decorators (#4830)
Fixes #2613.
2018-07-20 13:48:37 -06:00
Ika ed0ecdad18 fix(json): do not put values on a separate line from the key (#4852)
* test: add tests

* fix(json): do not put values on a separate line from the key
2018-07-17 18:08:59 -03:00
Eugene Datsky 03ee86ea80 Blacklist this in functional composition heuristics (#4836) 2018-07-12 11:58:57 -03:00
Ika b1c0c8c8d6
refactor(typescript): remove unnecessary experimental types (#4819)
Ref: eslint/typescript-eslint-parser#429
2018-07-10 10:05:31 +08:00
Ika 50d242d085
feat(typescript): support TSOptionalType and TSRestType (#4757)
Ref: Microsoft/TypeScript#24897
2018-06-30 09:10:56 +08:00
Ika e10c31a333
fix(typescript): update typescript-eslint-parser (#4762) 2018-06-29 19:27:21 +08:00
Karl O'Keeffe 7a3ac3a693
Handle JSX whitespace separately from fbt whitespace (#4717)
* Hande JSX whitespace separately from fbt whitespace

* Extra test cases

* Further tweak to JSX handling

* Possible improvement of single character text

* More tests

* Pull out separator code

* More tests for fbt
2018-06-25 19:11:40 +01:00
Suchipi cb5e1db4a5
Revert "Ternary Operators in JSX Expression Containers (#4731)" (#4736)
This reverts commit 12046cd01b.
2018-06-22 10:32:38 -06:00
tyrerexus 12046cd01b Ternary Operators in JSX Expression Containers (#4731)
This pull request aims to fix the issue of excessive nesting brought up in the following comment: https://github.com/prettier/prettier/issues/737#issuecomment-392541493

This "fix" is very simple. It adds a new possible way to activate JSX mode for ternary operators. If the first non-conditional parent of the expression is a JSX expression container, then JSX mode gets activated.

This branch also contains a test case for said scenario.
2018-06-22 10:30:53 -06:00
Ika 4109abf4dd
feat(javascript): support BigIntLiteral (#4697) 2018-06-16 00:20:04 +08:00
Lynn Smeria 61d35dd636 fix(typescript): preserve type parameters of import-types (#4656) (#4662) 2018-06-11 11:29:10 +10:00
Brian Ng 3e0dceda99
flow-parser@0.74.0 (#4649) 2018-06-09 17:03:50 -05:00
Ika 98bfd03d93
feat(typescript): support unknown type (#4625) 2018-06-10 00:12:30 +08:00
Lucas Duailibe d013983d8a
Always expand first argument if the second argument is also a call expression (#4657) 2018-06-08 15:16:12 -03:00
Lucas Duailibe cb1c52ad08
Break JSX in arrow functions in JSX expressions (#4601) 2018-06-08 15:15:50 -03:00
Lucas Duailibe a4da6e6c8e
Inline _ or $ in the root of a method chain (#4621) 2018-06-01 12:51:06 -03:00
Ika 8abbc5d4b0
fix(javascript): regression for `hasOwnProperty` (#4603) 2018-05-31 00:39:39 +08:00
Lucas Duailibe a6db391556
Short rule should only apply to the first identifier (#4575) 2018-05-27 21:52:42 -03:00
Kevin Donnelly 16a84e88d6 Improve format when passing ts arrow function with return type as an argument (#4228)
* Add various tests for ts type annotated function properties.

* Improve format when passing ts arrow function with return type

* Add test for case from #2581.
2018-05-27 20:39:08 -03:00
Lucas Azzola b0cb63a7bb
Use destructuring for imports (#4554)
* Use destructuring for imports

* Clean up integration tests

* Use moduleNameMapper for require_prettier
2018-05-27 21:36:12 +10:00
Brian Ng fda7bf59f4
Add support for Flow's proto modifier syntax (#4551)
Flow commit: eb815be907

Babel PR: https://github.com/babel/babel/pull/7978
2018-05-25 17:23:17 -05:00
Brian Ng d20d9c160e
Switch to @babel/parser (#4544)
We landed a change that added a new `InterpreterDirective` AST node type for hashbangs, and no longer add it as a comment/leadingComment.

Ref: https://github.com/babel/babel/pull/7928

I mimicked what we do in `@babel/generator` here, since I found it better than trying to add comments to the ast in `parser-include-shebang.js`). Definitely open to a better/cleaner option though!

Note: I'll follow this up with enabling tests for https://github.com/prettier/prettier/pull/4543 and https://github.com/prettier/prettier/pull/4540 once they land too.
2018-05-25 11:27:41 -05:00
Brian Ng e42db35427
Add support for flow inline interfaces (#4543)
Flow commit: 4f93f3adb7

Babel commit: https://github.com/babel/babel/pull/7973

Will follow up w/ flow team on making `InterfaceType` -> `InterfaceTypeAnnotation`, since it seems a bit inconsistent.
2018-05-25 09:17:43 -05:00
Brian Ng 61b39749a1
Add support for flow explicit type arguments (#4540)
Fixes #4489.

Babylon support landed in `beta.48` just now but requires a few other fixture changes, so I'm going to follow this up with another PR.
2018-05-25 08:55:39 -05:00
Lucas Duailibe c2202efd54
Do not remove parens for ?. operator (#4542) 2018-05-24 23:27:49 -03:00
Christopher Chedeau 8f141bfafe
Update babylon & flow (#4536)
* Support new node types for optionals

* Update babylon

* Fix decorator tests

* fix manual errors

* Update flow

* pretty print

* enable option for flow to support ??

* fix AST_COMPARE=1

* fix lint and explicitly test 1_2_3 syntax for flow
2018-05-24 13:06:33 -07:00
Ika 553e9bb1ac
fix(typescript): preserve quoted class property (#4517) 2018-05-21 18:57:30 +08:00
Lucas Duailibe ea01781d8c
Only break chains with short names if inside ExpressionStatement (#4505) 2018-05-18 21:44:15 -03:00
Georgii Dolzhykov c6e8177282 Inline AngularJS tests that use `inject` (#4495)
* Inline AngularJS tests that use `inject`

See https://docs.angularjs.org/guide/unit-testing#using-beforeall- for a code example.

* More meaningful function name, minor refactoring

* Linting

* Minor regexp improvement

* address review comments
2018-05-17 12:09:20 -03:00
Brian Ng 857c55bd61
Keep parens around do-expressions inside ExpressionStatement (#4479) 2018-05-15 11:41:17 -05:00
Soo Jae Hwang ee96e97c77 Fix: Group long name method in bind expressions (#4447)
* Fix: Group long name method in bind expressions

* Add test for short name method in bind expressions
2018-05-09 10:42:16 -06:00
Nicolò Ribaudo ab452ddc38 Fix: Correctly break class prperties initializer. (#4442) 2018-05-08 20:35:49 -04:00