Commit Graph

211 Commits (1916966910d30756073a04426a8b40bab543b148)

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

* Improve formatting of TS casts with generics and unions.

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

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

* Update tests in prepation for updating long cast format.

* Update so nested breaks inside type cast are indented.

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

* Update cast formatting to only sometimes break after cast.

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

* Regex -> array

* Use object instead of array for faster lookup

* Remove empty lines

* Add redux connect

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

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

* test: add trailing newline

* fix: there can be no trailing newline

* refactor: simplify regex

* refactor: Array.from

* refactor

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

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

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

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

* feat(typescript): support TaggedTemplateExpression typeParameters

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

* chore(deps): update typescript-eslint-parser
2018-04-24 08:45:06 -05:00
Adam Pearce 09ac476a32 Nicer line wrapping for d3 (#4285)
* d3 counts as a constructor

* adds test

* Tweak wording

* docs: fix linting

* updates test

* no $ special case

* renames function

* shorter function name

* removes trailing white space
2018-04-24 06:54:45 -04:00
Mike Grip 4c464133ac feat: adding plugin ability for isBlockComment (#4347)
* adding plugin ability for isBlockComment

* refactor to remove private util def

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

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

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

* typo

* remove default value

* add safe check if parent exists

* add spec

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

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

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

* refactor(js): reuse conditional expression logic

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

* chore(js): make code support Node 4

* chore(js): rename utility functions

* chore(js): add comments for formatTernaryOperator

* fix(ts): support infer keyword

* chore(js): new line

* chore(js): improve readablity a little bit
2018-02-23 12:34:23 -07:00
Lucas Azzola b7f0794ad5
Handle definite variable declarations (#4025)
* Handle definite variable declarations

* printDefinite -> isDefinite
2018-02-22 13:03:35 +11:00
Ika 8f6a32853c
feat(typescript): support definite assignment (`!:`) (#4020) 2018-02-22 01:40:57 +08:00
Lucas Duailibe 974b27dac2
Break JSX element if a string literal prop has a newline (#4011) 2018-02-21 10:52:30 -03:00
Eric Anderson 051a488bbd fix(typescript): properly chain when there is a TSNonNullExpression (#4005)
* fix(typescript): properly chain when there is a TSNonNullExpression

* No need to pass args

* PR feedback

* Fix lint
2018-02-20 12:37:11 -03:00
Brian Ng a8fe401b26 Fix cases with missing semi when printing DeclareExportDeclaration (#3979) 2018-02-17 17:40:43 +11:00
Ika 4a4bd2faed
fix(typescript): support `unique symbol` (#3967)
* test(typescript): add failing test

* chore(deps): update typescript-eslint-parser to v13.0.0

* fix(typescript): support `unique symbol`
2018-02-14 01:03:53 +08:00
Lucas Azzola 2313574fcc
Fix flow maybe object return type (#3948) 2018-02-11 17:46:00 +11:00
Christian Zosel fac08034e7 Split out location extraction into plugin config (#3777)
* Split out location extraction into plugin config

* Reduce set of exported function, rebase to current master

* Pass custom locStart/locEnd fn's directly to affected methods

* (wip) always use locStart/locEnd from plugin

* Convert graphql implementation

* Convert HTML implementation

* (wip) convert JS implementation

* Remove unused variables

* Continue conversion of JS implementation

* Replace "util.locStart" with direct call to "options.locStart"

* Remove util closure

* Add unit test for structure of shared util

* Fix linting error, simplify locStart/End implementations
2018-02-09 23:17:48 +11:00
Ika 47714f5d4b
feat(plugins): change external options to be plugin-level (#3924) 2018-02-09 00:06:38 +08:00
Lucas Duailibe aac38fca49 Force break if comment in return argument (#3665)
* Force break if comment in return argument

* add test case
2018-01-31 12:00:29 -05:00
Salem 8c792121f2 Treat define calls like require (#3830)
* Treat define calls like require

See issue #3829. This commit keeps define calls as a unit when possible,
to prevent an extra indent in the body of an AMD-style define.

Rather than adding the "define" check in the same case as the existing
"require" check, I added a separate condition to explicitly call out the
fact that this checks for both AMD and CommonJS modules.

`yarn test -u` yields no changes, and `yarn lint` passes successfully.

* Added tests for define and require amd formatting

This tests the solution for issue #3829.

* Add babylon interpreter to require-amd test

* Merge require and define checks
2018-01-29 16:44:32 -05:00
Ika 03292a6488
fix(javascript): ternary with `--use-tabs` (#3745)
* test: add test cases

* test: add test cases

* fix(javascript): ternary with `--use-tabs`

* chore: add istanbul ignore comment

* fix: remove unnecessary condition

* docs(commands): update `align`

* fix: do not transform the middle part

* refactor: markAsRoot

* fix: print tabs in sub-ternaries

* docs(commands): update

* test: add a cool test case
2018-01-26 10:02:42 +08:00
Ika 2dd311d554
fix(javascript): indentation for sub-ternaries (#3747)
* test: add test cases

* test: add test cases

* fix(javascript): indentation for sub-ternaries

* test: update test cases

* fix: no extra tab for `tabWidth: 4`
2018-01-16 11:32:25 +08:00
Thorben von Hacht 1a1de60491 Prettier extends and implements when not fitting in same line (#3689)
* Added prettier layout for class extends and implements

* Added prettier layout for class extends and implements, fix with keeping it in online if it fits

* Added prettier layout for class extends and implements, fixed tests as a side change

* Extends implements comments in same line fix

* Extends implements comments in same line without ugly workaround

* added empty line to test typescript_class/extends_implements.ts

* If only one extends keep old behaviour

* Removed console logs
2018-01-13 16:31:51 +11:00
Quinn Hoyer aa0437cc60 Add support for skip() (#3706) (#3735)
* Add support for skip() (#3706)

* Fix regex & add tests
2018-01-13 13:02:31 +11:00
Lucas Duailibe 7f75499dd2 Prevent adding softline after arrow attribute with comments (#3641)
* failing test

* fix
2018-01-03 12:12:01 -08:00
Lucas Duailibe 7d3a30615b
Don't add () in JSX attributes with elements (#3640) 2018-01-03 11:36:25 -03:00
Lucas Duailibe 51744e1008 Print parens in FunctionTypeAnnotation when arrowParens is "always" (#3616)
* add test case

* print parens in function type annotation
2017-12-31 16:01:21 +01:00
Ika 6c0dd74518 feat(support-info): add `options` field (#3433)
* refactor: rename supportTable with supportLanguages

* refactor: use `dedent`

* test: reduce unnecessary data

* feat(support-info): add `options` field

* add `showDeprecated` option
* add `showUnreleased` option

* test: snapshot diff

* fix(support): add missing `since`

* fix: add missing `category`

* refactor: use template tag

* fix: `trailingComma:true` should redirect to `trailingComma:es5`

* refactor: reorder parser

* refactor: fix linting

* refactor: move options

* refactor: move options to printers
2017-12-31 15:34:37 +11:00
Lucas Azzola a041914551
Extract cleanAST to language-specific files (#3610)
* Extract cleanAST to language-specific files

* Fix lint

* Fix clean-ast for vue and glimmer
2017-12-30 21:30:09 +11:00
Christopher Chedeau 7eca8011bc Inline do expressions inside of JSX (#3607)
Fixes #3602
2017-12-29 18:58:01 -03:00
Lucas Azzola ee148bfded
Split up comment printing (#3575)
* Split up comment printing

* Refactor plugin handling

* Allow multiparser to use options normalization

* Rename to canAttachComment

* Add inline comment

* Format code

* Use prettier.__debug to get AST
2017-12-27 00:04:09 +11:00
Lucas Azzola 4c9d4061da
Prettier Plugin API (#3536)
* Move files around in preparation for refactor

* Update paths in build script

* Extract generic printing logic from the JavaScript printer

* Conform printer API

* Fixup decorator handling

* Fix multiparser

* Create plugin entry for markdown

* Create plugin entry for javascript/typescript

* Create plugin entry for html

* Create plugin entry for graphql

* Create plugin entry for css/less/scss

* Move JSON to JS plugin entry

* Integrate plugins into getSupportInfo()

* Move astFormat to parser definition

* Move util to common

* Implement parser loading

* remark -> mdast

* Rename cli/cli -> cli/index

* Rename builder -> doc package, fix printer resolution

* Fix doc shape assumption in CSS-in-JS logic

* Fix third-party.js prod resolution

* Fixup build-docs script

* Distribute multiparser code

* Remove requirement to forward options

* Flatten closure

* Remove debug directory

* Expose doc

* Add external plugins

* Pass options to loadPlugins

* Export getParsers

* Pin resolve version

* Use getSupportInfo in Markdown embed

* Document plugin API

* Update build-docs

* Add CLI for plugins

* Lint docs

* Fixup build.js

* Add vue language

* Fixup multiparser for vue

* Upgrade rollup and rollup-plugin-commonjs

* Fixup third-party build

* Change AST format in docs
2017-12-26 12:23:50 +11:00