Commit Graph

1127 Commits (47430d0c19ee4940494df1645df0df8fecd9f3d8)

Author SHA1 Message Date
Ika d08df0b221
fix(markdown): handle punctuation variants (#3254)
* fix(markdown): handle punctuation variants

* docs: add comment
2017-11-13 00:09:04 +08:00
Lucas Duailibe ece764a049
Preserve intentional new lines in GraphQL (#3252)
* Preserve intentional new lines in GraphQL

* Move function to bottom

* Rename arg

* Refactor

* Add comments in tests and support for arguments
2017-11-12 02:10:54 -02:00
Ika bddbd1914d
fix(markdown): no extra whitespace between ascii punc and CJK char (#3249)
* fix(markdown): no extra whitespace between ascii punctuation and CJK character

* test: update snapshot
2017-11-12 00:38:18 +08:00
Ika 4ae52c5aa6
fix(markdown): do not enable splitText in inlineCode (#3243) 2017-11-12 00:29:59 +08:00
Ika 1cde865a11
fix(markdown): no extra whitespace between non-cjk and cjk-punctuation (#3244)
* fix(markdown): no extra whitespace between non-cjk and cjk-punctuation

* fix: no node v4 unsupported feature
2017-11-12 00:08:24 +08:00
Ika 4c6a7e8749
fix(markdown): escape all emphasis-like text (#3246)
* fix(markdown): escape all emphasis-like text

* test: add test case
2017-11-12 00:07:58 +08:00
Ika 92459047ed
fix(markdown): force print spaces (#3225) 2017-11-11 15:05:07 +08:00
Ika 49f578fb91
fix(markdown): do not break `inlineCode` (#3230) 2017-11-11 12:50:40 +08:00
Lucas Duailibe 658886aab1
Prevent adding semi in TypeScript interfaces when type has prettier-ignore (#3103) 2017-11-09 21:52:47 -02:00
Mitermayer Reis 813d9b93eb Fix typos (#3212)
* Adding --stdin-filepath option in order to enable filetype inference from
stdin

* Fixing typo on the documentation

* Fixing typos - fixing some typos

* Restoring static lib files back since they are artifacts
2017-11-09 11:44:24 +11:00
Ika 7fb8e3fe43 fix(markdown): no break on link (#3204)
* fix(markdown): link/image url head is breakable

* fix(markdown): no break on link
2017-11-09 08:19:35 +11:00
Ika 4f1a2c4108 feat(markdown): add `--no-prose-wrap` option (#3199)
* feat(markdown): add `--no-prose-wrap` option

* refactor: fix typo

* refactor: fix typo

* refactor: reduce duplicate code

* docs: mention the option is for markdown
2017-11-08 21:01:06 +11:00
Lucas Duailibe a35257bacf Print JSON top comments as leading comments of root node (#3187)
* Make JSON top comments be leading comments of root node

* Update snapshot
2017-11-08 09:01:09 +11:00
Lucas Duailibe 68a99cf4b2 Parenthesis around TSAsExpression inside TSAbstractClassDeclaration (#3191) 2017-11-08 08:59:15 +11:00
Ika ec7eced099
test: lowercase the test file to avoid cross platform issue (#3189) 2017-11-07 22:07:01 +08:00
Ika 18345817d8 fix(markdown): allow more cases that `_`-style emphasis is available (#3186)
* fix(markdown): add more cases `_`-style emphasis is available

* refactor: fix naming style
2017-11-07 23:33:29 +11:00
Lucas Duailibe 49b07c3983 Don't add trailing commas in JSXAttribute for arrow functions (#3181) 2017-11-07 22:37:36 +11:00
Ika ffd198beaa fix(markdown): handle additional spaces before `code` (#3180)
* fix(markdown): handle additional spaces before `code`

* test: update snapshots

* fix: ignore leading `\n` from indented `code`

* docs: add comment
2017-11-07 22:25:20 +11:00
Lucas Azzola e733a7706d
Force JSON to no trailing comma in multiparser (#3182)
* Force JSON to no trailing comma in multiparser

* Switch to mutate next.options
2017-11-07 22:01:40 +11:00
Ika 9d616817be fix(markdown): do not break on unbreakable place (#3177) 2017-11-07 21:10:41 +11:00
Ika 2bdb652667 fix(markdown): do not break before special prefix (#3172)
* fix(markdown): do not break before special prefix

* fix: add more cases
2017-11-07 20:40:09 +11:00
Lucas Duailibe 8249b1c841 Add support for JSXSpreadChild and fix comments inside JSXSpread (#3163)
* Add support for JSXSpreadChild and fix comments inside JSXSpread

* Dangling comments

* Use another approach
2017-11-07 14:23:10 +11:00
Lucas Duailibe 2c5a792d9a fix(jsx): Break opening elements with single text attribute if there's a comment (#3154)
* fix(jsx): Break opening elements with single text attribute if there's a comment

* Single text attribute with a comment on the JSXElement name

* Consolidate rules of comments in JSX
2017-11-07 08:05:59 +11:00
Ika 1d4848b37c chore(deps): upgrade patch-level dependencies (#3153)
* chore(deps): update jest-docblock to 21.3.0-beta.7

* chore(deps): upgrade patch-level dependencies

* test: update snapshot
2017-11-07 00:38:37 +11:00
Ika ec8deb6c0b fix(markdown): print `---`-style thematic break (#3148)
* fix(markdown): print `---`-style thematic break

* test: fix diff
2017-11-05 20:50:10 +11:00
Christopher Chedeau ec18ebc6c6
[Graphql] Escape strings (#3143)
When I ran it on all the graphql files of fb, none of them had escape, but someone reported this issue!
2017-11-04 11:04:45 -07:00
Lucas Duailibe 1dfffd14e7 Don't inline trailing } for arrow functions in JSX 2017-11-04 01:52:27 -02:00
Lucas Duailibe 979b86944d Consider [0] to be part of the first member group 2017-11-02 14:42:13 -02:00
Lucas Duailibe 538ce6d209 Preserve line breaks in css grid declaration 2017-11-02 00:21:41 -02:00
Lucas Duailibe 21c6d4f501 Prevent inlining JSXAttribute if it has comments (#3132) 2017-11-01 09:56:04 -06:00
Lucas Duailibe 38b15f7899 Improve template literal expresions line breaks (#3124) 2017-10-31 14:31:27 -06:00
Christopher Chedeau 777090ca99
Make the factory detection handle multiple elements (#3112)
This was only accounting for a single element in the first group. Now it handles arbitrary elements. Only the last element being capitalized matters.

This fixes one issue in #3107
2017-10-27 09:05:40 -07:00
Lucas Duailibe 6ccf5c0246 fix(jsx): Don't inline trailing } for arrow functions attributes (#3110) 2017-10-26 11:32:57 -06:00
Lucas Azzola 1d3c86be4d Fix util.getStringWidth for falsy input (#3092) 2017-10-24 15:19:27 +11:00
Lucas Azzola c0aaa0fa52 Don't print JSX bracket on same line when it has trailing comments (#3088) 2017-10-23 17:13:12 +11:00
Ika 11d7213862 test(markdown): rename test case to avoid confusing (#3086) 2017-10-23 09:49:13 +08:00
Lucas Duailibe 878412c680 Break parens for binaries in member expression (#2958)
* Break parens for binaries in member expression

* Add test case

* Update snapshot
2017-10-22 17:29:13 -06:00
Cyril Junod e589babeaf Split source elements relative to their language. (#3069)
* Split source elements relative to their language.

Colliding node types which are not source elements in every language.
Example ObjectExpression in JSON / JS

* Node4's Array.prototype.includes

* Ensure there is no confusion

ObjectExpression vs BlockStatement & LabeledStatement
2017-10-22 20:04:06 +11:00
Karl O'Keeffe fa83ce3f3f Fix calculation of whether doc parts fit (#3081) 2017-10-22 07:54:23 +01:00
Andy Mockler c6d97abf95 Format SCSS maps like CSS rules (#3070)
* Format SCSS maps like CSS rules

* Ensure parent value starts with $ before formatting map with hardlines
2017-10-22 12:35:22 +11:00
Lucas Duailibe b53a426e15 Prevent breaking MemberExpression inside NewExpression (#3075)
* Test case

* Prevent breaking MemberExpression inside NewExpression
2017-10-22 10:30:05 +11:00
Mutasem Aldmour 54bdd30595 Fix first argument left behind when line breaks (#3079)
* fixing issue #2984

* removed typescript from test #2984

* prettier

* removed obsolete test copied from another

* added verification parsers

* added new line
2017-10-21 23:12:26 +11:00
Lucas Duailibe 465729685f Fix indentation of intersection object types (#3074) 2017-10-21 17:45:41 +11:00
Brian Ng 12f028cd46 Fix formatting styled(Foo).attrs(...)`` (#3073) 2017-10-21 09:10:55 +11:00
Jacky Ho 5b7b012fcd Account for empty lines in long member call chain (#3035)
* Account for empty lines in member chain

* Add tests

* Account for parens

* Improve tests

* Add some comments

* Remove an outdated comment

* Fix lint errors

* Refactor a line of code

* Add one more comment for clarification
2017-10-19 09:25:51 +11:00
Lucas Azzola 7162e1ecc8 Keep parens around TSAsExpression in ConditionalExpression (#3053) 2017-10-18 20:03:58 +11:00
Lucas Azzola 624d89e7a5 Print pipeline and nullish-coalescing operators (#3036) 2017-10-16 09:13:25 +11:00
Brian Ng d90aec1a1d Add test for nested ternary with arrow func (#3039) 2017-10-16 09:09:57 +11:00
Ika c27cc7ff45 feat(markdown): support CJK and emoji (#3026)
* refactor: extract `splitText`

* fix: respcet CJK width in table

* test: add failing test

* fix: support emoji

* test: add failing test

* feat: support CJK character

* feat: enable adding whitespace between non-CJK/CJK-character by default

* fix: do not print softline at node that is sensitive to its identifier

* fix: treat full-width whitespace as CJK punctuation

* disallow leading/trailing full-width whitespace

* feat: remove `--split-cjk-text` option and enable it by default

* refactor: simplify regex and remove unnecessary `g` flag
2017-10-14 23:57:31 -05:00
Ika c3b965145b feat(markdown): auto-detect which number style of ordered list to be used (#3029) 2017-10-14 22:53:58 +11:00
Ika c4118edbe7 fix(markdown): print auto-link as-is (#3032) 2017-10-14 22:49:12 +11:00
Ika 5c789b2dfc fix(markdown): use the most popular unordered list style (#3027) 2017-10-14 22:41:25 +11:00
Ika f009a96ae4 fix(doc-printer): use `string-width` (#3015)
* refactor(doc-printer): use `string-width`

* test: add test case
2017-10-12 02:27:02 -05:00
Ika 9f6f3e7355 feat: support markdown (#2943)
* feat(markdown): inital implementation

* feat(markdown): support strong

* fix: add missing default value

* feat(markdown): support inlineCode

* feat: support delete

* feat: support link

* feat: support image

* feat: support blockquote

* feat: support heading

* feat: support code

* feat: support yaml

* feat: support html

* feat: support list

* feat: support thematicBreak

* feat: support table

* feat: support linkReference

* feat: support imageReference

* feat: support definition

* feat: support footnote

* feat: support footnoteReference

* feat: support footnoteDefinition

* test(cli): update snapshots

* refactor: extract SINGLE_LINE_NODE_TYPES

* refactor: printChildren

* fix: correct newlines

* test: add trailing newline

* fix: blockquote formatting

* fix: node types

* fix: break line correctly

* fix: remove unnecessary properties to make AST_COMPARE happy

* fix: escape `|` in tableCell content

* fix: unexpected line break

* fix: ast difference from loose list

* fix: html break lines

* refactor: fix linting

* fix: normalize ast

* fix: escape specific chars

* test: add more tests

* fix: build markdown parser

* chore: remove unnecessary *.log

* fix: escape html entity

* feat: support prettier-ignore

* fix: line break for non-loose listItem

* feat: support formatting `code` based on `lang`

* fix: add `jsx` and `tsx`

* fix: use multiparser

* refactor: fix linting

* test: update test case 😉

* feat: switch to `_` style emphasis

* fix: sequence list should use different prefix

* test: add tests

* fix: do not print additional new line after `prettier-ignore`

* fix(list): enforce `1.` to avoid unnecessary git diff

* feat: enable `commonmark` option

* feat: support `break`
* fix: escape backslash
* refactor: escape html entity using backslash

* fix: respect autolink-style link

* feat: support md`...` and markdown`...`

* docs: replace ands with commas

* fix: respect indented code block

* fix: respect html entity

* docs: add docs for modified MDAST

* fix: inlineCode is breakline-able

* feat: support backtick in inlineCode

* feat: support a-lot-of-backtick in fenced code block

* feat: use `~~~`-style code block in js template

* fix: respect escaped chars

* fix: use `*`-style emphasis for invalid `_`-style output

* test: add test cases

* fix: use `- - -`-style thematicBreak to avoid conflict with yaml

* fix: remain the same content for linkReference identifier

* fix: `inlineCode` gap can be a line break

* fix: `html` should not print trailing spaces if it's in root

* refactor: fix typo

* fix: wrap `definition`'s url if there's whitespace

* fix: remove unnecessary whitespace at the end of paragraph

* fix: fix: remove unnecessary whitespace at the start of paragraph

* fix: setence children length is possible 0

* fix: support continuous ordered list

* fix: do not print addtional hardline after loose list

* fix: use double-backtick style for single-backtick value in inlineCode

* fix: support nested emphasis

* fix: support space-url in link/image

* fix: escape `)` in link/image url

* fix: support single-quote in link/image/definition title

* fix: respect alt in image/imageReference

* fix: use `*`-style thematicBreak in list

* fix: loose/tight list linebreaks

* fix: print third linebreak before indented code block with a tight list in the previous

* test: move bug cases

* fix: remove unnecessary linebreaks

* refactor: fix typo
2017-10-12 09:46:44 +11:00
Marshall Bowers 445f51709e Fix indentation for JSDoc comments (#2470)
* Fix TypeScript comment snapshot

* Add failing test for TypeScript method comments

* Remove trailing space in comment

* Add snapshot for comment with many lines

* Add TODO marking potential location for comment re-indentation

* Update snapshot

* Indent comments based on the parent node

* Only adjust indentation if the comment looks like a JSDoc comment

* Only strip leading spaces when adjusting comment indentation

* Update snapshot

* Add test to show incorrect indentation based on parent node

* Update snapshot

* Update snapshot

* Update comment indentation to not rely on the parent node

* Extract code for getting the indent size

* Add test where the parent indentation changes as well

* Fix lint warning regarding lexical declarations within case block

* Update lockfile

* Update snapshot

* Add test case for block comment inside of a method

* Replace spread operator with `concat`

* Use `align` instead of `addAlignmentToDoc`

* Add test for mismatched indentation within JSDoc comment

* Always add a leading space to subsequent lines in a JSDoc comment

* Refactor JSDoc comment printing into a separate function

* Remove unneeded `align`

* Replace `forEach` with `map` for better style

* Only `trimLeft` when the end comment token is on the last line of the comment

* Remove unneeded `docBuilders`

* Add tests for JSDoc comments in JSX

* Update snapshots
2017-10-08 20:34:24 +11:00
Chris Voll 4a6b61aaf3 fix: support sequential CallExpressions in member chains (#2990)
* fix: support sequential CallExpressions in member chains

fixes #2832

* test: add additional test cases for sequential CallExpressions

* test: regenerate method-chain snapshot
2017-10-08 12:12:17 +11:00
Lucas Azzola 23f7e92162 Handle comments between function name and open paren (#2979) 2017-10-06 20:07:58 +11:00
Jake 50f3e646c7 Add option to insert @format to first docblock if absent (#2865)
* Add option to insert @format pragma if absent

prependPragma --> insertPragma

add tst dir, move stripBom, add to README, update snapshots

remove noise from test + update snapshots

use jest@test new functions, update docs, rerun snapshots

fix accidental upgrade to jest@test

update jest-docblock again to latest with strip()

updated snapshot

* updated snapshots

* revert jest dep change

* apply a trim to parsed comments

* remove empty object

* Revert "apply a trim to parsed comments"

This reverts commit 467f71ce5f4b4f8a1b5c4474ee0484bc96c92141.

* rerun snapshots with proper jest version

* pin jest-docblock to latest @test release

* comment out docs for new feature from readme

* remove leading newlines

* ensure blank line between docblock and rest of file

* remove backtick string
2017-10-06 19:37:14 +11:00
Lucas Duailibe f82fcbc98e Prevent formatting GQL template literals with expressions (#2975)
* Prevent formatting GQL template literals with expressions

* Remove unnecessary check

* Change quasis check to expression check
2017-10-05 11:23:57 +11:00
Alex Rattray a7223d8262 Merge pull request #2973 from karl/jsx-collapse-multiple-jsx-whitespaces
Collapse multiple JSX whitespaces
2017-10-03 23:31:16 -07:00
Karl O'Keeffe e9b82074a6 Collapse multiple JSX whitespaces 2017-10-03 21:15:49 +01:00
Simon Lydell fcdf6b5806 Add test for #2880 (#2959)
I added the test in css_case/case.less because it also tests that
`!important` is lowercased in this case.
2017-10-02 21:17:08 +02:00
Simon Lydell 43cb08c45c Make production tests always run against dist/ (attempt 2) (#2942)
* Make production tests always run against dist/

* Try to mock process.stdin instead of get-stream

* fix: mock `get-stream` from `index.js`

* refactor: remove unnecessary variable

* Try `transform: {}` in jest.config.js

* Add comment explaining the unusual get-stream mocking
2017-10-02 17:58:55 +02:00
Lucas Duailibe 2466ce11a5 Force template literals to break after ` for sytled-components (#2926)
Force template literals to break after ` for styled-components
2017-10-02 17:55:42 +02:00
Lucas Azzola 264ec70999 Don't use parens with optional chaining meber expressions (#2921) 2017-09-28 17:46:47 +10:00
Lucas Duailibe 038d02b3e2 Revert "Fix line break in test declarations with a single argument function declaration" (#2912)
This reverts commit 3703cb5b07.
2017-09-27 21:32:34 +02:00
Lucas Azzola 11a7b8d308 Fix printing of comments between decorators and method names (#2906) 2017-09-28 00:03:11 +10:00
Lucas Azzola f77e471b0c Upgrade to ts2.5.3-insiders (#2842) 2017-09-27 15:43:17 +10:00
Lucas Duailibe 3703cb5b07 Fix line break in test declarations with a single argument function declaration (#2877) 2017-09-26 19:24:25 +02:00
jackyho112 88049a3d6b Keep original empty lines in argument list (#2763)
* Account for empty lines in argument list in typical cases

* Fix build errors

* Fix one more build error

* Refactor

* Have better variable names for printing argument list

* Account for feedback on argument list empty lines

* Improve expanion argument logics

* Add a lot more tests

* Improve a test

* Make code cleaner

* Fix a lint error

* Refactor

* Add one last check

* Refactor
2017-09-26 17:47:56 +02:00
Lucas Azzola daef144102 Support fit(), xit(), it.only(), etc (#2900) 2017-09-26 23:12:38 +10:00
Stephen Scott e1c2085d2e Merge pull request #2888 from motiz88/fix-2593
Use semicolons in Flow interface-like bodies (#2593)
2017-09-25 22:31:24 -07:00
Simon Lydell c6bac7cfe6 Split Less and SCSS parsing into different parsers (#2844)
* Split Less and SCSS parsing into different parsers

Now, .less files are always parsed with postcss-less, and .scss files
areare always parsed with postcss-scss. This:

- Is less hacky.
- Is meant to avoid issues like #2829.
- Is probably more performant.

`parser: "postcss"` and `--parser postcss` continue to work like before:
First trying postcss-less, and if that fails, postcss-scss, unless a
regex says that we should try in the opposite order. The new values for
the parser option are "postcss-less" and "postcss-scss".

* Remove postcss from package.json since it is not used

* Rename parser-less to less and parser-scss to scss

* Deprecate parser:postcss in favor of parser:css

* Fix CSS tests
2017-09-26 07:08:11 +02:00
Ika 70f5165bb1 fix(typescript): allow symbol type (#2899) 2017-09-26 12:34:31 +10:00
Moti Zilberman 5e146cdabe Use semicolons in Flow interface-like bodies (#2593)
Closes #2593.
2017-09-25 12:45:40 +01:00
Simon Lydell cd4d4e7273 Don't lowercase SCSS placeholder selectors (#2876)
Fixes #2872.
2017-09-21 20:23:22 +02:00
Lucas Duailibe 9b0d6b8de0 Fix different precedence binary expression when inlining (#2827) 2017-09-20 17:07:51 +02:00
Brian Ng 2be986d0d7 Add support for ClassPrivateProperty (#2837) 2017-09-19 21:41:24 +02:00
Simon Lydell fb55367633 Don't lowercase Less variables when parsed with SCSS parser (#2833)
Fixes #2829
2017-09-15 19:48:16 +02:00
Simon Lydell 23041e2113 Don't lowercase `&class` in SCSS/Less selectors (#2834)
Fixes #2830
2017-09-15 19:48:04 +02:00
Brian Ng 5bd8ca472b Bump Babylon (#2831) 2017-09-15 17:26:35 +02:00
Simon Lydell ec4abdfb1e Don't lowercase CSS custom media names (#2822)
Fixes #2820. While that issue is about `@media (--fooBar)` in
particular, this commit changes to never lowercase stuff starting with
`--` in general, as it seems like those `--customStuff` things can pop
up kind of anywhere.
2017-09-14 21:55:11 +02:00
Simon Lydell 9c598b1846 Adjust quotes in some more cases of `@import` in CSS (#2818)
Fixes #2817.
2017-09-14 14:04:04 +02:00
Will Binns-Smith d5e5d66407 Add option to require @prettier or @format pragma (#2772)
* Add option to require @prettier or @format pragma

Fixes #2397.

Inspired by `eslint-plugin-prettier` and the discussion in #2397, this
implements requiring a special comment pragma to be present in a file's
first comment in order to be formatted.

This will help large codebases gradually transition to prettier over
time without tons of churn or large code reviews.

I implemented this as a standard prettier "option", not just a typical
`argv` flag, as it is relevant in both the cli and the api. This way it
can be provided programmatically, on the command line, or standardized
in a prettierrc file so like the style options, every user can use this
setting consistently and only apply prettier to relevant files, no
mattier their editor integration.

This requires the pragma begin with `@` (in fact it's inserted if the
user doesn't provide it). Currently the usage implies it must be
"prettier" or "format", but it can technically be any value other than
"none", which is similar to the `trailingCommas` option.

cc @vjeux

* Don't quote anything in runPrettier; this is usually handled by a shell

* Make --require-pragma a boolean option

* Use jest-docblock to find pragmas without parsing the ast

* Clarify docs

* includes -> indexOf

* Move test out of integration
2017-09-13 09:03:18 -07:00
Lucas Azzola 3f74c45b91 Support graphql(schema, `query`) (#2781) 2017-09-11 20:18:11 +02:00
Lucas Duailibe 902f7f0339 Use same logic for binary chain 2017-09-10 15:00:52 -06:00
Lucas Duailibe 1b2127efb6 Update snapshot 2017-09-10 15:00:52 -06:00
Lucas Duailibe bd78572b19 Break closing paren of ConditionalExpression in member chains 2017-09-10 15:00:52 -06:00
Lucas Duailibe 955a2c1472 Keep conditional expressions in one line on method chains (#2784)
Fixes #2775.

This commit will make conditional expressions to match the behavior of
logical expression in method chains:

```js
(a ? b : c).map()

// if the conditional fits in oneline
(a ? b : c)
  .map()

// if the conditional doesn't fit
(a
  ? b
  : c)
  .map()
```
2017-09-10 08:34:55 -07:00
Lucas Duailibe bba7dcf498 Fix break on conditional expressions inside return
Fixes #2777

Since we can't break after `return` and don't add `()` around
ConditionalExpressions' tests, we end up with some weird indentation when
breaking.
2017-09-10 04:13:47 -06:00
jackyho112 302de60bdc Fix comment style when placed after if statement test (#2675)
* Fix comment style when placed after the test of an if statement

* Add tests

* Do a bit of refactoring

* Fix lint errors

* Handle skipping comments

* Account for multiple-line comments

* Add more tests

* Change function name

* Add more tests

* Refactor

* Add some comments

* Do away with getPreviousNonSpaceNonCommentCharacter

* Improve comment and code on handling if statement comments

* Refactor

* Fix a bug
2017-09-08 10:12:10 -07:00
Lucas Duailibe 2c37697f82 Fix chained logical expressions with objects/array/etc inlined 2017-09-07 21:57:07 -06:00
Lucas Duailibe f964be5f8a Remove unnecessary tests 2017-09-07 21:29:53 -06:00
Lucas Duailibe 541e929b43 Change how JSX mode is activated in ternaries 2017-09-07 21:29:53 -06:00
Lucas Duailibe 15989df6e1 Group last argument if it's an empty object with a comment (#2758) 2017-09-05 12:22:25 -07:00
James Henry 9c4ec68afd Fix: TypeScript never keyword (fixes #2718) (#2756) 2017-09-05 11:37:22 -07:00
Roman Kurbatov 01387bc9d1 fixes dynamic imports (#2748) 2017-09-05 11:57:36 +10:00
Simon Lydell 368522cf33 Normalize CSS case (#2736)
Fixes #2653.
2017-09-03 21:22:28 +02:00
Christian Wesselhoeft 87401de0a5 Handle +/- before numbers in CSS (#2713)
* src/util: Fix negative number handling

* src/util: Handle decimal numbers with leading plus sign

* src/util: Handle sign symbols before numbers in scientific notation
2017-08-30 20:26:11 +02:00
Brian Ng 9533c17827 Fix printing declare modifier for TS enum (#2711) 2017-08-30 08:14:26 -07:00
Brian Ng 123bc5d5ff Ensure parens around LogicalExpression inside ExperimentalSpreadProperty (#2710) 2017-08-30 08:10:36 -07:00
James Henry 987b931215 Fix: Union type with type params regression (#2688) 2017-08-28 18:37:12 -07:00
Lucas Azzola 2e828de76f Print 3 or more chained calls on multiple lines (#2673) 2017-08-27 09:44:44 -07:00
Lucas Azzola 1e2da6c727 Support TypeScript 2.5 RC (#2672) 2017-08-26 05:36:50 -07:00
Lucas Azzola dd84559991 Merge computed MemberExpression in member chain (#2670) 2017-08-26 05:35:05 -07:00
Christopher Chedeau 0d38136115 Put parenthesis after return when jsx is prettier-ignored (#2665) 2017-08-24 19:29:05 -07:00
Christopher Chedeau 0ee74a8d25 Do not swallow prettier-ignore comments (#2664) 2017-08-24 18:57:01 -07:00
Christopher Chedeau f7bd74ed98 Fix fatal with empty jsx (#2663) 2017-08-24 18:02:44 -07:00
Christopher Chedeau ab91f6f8be Fix interleaved comments in class decorators (#2661)
I wrote this fix a while ago but it conflicted with the class heuristic, now that #2660 fixes it, we can ship this one as well!

Fixes #1460
Fixes #2507
2017-08-24 16:04:02 -07:00
Christopher Chedeau 05b4422e4f Better fix for class comments (#2660)
We used to be very naive and just push all the comments at the top of the class, but it's very brute force (and breaks some flow annotations inside of fb) so we can do better :)
2017-08-24 15:45:28 -07:00
Simon Lydell 302d1d89cb Switch to postcss-values-parser with support for exponential notation 2017-08-22 18:50:10 +02:00
Simon Lydell e5f84467b7 Normalize numbers in CSS like JS
Unlike JS, `1.0` is also normalized to `1`.
2017-08-22 18:50:10 +02:00
Simon Lydell 5f95e68913 Quote unquoted CSS attribute values in selectors (#2644) 2017-08-22 09:45:15 -07:00
Simon Lydell 876dfe6398 Work around issue #2584 (#2652)
parser-postcss parses `@import` at-rules specially, and unfortunately
buggily. This monkey-patches parser-postcss to parse all at-rules the
same way.

Fixes #2584.

postcss-less bug: https://github.com/shellscape/postcss-less/issues/88
2017-08-22 09:44:25 -07:00
Simon Lydell 3e924474cd Print sub-nodes of `@import` in Less (#2646)
Fixes part of #2584.
2017-08-21 12:28:22 -07:00
jackyho112 b77b1c82a7 Strip away unnecessary quotes in keys in type objects and interfaces (#2643)
* Use printPropertyKey function to print keys in object type property in TS and Flow

* Remove flow test modification

* Add tests for new object key cases

* Add new test file

* Fix some styles
2017-08-21 20:08:38 +10:00
Simon Lydell 9e16dbbde7 Adjust some more quotes in CSS 2017-08-17 08:59:56 +02:00
Simon Lydell c198c33700 Merge pull request #2624 from lydell/css-strings
Normalize quotes in CSS like in JS
2017-08-15 16:07:06 +02:00
Simon Lydell 4979f58c15 Normalize quotes in CSS like in JS 2017-08-14 09:14:57 +02:00
Lucas Azzola 0b9fbf940f Support styled.div.attr({})`...` (#2619) 2017-08-13 13:52:24 +10:00
Lucas Azzola ec85cf0f0a Do not accept declare on previous line (#2618) 2017-08-13 13:47:48 +10:00
Dmitry Korlas f738a214d3 fix cut off line-break in scss between comment and followed @else (#2600)
* fix cut off line-break in scss between comment and followed @else

* fix cut off line-break in scss between comment and followed @else (CR fixes)
2017-08-08 12:07:47 +10:00
Lucas Azzola e378f5e9ba Implement proposal-optional-chaining (#2572)
* Implement proposal-optional-chaining

Closes #2568

* Refactor optional token printing
2017-08-03 17:38:02 +10:00
Brian Ng 1701f4a0d5 Print declare for TSInterfaceDeclaration (#2574) 2017-08-02 00:00:01 +10:00
Brian Ng 4c335cae0a Add support for printing optional catch binding (#2570) 2017-07-31 14:40:14 -06:00
Lucas Azzola 58edd0d3f3 Keep parens around FunctionTypeAnnotation inside ArrayTypeAnnotation (#2561)
Without this, this:

    const actionArray: (() => void)[] = [];

is formatted as:

    const actionArray: () => void[] = [];

Fixes #2559
2017-07-30 00:50:38 +10:00
Lucas Azzola af6b020f7e Support styled-components with existing component (#2552)
Supports the syntax:

```js
styled(ExistingComponent)`
  css: property;
`;
```

Fixes #2545
2017-07-28 19:04:17 +10:00
Brian Ng 24e1aec306 Add support for flow opaque types (#2543) 2017-07-25 19:47:54 -07:00
Brian Ng cf6258ab4f Re-enable flow-jsx-func-attr test (#2541) 2017-07-26 09:07:37 +10:00
Brian Ng 60f5836b37 Add support for flow export type star (#2542) 2017-07-26 09:00:20 +10:00
Yang Su 26842e4d69 Handle closure compiler type cast syntax correctly (#2484)
* Handle closure compiler type cast syntax correctly

Fixes https://github.com/prettier/prettier/issues/1445

* Move closure type cast detection to needParens in fast-path.js

* every => some and added additional check for leading comment
2017-07-25 11:21:25 +10:00
Lucas Azzola a666a29aa3 Print semi after DeclareFunction, fixes #2534 (#2536) 2017-07-24 21:55:16 +10:00
Joseph Frazier a78d1389f6 Use babylon.parseExpression for JSON (#2476)
* Add comments showing parser arguments

Since this is how they are invoked, the comments make it easier to maintain.

* Use babylon.parseExpression for JSON

See https://github.com/prettier/prettier/issues/2378#issuecomment-314600778

Note that this doesn't yet print comments:

    echo '{/*comment*/"K":"V"}' | ./bin/prettier.js --parser json

* Remove parser-json.js

This reduces duplicate code in the built package.
See https://github.com/prettier/prettier/pull/2476#pullrequestreview-50181398

* Add test with block comment in JSON

* Fix test with block comment in JSON

* Add test with line comment in JSON

* Don't build now-redundant parser-json.js
2017-07-24 11:43:49 +10:00
Lucas Azzola 4a0e9475df Print parens around type assertion as LHS in assignment, fixes #2521 (#2525) 2017-07-20 23:16:15 +10:00
Lucas Azzola 02639da9a9 Improve coverage and remove some dead code (#2504)
* Improve test coverage

* Clean up some un-used code

* Lower patch requirements on codecov
2017-07-17 23:31:42 +10:00
Lucas Azzola d62d1c5c56 Preserve parens with keyof, enforce parens with arrows with type params (#2503)
* Force parens around argument of simple arrow function if type annotation is present

* Preserve parens inside keyof operator
2017-07-17 13:32:33 +02:00
Lucas Azzola 71b2004391 Cleanup unused nodes, and turn on importMeta babylon plugin (#2498)
* Cleanup unused AST nodes

* Add tests for JSXNamespacedName

* Turn on importMeta babylon plugin

* Add tests for DeclareTypeAlias

* Add back TS*Keyword nodes, fix TS optional destructuring
2017-07-16 23:59:49 +10:00
Lucas Azzola 188c466cd5 Don't call shouldHugType for function arguments, fixes #2458 (#2496) 2017-07-16 11:53:01 +02:00
Lucas Azzola 028d9e0ea7 Improve bind expression formatting (#2493)
* Improve bind expression formatting, fixes #1400

* Fix parenthesis with bind expressions, fixes #1446
2017-07-16 11:47:06 +02:00
Lucas Azzola 00d9aa208e Trim trailing whitespace from comments, closes #2422 (#2494) 2017-07-16 17:45:27 +10:00
Lucas Azzola bac9658687 Flatten x & y & z, and x ^ y ^ z, fixes #2445 (#2490) 2017-07-15 12:54:33 +02:00
Lucas Azzola b9b3da6ee9 Implement prettier-ignore inside JSX (#2487)
* Implement prettier-ignore inside JSX, closes #2467

* Re-enable babylon and typescript verification
2017-07-15 20:21:43 +10:00
Stephen Scott 3ed2bae1b4 Improve JSX ternary formatting
* Now JSX-mode ternaries only break if they need to. 
* Only the outermost ternary in a chain of JSX-mode ternaries will become a group.
* We don't wrap null in parens when breaking JSX-mode ternaries.

This commit also improves the test coverage and explanation in tests/jsx/conditional-expression.js.
2017-07-13 10:21:58 -06:00
Stephen Scott 757037948a Improve JSX Formatting
* Arrow Function Expressions returning JSX will now add parens when the JSX breaks
* Conditional expressions within (or containing) JSX are formatted in a more natural way (for JSX), especiall when chained
* JSX in logical expressions (|| or &&) is always wrapped in parens

Fixes #2208
2017-07-13 10:20:42 -06:00
John Backus 1691b85322 Fix <this.Component /> (#2472)
This is a workaround while waiting on
https://github.com/eslint/typescript-eslint-parser/issues/337.

Fixes #2471
2017-07-13 17:21:46 +10:00
Alex Rattray ef91e28434 Merge pull request #2442 from karl/jsx-inline-single-expression
Allow single expressions in JSX to be inline
2017-07-12 21:32:48 -07:00
James Henry ee822f99b9 Update tsep and add test for destructuring assignment (#2443)
Fixes #2229
2017-07-11 09:11:18 +10:00
Karl O'Keeffe 5e76ea7bdd Allow single expressions in JSX to be inline 2017-07-10 20:02:30 +01:00
Lucas Azzola b25935d7a3 TypeScript: allow type assertions to hug (#2439)
* TypeScript: allow type assertions to hug, fixes #2437

* Update snapshots
2017-07-10 22:37:43 +10:00
Lucas Azzola 4a320a9332 Add supervisory parens for bitwise operations (#2429)
* Add supervisory parens for bitwise operations, fixes #2424

* Flatten x | y | z
2017-07-08 17:31:28 +10:00
Lucas Azzola 7e96e01fba Add more supervisory parens, closes #187 (#2423) 2017-07-07 15:57:17 +02:00
Lucas Azzola 8bbbc3a6f3 Remove parens for type assertions in binary expressions, fixes #2416 (#2419) 2017-07-07 13:02:43 +02:00
Lucas Azzola 82b80b3c79 Trim whitespace in descendant combinator, fixes #2410 (#2411)
* Trim whitespace in descendant combinator, fixes #2410

* Permit whitespace changes in clean-ast.js
2017-07-06 13:55:34 +02:00
Dan Wang 86c88ff278 Print TypeParameter even when unary function type (#2406) 2017-07-06 19:13:30 +10:00
Kevin Gibbons 28b3a4b925 Break sequence expressions (#2388)
* Add SequenceExpression tests

* Clean up printing of SequenceExpressions

* Remove test and lint
2017-07-04 22:50:57 +02:00
Karl O'Keeffe 06ae32ddce Ensure there is a line break after leading JSX white space (#2348) 2017-07-03 12:43:10 +02:00
Lucas Azzola 6f9824778d Strip BOM before parsing, fixes #2362 (#2373) 2017-07-01 18:11:13 +02:00
Jarda Snajdr 3f6a232cea Fix indentation of a do-while condition (#2359)
Fixes #2353. Use the same printing code for both `WhileStatement` and `DoWhileStatement`.
Fix calculation of `isInsideParenthesis` when printing a `LogicalExpression`. There is
no such thing as `DoStatement` -- it should be `DoWhileStatement`.
2017-06-29 15:46:25 -07:00
Simone Picciani 85e0bffa7d Removed injectGlobal and keyframes (#2342) 2017-06-28 16:03:33 -07:00
Simone Picciani 067a0137bd Add support for css, keyframes and injectGlobal keywords (#2337)
* styled components now support css keyword

* added support also for keyframes

* added comment to reflect the new keywords

* modified comment

* ignore css and keyframes when testing ast manipulations

* added also injectGlobal
2017-06-28 14:31:27 -07:00
Joseph Frazier 175cde1dc5 Force trailingComma option to "none" when parser is JSON (#2335)
* Run JSON tests with `trailingComma: "all"`

* Add test of `parser: 'json', trailingComma: 'all'` with non-.json extension

See https://github.com/prettier/prettier/issues/2308#issuecomment-311707801

* Force trailingComma option to "none" when parser is JSON

This fixes https://github.com/prettier/prettier/issues/2308
2017-06-28 09:29:47 -07:00
Joseph Frazier 8e37fd76e9 Add support for range-formatting GraphQL (#2319)
* Add test for range-formatting GraphQL

See https://github.com/prettier/prettier/issues/2296#issue-238985580

* Pass test for range-formatting GraphQL

See https://facebook.github.io/graphql/#sec-Appendix-Grammar-Summary.Query-Document

This fixes https://github.com/prettier/prettier/issues/2296

* Consider *Definition GraphQL nodes to be formattable

See https://github.com/prettier/prettier/pull/2319#discussion_r124569400
2017-06-28 09:21:11 -07:00
Lucas Azzola 678964b8de fix(typescript): don't add namespace keyword to global declaration, fixes #2327 (#2329) 2017-06-28 07:53:10 -07:00
Christopher Chedeau b231948a36 GraphQL: Print directives for field declarations (#2317) 2017-06-27 20:22:03 -07:00
Christopher Chedeau 45c8e40d8a GraphQL: Implement schema (#2316) 2017-06-27 20:15:55 -07:00
Christopher Chedeau 019beb54e5 GraphQL: Fix directives separator (#2315)
I couldn't figure out what the separator was, I tried `,`, `on` but none of them worked. Turns out it is `|`!
2017-06-27 19:58:38 -07:00
Christopher Chedeau 14caabd635 GraphQL: Print arguments for FieldDefinition (#2314) 2017-06-27 19:49:59 -07:00
Christopher Chedeau bbf8f76823 GraphQL: Implement scalar (#2313) 2017-06-27 19:34:25 -07:00
Christopher Chedeau 0a2a099efe GraphQL: Implement interface (#2312) 2017-06-27 19:30:58 -07:00
Christopher Chedeau 8e31088761 GraphQL: Implement input (#2311) 2017-06-27 19:27:02 -07:00
Christopher Chedeau b63e1c2dd7 GraphQL: Implement Enum (#2310) 2017-06-27 19:20:53 -07:00
Christopher Chedeau 51c7503dae GraphQL: Implement DirectiveDefinition (#2309) 2017-06-27 19:10:07 -07:00
Christopher Chedeau fbf4c3a952 GraphQL: Support object definition implements (#2307) 2017-06-27 18:51:56 -07:00
Christopher Chedeau ee07ff5870 Fix master 2017-06-27 18:33:23 -07:00
Christopher Chedeau af309e3acd Add support for GraphQL TypeExtensionDefinition (#2306) 2017-06-27 18:26:43 -07:00
Christopher Chedeau f96fe1ea5e Initial support for GraphQL ObjectTypeDefinition (#2305)
It appears in some files inside of fb codebase
2017-06-27 18:22:04 -07:00
Christopher Chedeau 189027c7d3 GraphQL: Use spaces instead of commas (#2303)
"Daniel Schafer: Yeah, that's definitely what I'd describe as the canonical style; anytime you have two "things" on a line, use commas, but if you have a newline it's not needed."
2017-06-27 18:13:07 -07:00
Christopher Chedeau 4d46a3975b GraphQL: Remove circular dependency in ast (#2304)
The tokens are attached to the location via the prototype (so they are not visible when you JSON.stringify) but the various places where we traverse the ast see them. It causes stack overflows and comments that are not printed because they are attached to tokens instead of real nodes.

Fixes #2302
2017-06-27 18:12:30 -07:00
Christopher Chedeau 850d51a033 Tweak name 2017-06-27 17:30:13 -07:00
Joseph Frazier b47c0b4e04 Allow formatting ranges of JSON (#2298)
* Add test for https://github.com/prettier/prettier/issues/2297

* Add JSON types to isSourceElement()

See https://github.com/prettier/prettier/issues/2297

* Avoid expanding format range when possible

This fixes https://github.com/prettier/prettier/issues/2297

* Move JSON range test into tests/range_json

This is so that the AST_COMPARE=1 tests don't try to parse JSON with Flow.

* Check parser in isSourceElement()

Otherwise JSON formatting would format weird things inside of JS.
See https://github.com/prettier/prettier/pull/2298#discussion_r124407056

* Use arrow functions instead of .bind()

See https://github.com/prettier/prettier/pull/2298#discussion_r124409783

* Add test of range-formatting JSON identifier

See https://github.com/prettier/prettier/pull/2298/files#r124410750

* Allow range-formatting JSON identifier

See https://github.com/prettier/prettier/pull/2298/files#r124410750

* Fix lint
2017-06-27 16:04:42 -07:00
Joseph Frazier 5f063ab168 Fix locEnd() for postcss parser (#2295)
* Fix locEnd() for postcss parser

`node.source` doesn't have an `end`, but `node.nodes[-1].source` does.

Fixes https://github.com/prettier/prettier/issues/2267

* Add regression test for https://github.com/prettier/prettier/issues/2267

See https://github.com/prettier/prettier/pull/2295#issuecomment-311484343

* Make locEnd() postcss fix more focused

This passes the tests again.

* Use getLast() instead of .slice()

See https://github.com/prettier/prettier/pull/2295#discussion_r124398553

* Move CSS range test into tests/range_css

This is so that the AST_COMPARE=1 tests don't try to parse CSS with Flow.
2017-06-27 15:12:22 -07:00
Christopher Chedeau 6f4eade422 Go back to babylon beta 13 (#2289)
Fixes #2286
2017-06-27 11:51:23 -07:00
Christopher Chedeau 073a2071a8 Inline import('x') to avoid having trailing , (#2288)
Fixes #2287
2017-06-27 11:40:20 -07:00
Christopher Chedeau 803b7ff6b9 Add \n at the end of .graphql files (#2285)
We need to use the same hack as CSS unfortunately.

Fixes #2275
2017-06-27 09:49:15 -07:00
Christopher Chedeau e707bdd52f Print comments attached to {' '} (#2283)
We had two occurrences on fb codebase where people attached comments on `{' '}` which would be swallowed. Instead of dropping the comments, let's make the algorithm a bit less naive.
2017-06-27 09:35:03 -07:00
Karl O'Keeffe be600337eb Improve JSX output when there is a single expression (#2274) 2017-06-26 19:05:34 -07:00
Karl O'Keeffe 95a5f11be9 Tweak to support FB translation pipeline (#2272)
This also improves formatting when there are consecutive tag/expression elements with no white space between them.
2017-06-26 09:30:52 -07:00
Karl O'Keeffe fe7fb260a4 Fix a case where significant whitespace was dropped (#2270) 2017-06-26 03:03:13 -07:00
Cyril Junod 400f34624f Add module, class and typed nodes to sourceElements (#2266)
babylon flow typescript parsers

+ tests to cover module and class
2017-06-25 09:07:52 -07:00
Christopher Chedeau 9a55f5b2d6 Fix unstable arrow comments (#2262)
It outputted which is completely wrong

```js
<FlatList
  renderItem={info => <span>{info.item.widget.missingProp // $FlowExpectedError - bad widgetCount type 6, should be Object
    }</span>}
/>;
```
2017-06-25 12:30:09 +10:00
Christopher Chedeau f71fcd0b65 Fix variance location (#2261)
Turns out when we refactored for TS, we moved it before "static" and it no longer parses. Oops.
2017-06-25 11:46:29 +10:00
Christopher Chedeau 38d4661ba9 Forward originalText in multiparser (#2260)
If we don't, all the places where we read from the original text (mostly comments) are reading into random places.

Fixes #2258
2017-06-24 17:54:09 -07:00
Christopher Chedeau 8def8e13b0 Add caching for printing (#2259)
* Add caching for printing

For printing the last argument expansion, we need to print the same node a bit differently with a flag. It's not easy to re-print just the node that is different so we end up printing all the sub-tree twice. Since it is often nested, it means that we run into an exponential complexity.

I finally found a simple solution: we can use a Map to store the nodes and their printed values. It is really cheap to do so (I can't notice a time difference with or without on normal code) and allows us to stop going through the two sub-trees in the bad case.

Fixes #1250

* Update printer.js
2017-06-24 14:01:02 -07:00
Christopher Chedeau 6663bab8a3 Support trailing commas for function calls (#2257) 2017-06-24 12:23:34 -07:00
Christopher Chedeau cc85769231 Add support for --trailing-comma for GraphQL (#2254)
Fixes #2251
2017-06-24 11:20:45 -07:00
Christopher Chedeau 59b3a9bc56 Add support for --no-bracket-spacing for GraphQL (#2255)
Fixes #2252
2017-06-24 11:06:56 -07:00
Christopher Chedeau 2f96357884 Attach comments in multiparser (#2253)
Otherwise it doesn't print comments :(
2017-06-24 11:06:50 -07:00
Joseph Frazier 4b955a14c4 Return original input when specified range is unformattable (#2250)
* Add failing test for range-formatting whitespace

See https://github.com/prettier/prettier/issues/2247#issue-238322065

* Return original input when specified range is unformattable

Fixes https://github.com/prettier/prettier/issues/2247
2017-06-24 09:41:10 -07:00
Cyril Junod b0413fc1fe Range Formatter: Remove Program/File from valid Ancestor (#2248)
* Remove Program/File from valid Ancestor

Fix edge range formatting entire file.

* Fix lint with `yarn lint -- --fix`

See https://travis-ci.org/prettier/prettier/jobs/246569943#L242-L260
2017-06-24 12:30:27 -04:00
Lucas Azzola 3474056b36 fix(typescript): handle ObjectPattern instead of ObjectExpression inside BinaryExpression, fixes #2237 (#2238) 2017-06-23 07:53:42 -07:00
Karl O'Keeffe 0cc0ebc3bc Allow JSX lines to be recombined (#1831)
* Allow JSX lines to be recombined

* Add test case for `<br />` breaking expression

* Fix issue where JSX whitespace could be dropped

* Newlines were incorrectly being preserved when JSX contained text
2017-06-22 09:19:44 -07:00
Christopher Chedeau 39954f7951 Handle conditions inside of a ternary (#2228)
Fixes #2122
2017-06-21 18:17:30 -07:00
Christopher Chedeau ec1b672bbf Don't indent + in object value (#2227)
This is a "regression" from when we started using the same heuristic for `=` and `:`

Fixes #2129
2017-06-21 15:58:12 -07:00
Christopher Chedeau c36dd48339 First try scss when there's an @import with comma (#2225)
It's annoying that the less parser is so lenient that it drops things instead of throwing :(

Fixes #2125
2017-06-21 15:45:55 -07:00
Christopher Chedeau aac0d1dda0 Support inline template for new calls (#2222)
I merged the implementation of new and call expressions in this PR.

Fixes #2215
2017-06-21 15:45:44 -07:00
Joseph Frazier 63c47c85e0 JSON: Print trailing newline (#2226)
* JSON: Append trailing newline

This partially addresses https://github.com/prettier/prettier/issues/2223

* Dedupe printing of JSON trailiing newline

* JSON: Add tests for newlines after boolean/null/number/string

* JSON: Fix tests for newlines after boolean/null/number/string, simplify code

This fixes https://github.com/prettier/prettier/issues/2223
2017-06-21 15:40:19 -07:00
Christopher Chedeau 08060e7c94 Use fill for CSS values (#2224)
This looks less weird to have them flow as they fit than breaking on every single line.

Fixes #2213
2017-06-21 15:13:51 -07:00
Karl O'Keeffe 04c41f6758 Fix up empty JSX element detection (#2220) 2017-06-21 13:48:02 -07:00
Christopher Chedeau 313519d8ae Allow long media rules to break (#2219)
Fixes #2198
2017-06-21 13:02:16 -07:00
Brian Ng 7cef77433a Bump babylon version (#2205) 2017-06-20 08:36:14 -07:00
Lucas Azzola 43521565e7 CSS: lowercase hex colors, closes #2139 (#2203) 2017-06-20 23:07:31 +10:00
suǝʞǝǝpʇ 16db5971f0 Fix css-modules composes breaking with long line width (#2190)
* fix(css): css-modules composes breaking

* refactor(css): to use removeLines in case of composes
2017-06-18 23:41:10 -10:00
Jon Wong 1511609c01 Support for printing GraphQL comments (#2187)
* save point

* prettier

* Reverting change to check SOF and EOF

* Removing console.log

* Fixing grouping

* Adding comment output

* Basic comments

* Printing comments

* Getting comments to work

* Adding in basic handling of graphql comments

* Removing parser normalization (i assume it'll be added with language support)

* Lint error

* Reverting special cases

* Dealing with off-by-one error
2017-06-18 07:37:52 -10:00
Joseph Frazier 69808cebfb Format JSON literals like object literals (#2181)
* Format JSON literals like object literals

Following up on commit a42db30 (https://github.com/prettier/prettier/issues/2173),
this change makes it so that literals in JSON files are formatted as
they would be in an object literal. This normalizes trailing zeroes,
exponential notation, unnecessarily escaped characters, etc.

It works by using babylon to parse literals as expressions, and putting
the result in the AST instead of a `json-literal` node. Since JSON
string literals have to be double-quoted, there's a new
`__prettier__isJson` flag on each node, which is used by the printer to
force double-quotes.

* json: Check options.parser when formatting StringLiteral

This is instead of having a custom AST property. See
https://github.com/prettier/prettier/pull/2181#discussion_r122578251

* multiparser: Use babylon.parseExpression

See https://github.com/prettier/prettier/pull/2181#discussion_r122578354

* json: Don't split result AST node into two

See https://github.com/prettier/prettier/pull/2181#discussion_r122578499

* json: Don't use babylon parser to build expression nodes

See https://github.com/prettier/prettier/pull/2181#discussion_r122579052

* Revert "multiparser: Use babylon.parseExpression"

This reverts commit 3d7a4362880d39fac0cea88b5d0186a29538cf6f.

* Remove unused parameter from babylon parser

* json: Remove unused constructorTypes
2017-06-17 20:49:22 -04:00
Joseph Frazier a42db30946 Add JSON support (#2173)
* Add JSON support

This fixes https://github.com/prettier/prettier/issues/1973 by using
[json-to-ast] to parse JSON, then converting the AST into a
mostly-Babylon AST, so as to piggyback on the existing printer logic.

Identifiers and literals are currently printed verbatim from the input,
but this could be improved upon later (at least for literals, not sure
about identifiers).

[json-to-ast]: https://github.com/vtrushin/json-to-ast

* Rename `json-to-ast` parser to `json`

See https://github.com/prettier/prettier/pull/2173#discussion_r122574644

* json: Use createError to have a pretty error

See https://github.com/prettier/prettier/pull/2173#discussion_r122574748

* json: Transform AST without mutations

See https://github.com/prettier/prettier/pull/2173#discussion_r122574690
2017-06-17 10:36:42 -10:00
Lucas Azzola bff28023b3 Comments: attach method name comments with estree parsers, fixes #2141 (#2170) 2017-06-17 22:22:39 +10:00
Lucas Azzola c669a1db72 TypeScript: group function params in call/construct signatures, fixes #2163 (#2169) 2017-06-17 12:09:18 +10:00
Stephen Wan a005211c96 Fix extra semicolon in ambient typescript declaration emit (#2165) (#2167)
* fix(typescript): add failing ambient declaration test

* fix(typescript): fix failing test case for ambient function exports
2017-06-16 08:20:59 -10:00
Lucas Azzola 7e60d70f97 fix(typescript): always break interfaces onto multiple lines, fixes #2159 (#2161) 2017-06-15 14:34:54 -10:00
Lucas Azzola 9e7b02d50e Print {} in import if it's in the source, fixes #2145 (#2150) 2017-06-15 20:19:01 +10:00
Lucas Azzola a2328edced TypeScript: keep parens around with yield/await non-null assertion, fixes #2137 (#2149) 2017-06-15 09:34:12 +10:00
Joseph Frazier 48bbd9cb6b Don't insert a cursor placeholder for a value-less path (#2136)
* Test that no cursor placeholder is inserted for a value-less path

This was taken from https://github.com/prettier/prettier/issues/2131

* Don't insert a cursor placeholder for a value-less path

This fixes https://github.com/prettier/prettier/issues/2131
2017-06-14 09:05:06 -07:00
Lucas Azzola b7e1c366e0 Vue: pretty-print binding syntax (#2108)
* feat(vue): pretty-print :class attributes

* feat(vue): switch to brand new custom parser API! 🎉

* refactor(vue): move AST manipulation to post-parse
2017-06-14 22:33:15 +10:00
James Henry 9b772cb4fd Add test for comment in TypeScript type parameters (#2132) 2017-06-14 20:10:03 +10:00
Christopher Chedeau abfdbe1896 Upgrade typescript to 2.4 (#2120)
Fixes #2117
2017-06-13 09:47:40 -07:00
Rodrigo Pombo 8dd0cb2a05 Format CSS in template literals with expressions (#2102)
* Add support for styled-jsx with expressions

* Lint

* Fix require for Node 4

* Re-create template-literal document when replacing placeholders

* Add support for styled-components with expressions

* Fix merge

* Move css library detection to functions
2017-06-13 09:45:16 -07:00
adanoff 44b5da8ade Add `graphql.experimental` parsing for react-relay (#2116) 2017-06-12 17:16:17 -07:00
Christopher Chedeau 62b9e29af5 Fix comments in non strict mode (#2114)
It turns out that by returning there, we didn't go through the line `delete ast.tokens` and the comments attachment logic would attach it to a random token. It's great that this fail-safe caught this bug!

Fixes #2111
2017-06-12 09:50:51 -07:00
Lucas Azzola 486a89bfdc fix(typescript): workaround - don't wrap directives in parens, fixes #2074 (#2107) 2017-06-11 19:10:56 -07:00
Lucas Azzola e8f12cf621 TypeScript: Remove parens from type annotations where possible (#2098)
* fix(typescript): remove parens from union types where possible, fixes #1885

* fix(typescript): ensure parenthesis removal is stable

* fix(typescript): don't strip parens around function type
2017-06-11 18:06:47 -07:00
Lucas Azzola 9c608d2ec1 fix(typescript): use printFunctionParams for call/construct signature, fixes #2105 (#2106) 2017-06-11 16:06:38 -07:00
Lucas Azzola ec7d99439d fix(typescript): print arrow function type params on same line as params, fixes #2099 (#2101) 2017-06-11 07:30:51 -07:00
Lucas Azzola 4395e09b78 fix(import): allow break with both default named import, fixes #2050 (#2096) 2017-06-10 21:55:21 -07:00
Lucas Azzola a79a444bac fix(variable-declarator): indent first variable in one-var scenario, fixes #2072 (#2095) 2017-06-10 21:19:50 -07:00
Lucas Azzola fdb7467de7 feat(html): add support for HTML fragments (#2093) 2017-06-10 20:10:34 -07:00
Lucas Azzola b4f0ff346e feat(mutliparser): add react-relay and graphql-tag parsing (#2092) 2017-06-10 08:59:27 -07:00
Lucas Azzola d1b94c540c Implement parser switching (HTML, Vue, styled-components) (#2086)
* feat(multiparser): implement switching from html -> css,js,ts

* feat(multiparser): use quasi value instead of originalText
2017-06-10 08:03:39 -07:00
Lucas Azzola 77f0c05d2a fix(method-chain): break on non-literal computed member expression, fixes #2075 (#2087) 2017-06-10 07:47:22 -07:00
Lucas Azzola 1e08f03554 fix(typescript): break on multiple interface extends, fixes #2043 (#2085) 2017-06-10 07:46:59 -07:00
Lucas Azzola f7819d5695 CSS: implement prettier-ignore (#2089)
* fix(css): implement prettier-ignore, fixes #2007

* refactor(css): move prettier-ignore to printNodeSequence
2017-06-10 07:45:59 -07:00
Lucas Azzola a9409f11e7 fix(css): print @else on same line as }, fixes #2053 (#2088) 2017-06-10 07:40:05 -07:00
Lucas Azzola d00956d51d feat(html): add parse5/htmlparser2 printer (#2083) 2017-06-09 19:22:59 -07:00
Christopher Chedeau f399e90bc2 Preserve lines after directives (#2070)
Looks like we were only doing it at the top level, we should do it everywhere.

Fixes #2067
2017-06-08 17:10:01 -07:00
Christopher Chedeau 939734b75e Use ifBreak instead of shouldBreak (#2063)
shouldBreak is only a heuristic to enforce a break, if it breaks "naturally", then it won't be applied.

Fixes #2055
2017-06-08 11:47:49 -07:00
Tim Griesser df26cc05cc Support graphql ListType (#2061) 2017-06-08 09:34:35 -07:00
Christopher Chedeau 883e637fa9 Support the Keyword type (#2056)
This is an issue in https://github.com/eslint/typescript-eslint-parser/issues/315

Fixes #2049
2017-06-08 09:25:28 -07:00
Tim Griesser e9045e4bcf Support graphql NonNullType (#2060) 2017-06-08 09:20:41 -07:00
Pier Paolo Ramon 126727380d CSS: Every selector is now printed in its own line (#2047)
Changes the behaviour for line breaking inside selector lists (those
separated by ',') so that every selector is in its own line.

Fixes #1962
2017-06-08 07:46:24 -07:00
Christopher Chedeau 924363193b Check if the next group has comments (#2040)
Fixes #1958
Fixes #1959
2017-06-07 15:20:11 -07:00
Christopher Chedeau 1edb1f261b Include typeAnnotation inside of node location (#2039)
We should remove this hack once https://github.com/eslint/typescript-eslint-parser/issues/314 lands

Fixes #1946
2017-06-07 15:05:46 -07:00