Commit Graph

1822 Commits (master)

Author SHA1 Message Date
Adrian 6dcc7ed575 fix(javascript): handle createSelector as function composition (#5430)
fixes #5285
2018-11-09 17:55:57 -07:00
Ika 4e7fca5047
fix(markdown): identify CJK correctly (#5402) 2018-11-10 01:00:58 +08:00
Ika 1bce579f8d
fix(ng|vue): whitespaces between interpolation and text are sensitive (#5396) 2018-11-10 01:00:26 +08:00
Ika b0b5460e8f
feat(cli): allow overriding (#5390) 2018-11-10 00:59:59 +08:00
Ika de11f69889
fix(html): preserve unterminated ie conditional comments (#5424) 2018-11-09 23:26:59 +08:00
Ika 6f6b634948
fix(html): preserve content for `<template>` with unknown lang (#5388) 2018-11-09 19:19:03 +08:00
Ika 12a8fa3a24
fix(html): treat CRLF as LF (#5393) 2018-11-09 09:56:46 +08:00
Ika 423ddf9abd
fix(angular): add missing parens for pipe in ternary (#5397) 2018-11-09 09:51:54 +08:00
Ika 9acb02997a
feat(html): treat capital element as custom element (#5395)
Custom element: keep it on its own line if both leading/trailing line breaks exist
2018-11-09 09:51:31 +08:00
Ika 0228863a92
feat(html): handle pre with interpolation (#5400) 2018-11-09 09:50:57 +08:00
Ika 32ea48d499
fix(scss): do not throw if node.source undefined (#5394) 2018-11-09 09:48:16 +08: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 8cedb9d25e
fix(markdown): do not keep increasing backslashes for dollar sign (#5358) 2018-11-07 10:06:57 +08:00
Ika 514b6d3741 Bump Prettier dependency to 1.15.0 2018-11-07 09:12:25 +08:00
Ika 40ac85125a
fix(html-in-js): do not break empty content (#5355) 2018-11-07 08:32:26 +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 6a54e21c12
fix(css-in-js): do not remove semicolon (#5353) 2018-11-07 00:19:42 +08:00
Alexander Kachkaev b87fe4cf22 Add option to enforce certain line endings (#5327) 2018-11-06 22:47:13 +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
Thomas Bartel dbe86abc24 Make ast-to-doc.js a little easier to understand (#5346)
Rename genericPrint function to callPluginPrintFunction to avoid similar name to printGenerically
Add comments that explain the descent/recursion
2018-11-05 07:34:27 -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
Ika 0878a6a3e7
fix(less): remove CRs from inline comments (#5334)
The issue here is that less parser somehow included CRs in `comment.raws.content`, but it was hidden by the wrong trailing space elimination previously, which was fixed by #5165.

We already have such tests but it's not reproducible in AppVeyor since they use LF ([`core.autocrlf=input`](https://stackoverflow.com/a/20653073)).
2018-11-04 11:36:14 +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
Onur Temizkan f6d8be881c fix(css-in-js) Keep newlines in CSS-in-JS Templates (Fixes: #5147) (#5240)
* fix(css-in-js) Keep newlines in CSS-in-JS Templates (Fixes: #5147)

* Add more tests

* Do not add semicolon when CSS prop is a template variable

* Fix deletion of original semicolon

* Prettify long line
2018-11-01 21:58:16 +02:00
Jaiden Gerig 0799280429 Fixed unstable comment between function declaration and block statement (#5250) 2018-11-01 21:55:33 +02: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
Jaiden Gerig 2cc32da5af Fixed unstable while comment (#5251)
* Fixed unstable while comment

* Aligned while loop formatting more closely with if statment formatting
2018-10-25 10:48:09 -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
Evilebot Tnawi 023a8b78df feat: more shared utils for plugins (#5254) 2018-10-17 07:53:38 -07: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
Ika dd4687e7ef
feat(html): whitespace-sensitive formatting (#5168)
- whitespace-sensitive formatting 
  - respect css `display: block`/`white-space: pre` (data from [`html-styles`](https://github.com/marionebl/html-styles))
  - support magic comment (`<!-- display: block -->`)
  - add an option to specify whitespace sensitivity (`--html-whitespace-sensitivity <css|strict|ignore>`)
    - magic comments take precedence
    - (default) `css`: respect default css style (safe in the most cases)
    - `strict`: every node is considered whitespace sensitive (the safest)
    - `ignore`: every node is considered whitespace insensitive (dangerous, the original behavior)
  - inline inline-tags 
- support ie conditional comment (`<!--[if IE]><![endif]-->`)
- indent the script/style content
- no inconsistent output for 2+ attributes
- force break tag if there're multiline attributes
2018-10-13 13:55:38 +08:00
Aquib Master 3369be0ca2 Fix comment issue with try finally (#5252) 2018-10-12 12:48:49 -04:00
Jed Fox 65b2454dd8
Improved object-break heuristic (#5205) 2018-10-12 12:45:30 -04:00
Kevin Gibbons cbcd24a5b2 Correct parentheses for mixed exp/mod (#5243)
Fixes #5238.

cc @duailibe for the [original change](https://github.com/prettier/prettier/pull/4413). I basically undid that PR because it didn't look to me like `shouldFlatten` made sense as the place to introduce the behavior it was going for, but I might have misunderstood something.
2018-10-12 12:33:47 -04:00
Ika 3056c5a5c0
fix(yaml): escape quotes correctly (#5236) 2018-10-11 14:31:18 +08:00
Lucas Duailibe ed6a2d9055
Prevent JSX from breaking a logical expression chain (#5092) 2018-10-10 14:11:37 -03:00
Ika bb5a116b4f
fix(markdown): preserve inline math style (#5220) 2018-10-10 09:46:58 +08: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
Warren Seine 7920e6fdde Add a new `trim` command to trim whitespaces in the current line (#4772) 2018-10-06 20:18:52 +08:00
Mahir Shah 30ec30daa9 Escape Quotes in Glimmer String Literals (#5143) 2018-10-05 22:19:33 +02:00
Lucas Duailibe 31c92a7237
Fix comment in variable declarator (#5190) 2018-10-05 08:40:16 -03:00
Petter 1244729ad7 Infer via shebang (#5149)
If no file type can be inferred, this attempts to read the first line of a file and extract a shebang, which can be checked against a known list.
2018-10-05 08:47:23 +08:00
Brian Ng 2283efb437
Fix parens around ternary inside OptionalMemberExpression (#5179) 2018-10-02 20:45:15 -05:00
Kent C. Dodds b84635f0d0 support script type of text/babel in language-html (#5167) 2018-09-30 12:32:25 +08:00
Simon Lydell f87c82cc4e
Improve glimmer parse errors (#5161)
Instead of showing 80 carets, point out just which line the error was
on, and rely on the original message to point out the "column".

I thought about matching the `----^` in the original message with a
regex and use the length of it as the column number, but unfortunately
the original message does not show the original code (in this example
some whitespace is missing), so it wouldn't work.

Before:

```
$ ./bin/prettier.js test.hbs --parser glimmer
[error] test.hbs: SyntaxError: Parse error on line 2:
[error] {{one}}{{
[error] ---------^
[error] Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EOF' (2:0)
[error]   1 | {{one}}
[error] > 2 | {{
[error]     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]   3 |
```

After:

```
$ ./bin/prettier.js test.hbs --parser glimmer
[error] test.hbs: SyntaxError: Parse error on line 2:
[error] {{one}}{{
[error] ---------^
[error] Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'EOF' (2:0)
[error]   1 | {{one}}
[error] > 2 | {{
[error]   3 |
```
2018-09-30 00:25:45 +02:00
Christopher Chedeau 9910536b58
[unicode] Fix trailing nbsp (#5165)
I don't know why I added all the unicode whitespaces instead of just space and tabs, but it's not only unecessary but also wrong.

Fixes #5077
2018-09-29 15:22:13 -07: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
Simon Lydell 87e109f884
Escape not just backticks but `${` as well in graphql tags (#5137)
* Escape not just backticks but `${` as well in graphql tags

Fixes #4974.

* Also escape backslashes correctly in graphql tags
2018-09-29 09:42:44 +02: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
Ika 07abf0588e
fix(html): non-HTML attributes are considered case-sensitive (#5135) 2018-09-27 20:18:00 +08:00
James Henry 81cf08118e
Drop-in replacement: typescript-estree for typescript-eslint-parser (#5139) 2018-09-25 15:44:21 -04:00
Ika 51954daa74
fix(html): do not format unknown script (#5132)
- do not format unknown script
- do not normalize spaces in script tags
2018-09-23 08:36:54 +08:00
Ika 13147facc5
feat(html): switch to htmlparser2 (#5127)
- switch to [`htmlparser2`](https://github.com/fb55/htmlparser2)
  - no need to fork
  - won't generate pseudo nodes ([`parse5` will](https://github.com/prettier/prettier/issues/5098#issuecomment-423055181))
  - should be [faster](https://github.com/fb55/htmlparser2#performance)
- support custom self-closing tags
- support HTML entities
- remove extra trailing newline for `<template>`
- distinguish empty/empty-string attributes (`<tag x>`/`<tag x="">`)
- rename `--parser parse5` with `--parser html`
- enable `html` since 1.15, which means it's enabled by default if you install the dev version from GitHub after this PR merged.
2018-09-22 21:53:38 +08:00
Ika 0cbacd3156
fix(markdown): trailing spaces after front matters are allowed (#5107)
```md
---···· <--- allowed
yaml
---···· <--- allowed

markdown
```
2018-09-21 19:51:03 +08:00
Ika 27bf64f6ce
feat(html): self-closing for void tags (#5116)
XHTML compatibility.
2018-09-20 00:04:43 +08:00
Ika 4a084c82a1
fix(html): no need to strip newline for text in script-like tag (#5111)
The issue here is that the `stripTrailingHardline` does not work for js/ts, I fixed it and then I realized that we always print trailing newline in every language, so there's no need to strip newline for text in script-like tag.
2018-09-20 00:03:50 +08:00
Ika ebedd5b74a
refactor(html): simplify/extract code (#5112)
- extract utilities
- use built-in hasPrettierIgnore
- simplify some functions
- remove dead code
2018-09-19 23:07:27 +08:00
Ika 8ddff0787a
feat(html): support front matter (#5110)
- format yaml front matter
- preserve toml front matter
2018-09-19 22:10:41 +08:00
Ika 02fcea06fd
fix(html): preserve case-sensitive attributes (#5109)
Attributes in non-HTML tags are considered case-sensitive.
2018-09-19 21:36:37 +08:00
Ika 00ed49fad9
fix(html): preserve case-sensitive tag names (#5101) 2018-09-19 12:53:38 +08:00
Ika 79f4251e26
chore: enable html on preview playground (#5105) 2018-09-19 09:19:18 +08:00
Ika 5bcd4424fa
fix(css): no wrong loc info caused by front matter (#5103)
Replace front matter with whitespaces to maintain the loc info.
2018-09-19 09:18:50 +08:00
Ika 79d510cf31
fix(html): exclude comments from fragment detection (#5100)
Context: https://github.com/prettier/prettier/pull/4753#discussion_r200848784
2018-09-17 21:38:06 +08:00
Ika a5cecbdfee
docs(html): add reference for boolean attributes 2018-09-15 22:02:36 +08:00
Ika 5cd367e502
fix(typescript): no invalid parens for destructuring with default value (#5096) 2018-09-15 21:45:43 +08:00
Evilebot Tnawi 8b0bdf52be [WIP] feat: html support (#4753)
* feat: html support

* fix: support empty lines between children

* refactor: isScriptTagNode util

* refactor: rename `glimmer` and `handlebars` tests

* fix don't add newline after `directive` node

* fix: support `pre` tag

* fix: don't trim comments content

* fix: `script` and `style` tags output

* feat: indent `head` and `body` inside `html`

* fix: better handle quotes around attribute value

* feat: better handle embed

* tests: svg into html

* fix: better handle boolean and empty attributes

* chore(deps): update `parse5` to latest version

* fix: better handle empty attribute

* tests: fix

* fix: extra newline in multiline node

* fix: print `pre` and `textarea` in right way

* tests: xhtml doctype

* fix: use `>` instead `/>`

* tests: case

* refactor: remove `toLowerCase()`

* feat: support `prettier-ignore`

* tests: empty `script` and `style` tags

* fix: clean

* tests: refactor and more
2018-09-13 07:06:49 -06: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
Lucas Duailibe c083300e9d Fix debug doc printer for literalline 2018-09-10 13:14:55 -03:00
Ika 9ca10a378f
fix(typescript): add parens for complex nodes in ClassExpression (#5074) 2018-09-10 08:18:30 +08:00
Ika 4ff0f26d3e
refactor: move cli leven suggestion to options-normalizer (#5057)
Option-related processing should be done in `options-normalizer`.

- unknown flag suggestions are colored
  ![image](https://user-images.githubusercontent.com/8341033/45103027-866c7900-b161-11e8-8ee3-6467a9ca0090.png)
- unknown flags with no suggestion are now errors:
  ```
  $ bin/prettier.js --help noseminosemi
  [error] Invalid `--help` value. Expected `a flag`, but received `"noseminosemi"`.
  ```
2018-09-08 07:40:09 +08: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 1965b74e61
refactor: move index.js and standalone.js to src (#5054)
There're always 2 files that they're source code but not in the `src` directory, which makes it hard to search.

- move the content of `index.js` and `standalone.js` to `src`.
- `/index.js` and `/standalone.js` are preserved as links to not break builds that's installed from git.
2018-09-06 13:51:18 +08:00
Ika 461e6035c1
fix(typescript): preserve necessary parens for TSOptionalType (#5056) 2018-09-06 09:04:37 +08:00
Ika a1545a835a
feat(markdown): preserve math (#5050)
- preserve inlineMath (`$inline$`) and blockMath:

  ```md
  $$
  block
  $$
  ```
- side effect: `$` always needs to be escaped.
2018-09-05 21:07:37 +08:00
Evilebot Tnawi 7fd346ffa1
feat: newline and space utils to shared (#5049) 2018-09-04 23:08:37 +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
Ika 91206891cd
fix(markdown): do not add whitespaces between Latin and Hangul (#5040)
Based on https://github.com/prettier/prettier/issues/5028#issuecomment-417825085, it seems Korean text uses conventional space so we're not going to add whitespaces between Latin and Hangul.
2018-09-02 16:20:22 +08: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
Ika db2bc3636d
fix(yaml): update parsers (#5027)
- upgrade to `yaml@1.0.0-rc.8` and `yaml-unist-parser@1.0.0-rc.4`
- refactor some logic since the AST has slightly changed (ikatyang/yaml-unist-parser#82)
- unmatched aliases are now errors since it may introduce invalid AST from `yaml`
- rewrite the document separator (`...`/`---`) logic, this fixes some cases where it can use `---` but we printed `...`
- removed some unnecessary duplicate trailing newline
- trailing comments on `document` (`... #comment`) and `documentHead` (`--- #comment`) are preserved (i.e. they won't be moved somewhere)
2018-09-01 20:04:37 +08:00
Ika 165742014a
fix(markdown): preserve leading/trailing newlines in fenced code block (#5038) 2018-09-01 13:35:29 +08:00
Ika 4ce28d3ef4
fix(markdown): inline footnote def if there's only one 1-line paragraph (#5025) 2018-09-01 13:14:22 +08:00
Ika 669282e32a
fix(markdown): stably print lists in front of whitespace-only trailing newline (#5024) 2018-09-01 12:14:53 +08:00
Ika 49e2f77bff
refactor: extract options-normalizer/validator (#5020)
- Uses [`vnopts`](https://github.com/ikatyang/vnopts#readme)
- This way it should be easier to support language-specific options (https://github.com/prettier/prettier/pull/4798#issuecomment-407258477) and map the common options to language-specific options using [`forward`](https://github.com/ikatyang/vnopts#forward), e.g. `singleQuote: true` -> `"javascript/singleQuote": "js"`, `singleQuote: false` -> `"javascript/singleQuote": "none"`.
2018-08-31 11:26:07 +08:00
Ika 32390cd6a3
fix(vue): do not pass `<script src>` into multiparser (#5031) 2018-08-31 09:28:55 +08:00
Eric Sakmar 93e8b15311 verify the precedingNode type when handling import declaration comments (#5016) 2018-08-27 20:02:40 -06:00
Felix Wu 8779937a07 Bugfix/ Leave Dangle Comments in NewExpression (#5017)
```js
new Thing(/* comment */)
```

now stays the same instead of being formatted into

```js
new Thing /* comment */()
```
2018-08-27 09:23:14 +08:00
Ika 58d34bb844
refactor: language extend (#4994) 2018-08-22 10:12:57 +08: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
Ika 1790211f76
feat: support MDX (#4975)
* feat: support MDX

* refactor: flip condition
2018-08-13 22:23:09 +08:00
TitanSnow 2de54dc4d8 remove redundant ASI protection for BindExpression (#4970) 2018-08-13 22:17:28 +08:00
Ika 6ba6138d09
feat(yaml): prefer implicit key for empty value (#4972)
* feat(yaml): prefer implicit key for empty value

* fix: prefer `?` for `!!set`

* refactor
2018-08-12 13:38:14 +08:00
TitanSnow b0a33b7326 fix #4963: parens are incorrectly stripped in BindExpression (#4964)
* fix #4963

* lint code

* fix more incorrectly paren stripping

* always need parens when UnaryExpression in BindExpression

* lint code
2018-08-09 14:44:13 -03:00
Ika 53c83f97f5
fix: guess line ending before preprocess (#4957) 2018-08-09 10:51:08 +08:00
Ika 3842cbb118
fix(typescript): use the first error when both failed (#4947) 2018-08-09 10:21:00 +08:00
Ika 4d2f224919
fix(javascript): add parens for unary in bind (#4950)
* test: add tests

* fix(javascript): add parens for unary in bind
2018-08-08 23:48:12 +08:00
Ika e72cb538f9
fix: update flow support info (#4943) 2018-08-08 23:47:49 +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
Jorge Gonzalez 7d78ce68ef feat(config): support TOML configuration files (#4877)
* Add initial support for TOML in configuration files

* Missed brace

* Fix snapshots

* refactor: move loadToml to utils

* Use @iarna/toml

* Add tests for loadToml

* Fix test for CI

* Remove jest-extended

* Create snapshot for load-toml

* Add feat to docs

* lint docs

* Use @iarna/toml/parse-string

* Change path string
2018-08-03 06:27:19 -04: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
Brian Ng 1597578b05
Bump babel-parser (#4910) 2018-08-02 22:19:21 -05:00
Ika b6077e175e
fix(yaml): end comment in nested mapping (#4918)
* test: add tests

* fix(yaml): end comment in nested mapping
2018-08-02 22:38:16 +08:00
Ika 10df246772
feat(yaml): do not put singleline values on a separate line from the key (#4916)
Only apply to `alias` and `plain`/`quoteSingle`/`quoteDouble` with

- no backslash newline
- or no literal newline and `proseWrap: preserve`
- or no newline and `proseWrap: never`
- or no whitespace and `proseWrap: always`

in mapping items with implicit key, otherwise it's impossible to do prose wrapping.
2018-08-02 00:15:33 +08:00
Paul Chavard 783923a81b fix(glimmer): preserve empty text attributes (#4897) 2018-08-01 12:45:36 -03:00
Ika 1915cc3c46
chore: enable glimmer parser on preview playground (#4915) 2018-08-01 15:44:37 +08:00
Ika d83ca5a6c6 fix(yaml): prefer dash as document separator (#4921)
* test: add tests

* fix(yaml): prefer dash as document separator
2018-08-01 14:10:06 +10:00
Lucas Azzola a938076ae5
Ignore .git, .svn and .hg directories (#4906)
Fixes #4895
2018-07-30 00:08:51 +10:00
Ika 440ab4f60b
refactor: upgrade to cosmiconfig@5 (#4899)
* refactor: upgrade to cosmiconfig@5

* fix: use custom require
2018-07-29 16:57:36 +08:00
Paul Chavard 0571b2b884 fix(glimmer): treat glimmer components as self closing tags (#4900) 2018-07-27 06:49:13 -04:00
Ika 556fb3e646
feat(markdown): only align lists if they're already aligned (#4893)
* feat(markdown): only align lists if they're already aligned

* fix: handle single item with multiple leading spaces

* fix: empty items are considered not aligned
2018-07-27 09:48:09 +08:00
Paul Chavard 65d65a5c13 fix(glimmer): better formatting of boolean attributes (and also ...attributes) (#4891) 2018-07-26 09:50:45 -03:00
Paul Chavard 505e08292c fix(glimmer): add softline in nested block statements (#4896) 2018-07-26 09:49:50 -03:00
Paul Chavard ca8e049126 fix(glimmer): remove extra space from sub-expressions without params (#4890) 2018-07-24 19:50:30 -03:00
Paul Chavard 5d254ce310 fix(glimmer): do not strip block params on <Component> (#4889) 2018-07-24 19:07:49 -03:00
Ika 02f64af6e3
fix(vue): no error on range format (#4868) 2018-07-22 15:58:29 +08:00
Suchipi 3bfaf6626c
Never inline decorators, unless they're lone parameter decorators (#4830)
Fixes #2613.
2018-07-20 13:48:37 -06:00
Ika 1fe0b01bd4
fix(yaml): no wrong loc info for CRLF (#4863)
Context: https://github.com/prettier/prettier/issues/4856#issuecomment-405982539

Workaround for eemeli/yaml#20
2018-07-19 21:50:27 +08:00
Ika 1a2c4e663e
chore: use pre-release version number on master (#4855)
* chore: use pre-release version number on master

* docs: tweak comment
2018-07-18 09:38:26 +08:00
Ika cb7fe00863
fix(yaml): support end comments (#4854) 2018-07-18 09:37:53 +08: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
Prashant Andani cdcb7b11c9 Use destructures and refactor code for readability (#4844)
* Use destructuring for readability and optimzations at for loop length property

* Destructure variables for easy maintainability of code

* PR review fix

* refactor: fix linting

* Use destructures and refactor code for better readability

* Remove merge conflict line

* lint before commit
2018-07-17 18:01:44 -03:00
Prashant Andani 12cb8a9688 Use destructuring for readability and optimzations at 'for' loop length property… (#4842)
* Use destructuring for readability and optimzations at for loop length property

* Destructure variables for easy maintainability of code

* PR review fix

* refactor: fix linting
2018-07-16 22:39:41 +08:00
Ivan Babak a7bb71c7e5 fix(perf): convert traverseDoc from recursion to stack (#4776) (#4848)
In addition to a tiny performance improvement outlined below,
the CPU profile of traverseDoc is now more readable.

Also anonymous arrow functions changed to named regular functions
so that they are properly displayed in the CPU profile,
and moved to outer scope where there's no closure
so that they aren't re-created (this change's performance is dependent
on JS engine implementation and optimization details).

Before (profile):
```
7129.9 ms       5.43 %    13349.9 ms     10.18 %    traverseDocRec
7067.4 ms       5.39 %    11285.5 ms      8.60 %      traverseDocRec
  31.5 ms       0.02 %     1031.9 ms      0.79 %      traverseDoc
  23.6 ms       0.02 %    12313.4 ms      9.39 %      traverseDoc
   2.6 ms       0.00 %       0.3 ms       0.00 %      (anonymous)
   1.7 ms       0.00 %       1.7 ms       0.00 %      call
   1.6 ms       0.00 %       1.6 ms       0.00 %      call
   0.5 ms       0.00 %       0.5 ms       0.00 %      conditionalGroup
   0.4 ms       0.00 %       0.4 ms       0.00 %      printDocToString$1
   0.1 ms       0.00 %       0.1 ms       0.00 %      printGenerically
   0.1 ms       0.00 %       0.1 ms       0.00 %      t
   0.1 ms       0.00 %       0.1 ms       0.00 %      ifBreak
   0.1 ms       0.00 %       0.1 ms       0.00 %      (anonymous)
     0 ms          0 %       0.1 ms       0.00 %      forEach

```

After (profile):
```
6937.9 ms       5.37 %    12872.5 ms      9.97 %    traverseDoc
5944.0 ms       4.60 %    11047.3 ms      8.55 %      propagateBreaks
735.7 ms        0.57 %     1358.3 ms      1.05 %      findInDoc
257.9 ms        0.20 %      466.7 ms      0.36 %      findInDoc
0.1 ms          0.00 %        0.1 ms      0.00 %      has
0.1 ms          0.00 %        0.1 ms      0.00 %      printArgumentsList
```

Before (performance):
```
cat ../LspLanguageService.js | NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --stdin-filepath LspLanguageService.js --loglevel debug --debug-repeat 1000 > /dev/null
Debugger listening on ws://127.0.0.1:9229/4b52c027-ef62-49d6-8770-179e805a0f43
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
[debug] normalized argv: {"color":true,"editorconfig":true,"stdin-filepath":"LspLanguageService.js","loglevel":"debug","debug-repeat":1000,"plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","config-precedence":"cli-override","_":[]}
[debug] resolve config from '/Users/ivanbabak/_sompylasar/_github/prettier-2/LspLanguageService.js'
[debug] loaded options `null`
[debug] applied config-precedence (cli-override): {"filepath":"LspLanguageService.js"}
[debug] '--debug-repeat' option found, running formatWithCursor 1000 times.
[debug] '--debug-repeat' measurements for formatWithCursor: {
[debug]   "repeat": 1000,
[debug]   "hz": 7.774598830700336,
[debug]   "ms": 128.624
[debug] }
```

After (performance):
```
cat ../LspLanguageService.js | NODE_ENV=production node --inspect-brk ./dist/bin-prettier.js --stdin-filepath LspLanguageService.js --loglevel debug --debug-repeat 1000 > /dev/null
Debugger listening on ws://127.0.0.1:9229/aa76e134-a68c-44ed-89a8-efb68bc46baa
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
[debug] normalized argv: {"color":true,"editorconfig":true,"stdin-filepath":"LspLanguageService.js","loglevel":"debug","debug-repeat":1000,"plugin-search-dir":[],"plugin":[],"ignore-path":".prettierignore","config-precedence":"cli-override","_":[]}
[debug] resolve config from '/Users/ivanbabak/_sompylasar/_github/prettier/LspLanguageService.js'
[debug] loaded options `null`
[debug] applied config-precedence (cli-override): {"filepath":"LspLanguageService.js"}
[debug] '--debug-repeat' option found, running formatWithCursor 1000 times.
[debug] '--debug-repeat' measurements for formatWithCursor: {
[debug]   "repeat": 1000,
[debug]   "hz": 7.888114977163907,
[debug]   "ms": 126.773
[debug] }
```
2018-07-15 20:02:14 -07:00
Eugene Datsky 03ee86ea80 Blacklist this in functional composition heuristics (#4836) 2018-07-12 11:58:57 -03:00
Ika cd16ff27d7
fix(markdown): preserve entity for surrogate pair (#4832) 2018-07-12 21:42:39 +08:00
Ika da91fb2f46
fix(javascript): allow top level super and await (#4823) 2018-07-11 13:18:20 +08: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 2271992446
feat(json): add jsonc to aliases and use it to find parser in markdown embed (#4734) 2018-07-07 20:46:34 +08:00
Ika 0df2199688
fix(grahpql): linebreak in non-block stringValue (#4808) 2018-07-05 00:14:09 +08:00
Ika 432c9d7d04
feat(yaml): support proseWrap (#4742)
- support `proseWrap` in `yaml`
- move `proseWrap` to `commonOptions`
- update to `yaml@1.0.0-rc.4` and `yaml-unist-parser@1.0.0-rc.1`
2018-07-04 00:28:47 +08:00
Ika 99c4e41fa1
feat: format yaml front matter (#4773)
* refactor: front-matter

* feat: format yaml front matter
2018-07-03 09:54:40 +08:00
Lucas Duailibe 6a6e8cada0
Fix benchmark require (#4792) 2018-07-02 13:17:08 -03:00
Ika e9f489cea1
refactor(debug-repeat): use built-in int type (#4791) 2018-07-02 16:01:05 +08:00
Ivan Babak b9fb113b3b feat(benchmark): add options to measure performance (#4776) (#4789)
- `--debug-benchmark` uses `benchmark` module to produce statistically significant time measurements.
- `--debug-repeat` uses a naive loop and measures just the average run time, but useful for profiling to highlight hot functions.
2018-07-01 19:49:16 -07:00
Ivan Babak 95cc2c97b5 fix(perf): shortcut getStringWidth for ASCII-only strings (#4776) (#4790) 2018-07-01 19:47:55 -07:00
Alexander Kachkaev a05fd118be Do not require space after markdown block language name (#4783)
https://github.com/prettier/prettier/pull/4153 made it possible to detect fenced code block language when it is followed by arguments (e.g. ` ```js {something=something} `). This PR makes it also possible to detect language in cases cases like ` ```js{something=something} ` (no space).

The reason for this change is that Atom highlights code blocks regardless of a space after the language name, which makes users wonder why the correctly detected code block is not being formatted:

<img width="324" alt="screen shot 2018-06-28 at 22 08 13" src="https://user-images.githubusercontent.com/608862/42060780-db11f5b6-7b1f-11e8-9f43-fe91843f7d89.png">

PR background: https://github.com/prettier/prettier/pull/4153#issuecomment-401174999
2018-07-02 08:22:56 +08:00
Ika 9bb8edf96a
feat: support .js.flow (#4777)
* feat: support .js.flow

* feat: add Flow language entry
2018-07-01 16:18:08 +08:00
Ika 61d5eeadd3
fix(javascript): add parens for await in bind (#4778) 2018-06-30 23:15:45 +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
Lucas Duailibe 576e570711
Fix custom require's (#4766) 2018-06-28 15:56:25 -03:00
Ika 0b659b898d
feat: update linguist languages (#4741)
Context: https://github.com/prettier/prettier/pull/4734#issue-196702272

Languages should be easy to maintain now.
2018-06-28 08:24:02 +08:00
Ika b67fa907bd
fix(markdown): preserve email autolink (#4740)
```diff
 <hello@example.com>
 <mailto:hello@example.com>
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-<mailto:hello@example.com>
+<hello@example.com>
 <mailto:hello@example.com>
```
2018-06-27 08:36:51 +08:00
Warren Seine 6c482e2e6c Expose `isPreviousLineEmpty` to plugins (#4747). (#4748) 2018-06-25 23:20:00 -06: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
Evilebot Tnawi aa4ea034b3
refactor: some stuff (#4703) 2018-06-25 12:57:41 +03:00
Ika f51acf22fe
feat(vue): support pragma (#4713) 2018-06-25 10:44:00 +08:00
Ika c38e6af301
fix(yaml): add missing `since` field (#4739) 2018-06-23 17:04:47 +08: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 f53b5b8323
fix(options): inferParser for standalone (#4721) 2018-06-22 12:43:44 +08:00
Ika dcf44ffbdc
feat: support YAML (#4563)
* feat: support YAML

* fix: do not indent sequence in mappingValue

* docs: add yaml to index.md

* fix: reduce `SyntaxError: Node#parse consumed no characters`

* chore: remove old-build and new-worker.js

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* refactor

* fix: no space after `<<`

* fix: add yaml to standalone test

* test: add tests

* fix: next empty line in flow collection

* fix: tabs are not allowed
http://yaml.org/spec/1.2/spec.html#space/indentation/

* fix: update parser

* feat: rewrite the mappingItem logic
* feat: indent sequence in mapping
* feat(doc): add ifBreak#groupId and group#id

* chore: fix node 4

* chore: add tools_yaml.svg

* chore: remove resolved TODO

* refactor: remove unnecessary workaround

* chore(worker): importScriptOnce

* chore(build): rename with babelPlugins

* make it rollup compatible

* feat: support singleQuote

* refactor
2018-06-21 10:29:42 +08:00
Anthony Sottile 5d5c97a17f Fix `prettier` installed in a directory not named prettier (#4706) 2018-06-18 13:29:54 -03:00
Ika b99de9811b
feat(graphql): support pragma (#4699) 2018-06-17 14:04:48 +08:00
Ika 4109abf4dd
feat(javascript): support BigIntLiteral (#4697) 2018-06-16 00:20:04 +08:00
Evilebot Tnawi 03a2002348
fix: newline between front-matter and comment (#4701) 2018-06-15 16:27:41 +03:00
Vojtěch Štěpančík 56af3d621d Add support for parsing babylons throwExpressions (#4695) 2018-06-14 21:35:39 -03:00
Ika 18aa527adc
feat(api): support relative paths for plugin(SearchDir)s in config files (#4667)
* feat(api): support relative paths for plugin(SearchDir)s in config files

* fix: convince appveyor
2018-06-15 04:25:03 +08:00
Ika f6890bd071
feat(css): support pragma (#4688) 2018-06-14 09:51:18 +08:00
Joseph Frazier 88be12ca07
Allow `originalText` to be passed to `formatAST()` (#4677)
This allows `prettier.__debug.formatAST` to not crash when given the AST
for the below code (taken from https://astexplorer.net/), which is
useful when trying to use Prettier as a code generator for an AST
without corresponding source code (https://github.com/prettier/prettier/issues/4675)

```js
let tips = [
  "Click on any AST node with a '+' to expand it",

  "Hovering over a node highlights the \
   corresponding part in the source code",

  "Shift click on an AST node expands the whole substree"
];

function printTips() {
  tips.forEach((tip, i) => console.log(`Tip ${i}:` + tip));
}
```
2018-06-13 12:30:14 -04:00
Tony Trinh dcc060a5a5 refactor: remove redundant call to normalizeOptions (#4671)
Removes redundant call to `normalizeOptions` (already done in preceding line)

8ec5432768/src/main/core.js (L260-L263)
2018-06-12 10:56:16 +08:00
Ika 5646573ad7
fix(javascript): preserve parens for type casting for sub-item (#4648) 2018-06-11 19:50:53 +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
Ika 35a42bef24
fix(markdown): better handling for trailing spaces (#4593)
- preserve trailing spaces in html, excluding html comment
- `doc-printer` is now unrelated to `options.parser`
- fix some cases that two trailing spaces are mis-considered as `break`
2018-06-08 00:20:25 +08:00
Ika fb74dc54c3
feat(api): make `getFileInfo()` really async (#4640) 2018-06-07 00:34:02 +08:00
Aakansha Doshi 8ec5432768 Fix empty file error in json and graphql (#4553)
* Fix empty file error in json and graphql

* fix AST_COMPARE=1 issue

* use tests/empty

* revert

* fix lint
2018-06-06 10:41:12 -03:00
Lucas Duailibe a4da6e6c8e
Inline _ or $ in the root of a method chain (#4621) 2018-06-01 12:51:06 -03:00
Ika b55997eb3d
fix(multiparser): no additional trailing newline for graphql in js (#4616)
Fixes #4615

The root cause is the output doc from graphql printer does not match the desired input from `stripTrailingHardline`.

a9b21a01e2/src/doc/doc-utils.js (L167-L180)
2018-06-01 00:38:39 +08:00
Ika e74e6565b4
fix(markdown): respect blank line between block htmls (#4609)
Fixes #4605 

The AST here is actually two `html`s and it did follow the [CommonMark spec](https://spec.commonmark.org/0.28/#html-blocks), so I ended up with respecting the blank line between block `html`s.
2018-06-01 00:33:37 +08:00
Evilebot Tnawi 9387e9d833
fix: comment type for scss (#4598) 2018-05-30 23:22:18 +03:00
Ika 75e86b9e6b
fix(cli): no regression for --debug-check + --list-different (#4600) 2018-05-31 00:42:26 +08:00
Ika 8abbc5d4b0
fix(javascript): regression for `hasOwnProperty` (#4603) 2018-05-31 00:39:39 +08:00
Jimmy Jia dc5de053c4 fix: comment around color adjusters (#4595) 2018-05-29 21:03:09 +03:00
Evilebot Tnawi 3d60871458
fix: output color adjusters (#4494) 2018-05-29 15:24:38 +03:00
Lucas Duailibe 1350edc5a6 Revert no parser error for API (#4587)
* Revert no parser error for API

* use warn
2018-05-28 23:43:44 -06:00
Lucas Duailibe b8ded70848 Handle comments in assignments before template literals (#4580)
Closes #4560
2018-05-29 00:08:18 +10: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 Duailibe 9da80415f4 Bump own prettier dependency 2018-05-27 15:22:34 -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
Lucas Duailibe 52a2a46b3c
New build system (#4449) 2018-05-24 15:30:45 -03:00
Dray Lacy bb6d130b5b Fix printing of `{{{raw}}}` handlebars expressions (#4535)
Previously, `{{{raw}}}` would be output as `{{raw}}`.
2018-05-24 11:16:50 -07:00
Evilebot Tnawi 27b1005455
feat: handle `composer.json` as `package.json` (#4532) 2018-05-24 20:36:16 +03:00
Evilebot Tnawi db0278a186
refactor: math operator (#4529) 2018-05-24 20:19:22 +03:00
James Henry 88b71481fa New: Format Angular Component styles (#4361)
* New: Format Angular Component styles and template

* Clean AST

* Cleanup
2018-05-23 19:08:40 -06:00
Lucas Duailibe 5c6e0802af
Don't default parser to babylon (#4528)
* Don't default parser to babylon

* Different default values according to version

* Fix error logging

* Add tests specifically for parser inference

* Add another test case

* Add API test
2018-05-23 16:55:06 -03:00
Evilebot Tnawi 9db668702c
refactor: `less` extend (#4526) 2018-05-23 19:28:18 +03:00
Evilebot Tnawi 7a8dc82065
refactor: printer (#4501) 2018-05-22 21:10:24 +03:00
Evilebot Tnawi 0b8a8d84f6
fix: scss interpolation in string (#4490) 2018-05-22 16:05:47 +03:00
Jed Fox 9155fe5018
Rename all uses of frontmatter to frontMatter or front-matter (#4519) 2018-05-21 10:02:09 -04:00
Ika 553e9bb1ac
fix(typescript): preserve quoted class property (#4517) 2018-05-21 18:57:30 +08:00
Aakansha Doshi 31f79fbc22 Don't add new lines after unless present in graphql (#4512)
* Don't add new lines after unless present in graphql

* fix logic and add more specs

* use index
2018-05-20 13:44:49 -04:00
Ika a9eb68296c
fix(markdown): do not merge continuous cjk if proseWrap=preserve (#4504)
* test: add tests

* fix(markdown): do not merge continuous cjk if proseWrap=preserve

* fix: remove trailing comma for node4
2018-05-19 13:53:34 +08:00
Lucas Duailibe ea01781d8c
Only break chains with short names if inside ExpressionStatement (#4505) 2018-05-18 21:44:15 -03:00
Lucas Duailibe 7d50c25195
Remove unnecessary check for PRETTIER_DEBUG (#4506) 2018-05-18 18:18:12 -03:00
Joseph Frazier 6d49a224c9
Don't format range if required pragma is missing outside range (#3996)
* Add tests demonstrating --require-pragma behavior with range

* Don't format range if required pragma is missing outside range

Fixes https://github.com/prettier/prettier/issues/3985
2018-05-17 13:38:50 -04: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
Evilebot Tnawi a8b0e55205
fix: better output scss maps (#4487) 2018-05-17 13:39:22 +03:00
Suchipi ec45dc9a4c
(refactor): Move common options out of JS plugin (#4445)
* (refactor): Move common options out of JS plugin

* Add Common category to playground
2018-05-15 14:14:50 -06:00
Lucas Duailibe 7bc5ec2dc6
Preserve Liquid tags contents (#4484) 2018-05-15 14:22:41 -03:00
Brian Ng 857c55bd61
Keep parens around do-expressions inside ExpressionStatement (#4479) 2018-05-15 11:41:17 -05:00
Lucas Duailibe 983202413c
Refactor frontmatter handling (#4482) 2018-05-14 22:17:15 -03:00
Evilebot Tnawi 636ae9d037
refactor: `css` language (#4483) 2018-05-15 01:08:04 +03:00
Evilebot Tnawi 9d41f1355a
refactor: parser-postcss (#4478) 2018-05-15 00:00:45 +03:00
Aakansha Doshi f99aee8e46 refactor: use `postcss-values-parser` for `@import` at rule (#4435)
* update to postcss value parser for @import and at rule

* fix specs

* Add rule for @import url and fix specs

* fix more specs

* fix more specs

* import check

* fix specs and add more specs

* remove console.log

* review fixes

* update snapshots

* remove bad code

* fix spec

* remove code

* Add comment

* fix comment

* lint fix
2018-05-14 22:54:34 +03:00
Paco bcdb6936ba Remove unused text parameter from Comments#getSortedChildNodes (#4481) 2018-05-14 14:32:18 -03:00
Nicolò Ribaudo bcfe2257f5 Wrap ?() => T in parens when needed. (#4475) 2018-05-14 11:25:16 -03:00
Ika d0f6aac001
refactor(massageAst): move stripLocation to corresponding plugins (#4477) 2018-05-14 20:52:27 +08:00
Evilebot Tnawi 6cd6ea383e
fix: characters escaping (#4472) 2018-05-14 13:47:46 +03:00
Jed Fox dc68a3d9a6
Break link definitions onto multiple lines when needed (#3531)
* Break link definitions onto multiple lines when needed

* Simplify the conditional for breaking the title

* Don’t print the title if it’s blank

* Revert "Don’t print the title if it’s blank"

This reverts commit 2a8d0dd9995a2e5ab8e6d888c07b88dda058637f.

* Add another test

* Fix title printing

* Second time’s the charm

* Third time’s the charm?

* Fix snapshot

* Prettify

* Don’t break unless `proseWrap` is `always`

* Test `proseWrap: never` on link references
2018-05-14 06:17:37 -04:00
Ika 1062f2a889
feat: support JSON.stringify formatting (#4450)
* test: move tests

* feat: support legacy JSON formatting

* fix: add missing assertion

* test: fix coverage

* fix: same output as JSON.stringify

* refactor: fix linting

* refactor: rename to json-stringify

* refactor: fix linting

* fix: should fix the production build

* docs: remove outdated name

* fix(playgound): add lib/parser-json-stringify.js

* feat(playgound): add example for json-stringify

* fix: no error on singleQuote string

* fix(playground): correctly load json-stringify

* fix: identifier is only allowed in ObjectProperty.key

* refactor: clearer
2018-05-14 09:12:25 +08:00
Evilebot Tnawi bc2f57dcf9
fix: css variables and scss interpolation (#4471) 2018-05-12 22:38:28 +03:00
Elias Meire 2f5c00ad18 Fix: not greedy match the frontmatter in postcss parser (#4457) 2018-05-10 13:50:19 -03:00
Ika 6447d30b0b
feat(markdown): change unordered list symbol to hyphen (#4440) 2018-05-10 14:32:52 +08:00
Alexander Kachkaev bc78541274 Improve plugin resolution when path does not start with ./ (#4451)
* Fix plugin resolution when path does not start with ./

* Minor consistency fix: use "if (resolvedPluginSearchDir) {...}" in load-plugins

* Use more appropriate quotes in plugin-resolution.js

* Try both local paths and node modules when resolving plugins manually

* Test bespoke plugin loading by node module name

* Simplify getFileInfo() as suggested by @j-f1

https://github.com/prettier/prettier/pull/4341#discussion_r187112707
2018-05-10 10:27:41 +10:00
Ika 0f02940de2
refactor(javascript): move loc util (#4443) 2018-05-10 02:23:40 +08:00
Alexander Kachkaev cc734753fc Implement prettier.getFileInfo() method and --file-info CLI option (#4341)
* Implement prettier.getFileInfo() method and --file-info CLI option

* Add empty line between functions in index.js

* Support --plugin-search-dirs / pluginSearchDirs() in --file-info / getFileInfo()

* Address review comments by @ikatyang
2018-05-10 00:53:44 +08: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
Alexander Kachkaev 7345a38e64 Fix plugin API in globally installed Prettier and introduce optional --plugin-search-dir (#4192)
* Fix plugin API in globally installed Prettier and introduce optional --plugin-search-dir

* Use find-parent-dir instead of find-up and test autoloading (with mocked fn)

* Add two test cases where --plugin-search-dir is not .

* Do not mutate pluginSearchDirs argument in load-plugins.js

* Do not test automatic plugin resolution as mocking of "find-parent-dir" does not work due to rollup

* Document --plugin-search-dir / pluginSearchDirs and improve spacing

* Address @ikatyang's review comments

* Fix require path for third-party

* Undo alphabetic sorting of third-party scripts
2018-05-09 19:17:12 +08:00