Commit Graph

173 Commits (3654108ebe028fbc3063ceccb3c4ce0d4164510a)

Author SHA1 Message Date
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
Ika 3fe790d4b7
refactor: fix linting 2018-05-08 12:42:02 +08:00
Ika 76a5f3c7b6
fix(typescript): add missing `qualifier` and `typeof` in TSImportType (#4438) 2018-05-08 12:35:12 +08:00
Kevin Donnelly c6e7c1966e Improve formatting of TS casts with generics and unions (#4219)
* Add tests showing existing behavior of various TS casts.

* Improve formatting of TS casts with generics and unions.

By adding a soft break between the cast and the expression. Also
includes wrapping parentheses for clarity as suggested in #4171.

Avoids changing behavior at all though if casting an array or object
literal because those already have good behavior where the array or
object literal breaks before the cast does so including them would just
result in a pointless extra layer of parentheses that would add no
clarity.

* Update tests in prepation for updating long cast format.

* Update so nested breaks inside type cast are indented.

* Add tests where expression being cast is too long itself.

* Update cast formatting to only sometimes break after cast.

Specifically it will break after the cast if that makes the cast itself
fit on a single line. If the cast itself won't fit on a single line then
the expression being cast will be placed directly after the `>` at the
end of the cast.
2018-05-07 22:26:01 -06:00
Suchipi ed18f9f7d7
Add heuristic to format functional composition more nicely (#4431)
* Add heuristic to format functional composition more nicely

* Regex -> array

* Use object instead of array for faster lookup

* Remove empty lines

* Add redux connect

Also add comments for libraries
2018-05-07 21:46:30 -06:00
Ika cc4392e5c0
feat(typescript): support TSImportType (#4429)
* feat(typescript): support TSImportType

* test: add singleQuote test
2018-05-07 07:57:57 +08:00
Ika 7e81a613b5
feat(javascript): support jest-each template string (#4423)
* feat(javascript): support jest-each

* test: add trailing newline

* fix: there can be no trailing newline

* refactor: simplify regex

* refactor: Array.from

* refactor

* fix: print quasis safely
2018-05-06 14:52:34 +08:00
Lucas Duailibe 5776c8405a
Fix TSMappedType comments (#4418) 2018-05-05 15:43:53 -03:00
Lucas Duailibe 8e1b60e943
Fix trailing JSDoc comments with trailing regular comments (#4414) 2018-05-04 10:15:30 -03:00
Lucas Duailibe 32900842e3
Apply destructuring rules in functions to catch param (#4385) 2018-05-01 10:24:46 -03:00
Ika 289b98c125
feat(json): enforce StringLiteral-style property key (#4371)
* test: add tests

* feat(json): enforce StringLiteral-style property key
2018-04-26 00:00:07 +08:00
Ika 6a17474e37 feat(typescript): support generic JSX element (#4268)
* feat(typescript): support generic JSX element

* fix(playground): `buffer is not defined` in `--parser typescript`

* chore(deps): update typescript-eslint-parser
2018-04-24 08:45:31 -05:00
Ika 643e2a83d6 feat(typescript): support TaggedTemplateExpression typeParameters (#4353)
* test: add tests

* feat(typescript): support TaggedTemplateExpression typeParameters

* fix(playground): `buffer is not defined` in `--parser typescript`

* chore(deps): update typescript-eslint-parser
2018-04-24 08:45:06 -05: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
Mike Grip 4c464133ac feat: adding plugin ability for isBlockComment (#4347)
* adding plugin ability for isBlockComment

* refactor to remove private util def

* remove old fn def
2018-04-19 13:31:08 -07:00
Brian Ng 7cb6790ce0
Merge pull request #4326 from existentialism/flow70
Bump flow to 0.70
2018-04-18 17:04:14 -05:00
Brian Ng 7ab3e94fbb
Ensure mixins before implements 2018-04-16 21:28:56 -05:00
Christopher Chedeau 02a1db8c9f
[flow] Fix union indent inside of function param with a name (#4325)
Fixes #4323

See #4323 for all the context
2018-04-16 18:47:05 -07:00
Ika 8e8a8d50cf
refactor(doc-utils): move `rawText` to printer-estree (#4309) 2018-04-14 00:05:00 +08:00
Suchipi Izumi bdc5e0073d Bump own prettier dependency to 1.12.0 2018-04-11 22:39:13 -06:00
Jed Fox 63a2ded4c9
Never print a semicolon after `export default interface Foo {}` (#4128)
* Never print a semicolon after `export default interface Foo {}`

* Add test
2018-04-11 06:38:02 -04:00
Lucas Duailibe 57bc700602
Stop marking all comments in named exports as leading comments (#4292) 2018-04-10 17:05:49 -03:00
Aakansha Doshi 6794a14554 Inline Angular async tests and beforeEach, etc. (#4241)
* fix #3791 and refactor isTestCall

* typo

* remove default value

* add safe check if parent exists

* add spec

* better comment
2018-04-11 00:06:42 +08:00
Lucas Duailibe 18aaee594f
Break object destructuring with nested destructuring (#4267) 2018-04-06 11:57:37 -03:00
Lucas Duailibe fa089f5bb6 If consequent is a block statement, treat as trailing comment 2018-04-05 17:22:10 -03:00
Lucas Duailibe 88489a9afe Handle comments before `else` 2018-04-05 16:06:18 -03:00
Lucas Duailibe e17bb5e947 Break nested ternaries (#4120) 2018-04-04 18:50:15 -06:00
Lucas Azzola e03e4d6d40
Move needsParens to a language-specific file (#4201) 2018-03-25 18:35:32 +11:00
Christopher Chedeau adf6d1849d
Remove outdated comment (#4190)
We now always return a conditional group.
2018-03-21 14:38:51 -07:00
Brian Ng 4553b88bd4
Merge pull request #4156 from Cryrivers/master
feat(typescript): support TSMinusToken and TSPlusToken
2018-03-21 09:06:06 -05:00
Mike Grip d9ee183f5b feat: enable plugin-specific comment functionality (#4182)
* feat: enable plugin-specific comment functionality

This change enables language plugins to provide their own "handleComment" function. To do so, we're exposing the addLeadingComment, addTrailingComment, and addDangling comment functions which attach comment nodes correctly in the ast which will get handled by prettier core when printing.

* moving js comment functionality to plugin
2018-03-20 18:39:28 -07:00
Evilebot Tnawi 31530259a1 feat: indent in discriminant switch (#4165) 2018-03-19 23:50:24 +11:00
Wang Zhongliang 419694485b fix: make ESLint happy 2018-03-16 14:47:51 +08:00
Wang Zhongliang 5eea8aa2f5 feat(typescript): support TSPlusToken 2018-03-16 14:08:25 +08:00
Wang Zhongliang 67277f7477 feat(typescript): support TSMinusToken 2018-03-16 10:46:12 +08:00
Lucas Duailibe 13103101eb
Move pragma detection/insertion to plugins (#3685)
New pragma infrastructure, only JS and JSON has detection/insertion implemented
2018-03-08 13:50:33 -03:00
Lucas Duailibe 41098a06b5
Prevent "over-indenting" class properties values (#4085) 2018-03-02 11:28:27 -03:00
Eric Anderson efd5bde713 Fix(typescript) non-null identifier same line in chain (#4052) 2018-02-26 15:12:03 -03:00
Zhongliang Wang d18da53e87 feat(typescript): Support conditional types (#4007)
* feat(typescript): support for conditonal types

* refactor(js): reuse conditional expression logic

* chore(typescript): update snapshot for typescript conditional type test suite

* chore(js): make code support Node 4

* chore(js): rename utility functions

* chore(js): add comments for formatTernaryOperator

* fix(ts): support infer keyword

* chore(js): new line

* chore(js): improve readablity a little bit
2018-02-23 12:34:23 -07:00