Commit Graph

1522 Commits (master)

Author SHA1 Message Date
Sosuke Suzuki 74f4d2b3c0 JavaScript: Keep line breaks when tagged template literal has a single line comment. (#6236) 2019-07-10 10:56:53 -03:00
Sosuke Suzuki cfba21f493 JavaScript: Keep unary expressions parentheses with comments (#6217) 2019-07-10 10:06:08 -03:00
Gavin Joyce 12b8176d5d [Glimmer] preserve html entities (#6234) 2019-07-08 11:07:41 +02:00
Gavin Joyce e8037ff250 [Glimmer] improve text/mustache formatting (#6206) 2019-06-19 09:53:27 -03:00
Gavin Joyce ff7bc1c008 [Glimmer] improve text/mustache formatting (#6186) 2019-06-14 12:11:47 -03:00
Lucas Duailibe 4e8f911a29
Print comment following a JSX generic (#6209) 2019-06-10 09:30:54 -03:00
Lucas Duailibe a90adf4753
Fix adding trailing comma in TS tuples (#6199) 2019-06-07 11:18:42 -03:00
Sosuke Suzuki 8812792e93 [TypeScript] Add trailing comma for only arrow functions in tsx. (#6190)
* Modify to add traling comma only for allow-function

* Add tests

* Update CHANGELOG.unreleased.md

* Add pr number and link

* Modify to improve RegExp to detect tsx file
2019-06-07 09:01:58 -03:00
Gavin Joyce 90308ebe76 fix: avoid unwanted whitespace in glimmer components (#6178) 2019-06-05 11:15:11 -03:00
Lucas Duailibe 2e6191fe77
Prevent adding quotes if there's a numeric literal as key (#6138) 2019-06-04 13:45:29 -03:00
Sosuke Suzuki ed2055b81f [TypeScript]Keep a trailing comma on tuple types (#6172) 2019-06-03 09:59:34 -03:00
Georgii Dolzhykov e4f0df5bed fix: nested embeds (JS in HTML in JS) (#6038) 2019-05-27 14:42:13 -03:00
Lucas Duailibe f8875c1caa
Prevent parens around BindExpressions as properties of MemberExpressions (#6159) 2019-05-27 13:58:26 -03:00
Sosuke Suzuki dcf4c21171 Keep necessary parentheses around the bind expression passed to "new" expression (#6152) 2019-05-27 09:21:34 -03:00
Sosuke Suzuki 3654108ebe TypeScript: Keep line breaks within mapped types. (#6146) 2019-05-24 19:00:32 -03:00
Kevin Gibbons c03fcfedb1 Address parentheses bugs for edge cases with call and new (#6148) 2019-05-24 11:09:17 -03:00
Georgii Dolzhykov b3adb46ba9 Keep parens around non-null assertions for new-expressions only (#6140) 2019-05-22 19:01:47 -03:00
Lucas Duailibe 7e47b4ea26
Preserve parens around expressions in default export declaration that start with function or class (#6133) 2019-05-20 09:31:38 -03:00
Rich Hong 906d33749b Add support for styled-jsx external styles (#6089) 2019-05-19 13:26:30 -03:00
Sosuke Suzuki 3b3c411642 TypeScript: Keep parentheses around a function called with non-null assertion. (#6136) 2019-05-19 13:15:02 -03:00
Sosuke Suzuki 4c64f13ef4 [TS] keep a pair of parentheses where there extra pairs. (#6131) 2019-05-17 18:13:40 -03:00
Lucas Duailibe eca23e111f
Stop converting empty JSX elements to self-closing elements (#6127)
Co-Authored-By: Simon Lydell <simon.lydell@gmail.com>
2019-05-16 15:14:35 -03:00
Lucas Duailibe df258d6d7e
Add parens in JSX spread element with expressions (#6130) 2019-05-16 15:06:41 -03:00
Evilebot Tnawi 7a76e5d08e fix(javascript): correctly handle comments in empty arrow function expressions (#6086) 2019-05-15 12:46:12 -03:00
Evilebot Tnawi 2cebeecb4f fix(javascript): do not hug sequence expression in object properties (#6088) 2019-05-15 12:29:45 -03:00
Lucas Duailibe 012b7a653e
Prevent adding unnecessary quotes when a computed key exists (#6119) 2019-05-14 19:41:49 -03:00
Mykola Bilochub c95b81dd3d fix(markdown): correctly determine count of backticks in inline code (#6110) 2019-05-14 12:51:31 -03:00
Brian Kim 48d542ec1e TypeScript: Don’t breakup call expressions when the last argument is an arrow function with a simple return type (#6106) 2019-05-14 10:57:42 -03:00
Justin Ridgewell 4fda7af783 Fix closure type cast without spaces (#6116)
* Fix closure type cast without spaces

Closure typecasts don't require a space between the `@type` and opening `{`.

* More tests, and add a changelog entry
2019-05-14 10:14:52 -03:00
Sosuke Suzuki e3b2f4adb4 Keep a trailing comma in type parameter in .tsx files (#6115) 2019-05-13 14:53:45 -03:00
jwbay 6cee80b5b5 Don't break simple template literals (#5979)
A simple template literal is initially defined as a literal wherein all the expressions are identifiers or member access expressions where all parts are identifiers. We print these expressions into strings with infinite print width before printing the template.
2019-05-08 13:14:55 -03:00
Yang Su 54b7655dab Improved multiline closure comment detection (#6070) 2019-05-07 07:30:07 -03:00
mathieulj 26183e5be2 Use same print width for range formatting as normal formatting. (#6050)
* Use same print width for range formatting as normal formatting.

Fixes an issue were a file would end up formatted differently
with ranged formatting (--range-start & --range-end) versus
normal whole file formatting.

* Document range bugfix in changelog.
2019-05-04 10:18:55 -04:00
Cyrille David 84cc273c7d fix(glimmer): {{else}}{{#if}} into {{else if}} merging (#6080) 2019-05-02 16:26:26 +03:00
Evilebot Tnawi 157b020de6
fix(javascript): correctly handle comments in empty arrow function expressions (#6087) 2019-04-30 14:25:20 +03:00
Justin Ridgewell c085aeb152 Fix closure compiler type casts (#5947)
* Fix closure compiler type casts

This fixes casts when they are followed by a closing parenthesis, eg:

```js
foo( /** @type {!Array} */(arrOrString).length );
```

The old code would see the `CallExpresion`'s closing `)` and assume the typecast belonged to the `MemberExpression`, not the `arrOrString` `Identifier`.

This would be easier to accomplish if every AST would tell us if the expression were parenthesized. If they did, we could check that the node were parenthesized and either it or an ancestor has a typecast, stopping when we find an ancestor is itself parenthesized.

* More tests, and changelog

* Fix while loop

* Update changelog

* Update CHANGELOG.unreleased.md

* Use babel's parenthesized information

* Cleanup call
2019-04-26 13:05:57 -04:00
Chris Brody 6ae41067cf Test generics in object methods in TypeScript (#5989) 2019-04-08 16:56:39 -03:00
Evilebot Tnawi dcaed91518 fix: respect newlines in parameters (#5836) 2019-04-04 09:50:07 -03:00
Adrian Zgorzałek 9cb50add5e graphql: Support variable directives. (#6020) 2019-04-04 09:47:05 -03:00
Adrian Zgorzałek 7c9823fcba Teach prettier/graphql about formatting fragment variables. (#6016)
Fragment variables are an experimental extension to GraphQL schema.
Formatting should follow the same rules as formatting an OperationDefinition node,
hence code is the same.
2019-04-04 09:44:52 -03:00
Ika f4bcb13d41
feat(typescript): support TS 3.4 (#6027)
- add support for `readonly` operator
- `as const` was already supported, added tests to ensure no regression
2019-04-04 15:32:54 +08:00
Noah Sugarman 0b07e10833 fix multiline dynamic import comments (#6025) 2019-04-02 12:35:03 -07:00
Kevin Gibbons 1e471a0079 Add parentheses for immediately-constructed fn/class (#5996) 2019-03-28 21:06:39 +03:00
Zaven Muradyan 887f800651 fix(angular): don't add unnecessary parentheses to pipes (#5929) 2019-03-13 09:02:36 +08:00
Lucas Azzola f526c47b1e
Add an option to modify when Prettier quotes object properties (#5934)
* Implement quote-props=preserve

* Implement quote-props=consistent

* Add tests

* Enable quoteProps in playground

* Add documentation

* Cache objectHasStringProp calculations

* Fixup changelog
2019-03-06 20:33:08 +11:00
Yang Su 71b815f583 JavaScript: Fix parens logic for optional chaining expressions and closure type casts (#5843) 2019-02-11 13:33:56 -02:00
Nathan Totten a093bb3f7b Adds LWC Parser to support unquoted interop attributes (#5800)
This pull requests adds a new parser option `lwc`. This is the same as the HTML parser, but it adds support for unquoted HTML attributes per the needs of LWC. See: #5627
2019-02-01 13:58:50 +08:00
陈帅 a9d2c41464 feat(markdown): do not align table contents if it exceeds the print width and `--prose-wrap never` is set (#5701)
Fixes #5651
2019-01-30 12:24:21 -05:00
Yang Su 47da0804a9 JavaScript: fix edge cases in type cast comment detection regex (#5793)
Fix edge cases involving {...} ([record @type](http://usejsdoc.org/tags-type.html)) and newlines in prettier's detection code for type cast comments
2019-01-30 15:24:34 +08:00
Ika 847a78e8e9
fix(html): do not format non-normal whitespaces as normal whitespaces (#5797) 2019-01-30 14:30:10 +08:00
Ika 153d2d0570
fix(typescript): stable parens for function type in arrow return type (#5790) 2019-01-22 21:07:10 +08:00
Ika 1061be0702
fix(mdx): correctly recognize inline JSX (#5783) 2019-01-22 12:02:30 +08:00
Ika 2002ce0453
fix(javascript): add necessary parentheses for decorators (#5785) 2019-01-22 00:54:41 +08: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
Ika 42f7b6025e
fix(javascript): remove unnecessary linebreaks from html templates (#5771) 2019-01-20 11:15:18 +08: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
Jarda Snajdr 5847c168e4 Fix formatting of lists in SCSS property/variable values (#5710) 2019-01-10 00:08:34 +08:00
Phil 30979ed104 typescript: remove unneeded parentheses around type annotation (#5724)
* Remove unnecessary parentheses from annotations

* add test for ts parentheses bug
2019-01-07 09:19:41 -03:00
Ika 63999c74eb
fix(mdx): handle inline html correctly (#5704) 2019-01-03 10:46:11 +08:00
Ika 3de36e3a2b
fix(ng,vue): add parens to avoid unexpected `}}` in interpolations (#5657) 2018-12-30 23:03:42 +08:00
Ika 7c4cebeaa5
feat: add babel-flow (#5685) 2018-12-29 21:35:47 +08:00
Wei-Wei Wu 91c20f7fbe Rename "babylon" with "babel" (#5647) 2018-12-27 21:05:19 +08:00
Ika 65a9d3b8cc
fix(flow,ts): format `/* HTML */` templates (#5658) 2018-12-19 23:00:18 +08:00
lhchavez 911d6c88e5 Fix formatting with --range-start / --range-end (#5632)
This change avoids collapsing an already-formatted range into a single
overlong line when --range-start / --range-end are provided.

Fixes: #4923
2018-12-17 10:59:20 -02:00
Dmitriy Sharshakov aka. sh7dm 6a45924379 fix(printer-postcss): ignore escape \ and escaped / in Less (#5597)
Avoid messing up Less files containing \\/ (escaped /).
Ignore escape \ and escaped / in Less.
2018-12-17 08:28:48 +08:00
Ika cbf06bf388
feat(html): format script with "application/ld+json" (#5642) 2018-12-16 16:21:10 +08:00
Brian Ng 8e612f05a0
Add support for class private methods (#5637) 2018-12-14 09:45:26 -06:00
Ika ffc8482458
fix(vue): tag names are case-sensitive (#5606) 2018-12-13 10:31:48 +08:00
Ika 419559e964
fix(javascript): correct indentation for expression in root template (#5607) 2018-12-12 09:52:23 +08:00
Ika 5e89969a9e test: update snapshots 2018-12-11 16:18:29 +08:00
Ika d97fe0a1e0
feat(html): preserve surrounding linebreaks (#5596) 2018-12-11 12:43:53 +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
Lipis 7c1758de86
Update example for *.vue (#5605) 2018-12-07 16:34:26 +01:00
Laurin Quast 9d1fb93e86 feat: add mjml extension to html language (#5505) 2018-12-07 21:01:40 +08:00
Ika cd28c22dbe
feat(html): smart quote for attributes (#5590) 2018-12-05 11:15:09 +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 2247ce1aab
feat(angular): support interpolation in attributes (#5573) 2018-11-30 09:28:54 +08:00
Ika 28b938da97
feat(html): update angular-html-parser (#5565)
- support [`htm`](https://github.com/developit/htm) (`<${Component}>content<//>`, `<div />`)
- preserve [bogus comments](https://www.w3.org/TR/html5/syntax.html#bogus-comment-state) (`<! ... >`, `<? ... >`)
2018-11-29 11:03:22 +08:00
Ika d124bbaacb test: update snapshots 2018-11-29 10:38:37 +08:00
Ika 1ecd2228b4
fix(vue): group slot-scope correctly (#5563) 2018-11-29 10:09:38 +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 a7528ebea4
fix(ng,vue): do not normalize attribute names (#5549) 2018-11-26 12:09:19 +08:00
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
Ika 66ada24961
feat(angular): do not print colon for ngIf (#5542) 2018-11-25 15:43:40 +08:00
Ika b6a04ab8ba
fix(html-in-js): do not add quotes for interpolation-only attributes (#5544) 2018-11-25 15:04:02 +08:00
Ika c788842fea
fix(javascript): add missing parens for binary in optionalMember (#5543) 2018-11-25 11:42:06 +08:00
Ika ab7f46bf40
feat(yaml): preserve the first document head end marker (#5502) 2018-11-25 10:30:25 +08:00
Ika a50a8e258c
fix(javascript): upgrade @babel/parser to 7.1.6 (#5530) 2018-11-24 21:47:47 +08:00
Ika 7da4ed76ad
fix(html): do not touch comments (#5525) 2018-11-23 21:25:58 +08:00
Ika 228a8b0782
fix(html): do not add extra indent for js template in script (#5527) 2018-11-23 15:20:30 +08:00
Ika cdac9552ef
fix(vue,ng): do not normalize tag names (#5526) 2018-11-23 13:12:43 +08:00
Ika b2eadd234b
fix(vue): preserve custom block (#5458) 2018-11-23 12:33:48 +08:00
Ika 6ee2f464ac
feat(javascript): enable logical assignment (#5489) 2018-11-18 16:38:35 +08:00
Ika 043a937de6
fix(markdown): do not trim content in inline-math (#5485) 2018-11-16 00:17:20 +08:00
Ika 668e049a5e
feat(html): support ie conditional start/end comment (#5470) 2018-11-15 12:35:28 +08:00