Commit Graph

870 Commits (2c76bfe1e13be35ab73661746bedfae5e9ad2d0b)

Author SHA1 Message Date
Danny Martini 2c76bfe1e1 update typescript parser (#1578)
* update eslint-parser-typescript

* fix comment parsing

* disable all failing tests

* fix TSInterfaceDeclaration

* fix #1537

* only disable typescript tests for tests/function
2017-05-10 14:11:50 -07:00
Joseph Frazier 8cc38ad524 Preserve code unit sequence of directive literals (#1571)
* Print directive literals verbatim

This addresses https://github.com/prettier/prettier/issues/1555,
but doesn't seem to pass the AST_COMPARE=1 tests:

    AST_COMPARE=1 npm test -- tests/quotes -t strings

However, running `prettier --debug-check` on the relevant file *does*
work:

    prettier tests/quotes/strings.js --debug-check

* Change directive literal quotes if it doesn't contain quotes

This addresses https://github.com/prettier/prettier/pull/1560#discussion_r115396257

From https://github.com/prettier/prettier/issues/1555#issue-227206837:

> It's okay to change the type of quotation marks used, but only if
doing so does not require changing any characters within the directive.

* Don't change directive literal quotes if it contains a backslash

This passes the `--debug-check` tests again:

    prettier tests/quotes/strings.js --debug-check

* Try to add regression test for escaped directive literals

This seems not to work, despite the following command having the correct
output:

    echo "'\''" | prettier

You can use the following to get an idea of how flow/typescript parse
this:

    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'flow'}), null, 2)"
    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'typescript'}), null, 2)"

* WIP Disable Flow/Typescript for ./tests/directives

We don't yet handle escaped directives for them, but Babylon works.

(similar to 90bf93713c (diff-0de18284f37da79ab8af4e4690919abaR1))

* Revert "WIP Disable Flow/Typescript for ./tests/directives"

This reverts commit 2aba6231271f6985a395c31e3df9323e8f3da115.

* Prevent test strings from being parsed as directives

See https://github.com/prettier/prettier/pull/1560#issue-227225960

* Add more escaped directive tests

* Infer DirectiveLiterals from Flow parser

* Don't test TypeScript on directives

See https://github.com/prettier/prettier/pull/1560#issuecomment-300296221

* fixup! Infer DirectiveLiterals from Flow parser

* Don't fake objects that look like a DirectiveLiteral

Instead, add a flag to nodeStr() that deals with the Flow node
accordingly. See https://github.com/prettier/prettier/pull/1560#discussion_r115605758

* Print preferred quotes around escaped DirectiveLiteral when it doesn't contain quotes

See https://github.com/prettier/prettier/pull/1560#discussion_r115606122

* Simplify `canChangeDirectiveQuotes` logic

* Add directive test with unnecessarily escaped non-quote character

* Fix boolean logic error

I thought that this would result in the following if-block executing, as
needed to pass the test case in the previous commit. However, it appears
that it's not actually needed to pass the test case, since `makeString`
doesn't unescape unnecessarily escaped non-quote characters.
Nevertheless, I think we should leave that if-block (`if (canChangeDirectiveQuotes)`)
there, in case `makeString` is updated.

See https://github.com/prettier/prettier/pull/1571#discussion_r115658398

* Make isFlowDirectiveLiteral a separate argument to nodeStr()

See https://github.com/prettier/prettier/pull/1571#discussion_r115810988

* Simplify isFlowDirectiveLiteral logic by passing n.expression to nodeStr()

See https://github.com/prettier/prettier/pull/1571#discussion_r115811216
2017-05-10 12:15:27 -07:00
Stephen Eisenhauer dfbea5d8ab Improve clarity of boolean option documentation (#1573)
As discussed on #1564, improve the clarity of the descriptions for the bracketSpacing and semicolons options by describing what the options do rather than what their CLI overrides do; These were confusing as written because these options default to true, and their CLI overrides trigger the opposite behavior.
2017-05-10 08:15:32 -07:00
Joseph Frazier 8ce393a425 Remove trailing whitespace from src/ and markdown files (#1576) 2017-05-10 08:15:11 -07:00
Christopher Chedeau 13f247aee3 Revert "Print directive literals verbatim (#1560)" (#1570)
This reverts commit 32d9d68154.
2017-05-09 14:19:03 -07:00
Joseph Frazier 32d9d68154 Print directive literals verbatim (#1560)
* Print directive literals verbatim

This addresses https://github.com/prettier/prettier/issues/1555,
but doesn't seem to pass the AST_COMPARE=1 tests:

    AST_COMPARE=1 npm test -- tests/quotes -t strings

However, running `prettier --debug-check` on the relevant file *does*
work:

    prettier tests/quotes/strings.js --debug-check

* Change directive literal quotes if it doesn't contain quotes

This addresses https://github.com/prettier/prettier/pull/1560#discussion_r115396257

From https://github.com/prettier/prettier/issues/1555#issue-227206837:

> It's okay to change the type of quotation marks used, but only if
doing so does not require changing any characters within the directive.

* Don't change directive literal quotes if it contains a backslash

This passes the `--debug-check` tests again:

    prettier tests/quotes/strings.js --debug-check

* Try to add regression test for escaped directive literals

This seems not to work, despite the following command having the correct
output:

    echo "'\''" | prettier

You can use the following to get an idea of how flow/typescript parse
this:

    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'flow'}), null, 2)"
    node -p "JSON.stringify(require('./src/parser').parse('\\'\\\\\'\\'', {parser: 'typescript'}), null, 2)"

* WIP Disable Flow/Typescript for ./tests/directives

We don't yet handle escaped directives for them, but Babylon works.

(similar to 90bf93713c (diff-0de18284f37da79ab8af4e4690919abaR1))

* Revert "WIP Disable Flow/Typescript for ./tests/directives"

This reverts commit 2aba6231271f6985a395c31e3df9323e8f3da115.

* Prevent test strings from being parsed as directives

See https://github.com/prettier/prettier/pull/1560#issue-227225960

* Add more escaped directive tests

* Infer DirectiveLiterals from Flow parser

* Don't test TypeScript on directives

See https://github.com/prettier/prettier/pull/1560#issuecomment-300296221

* fixup! Infer DirectiveLiterals from Flow parser
2017-05-09 17:17:29 -04:00
Joseph Frazier ebe85917a3 Add warning about vanilla Vim integration, recommend Neoformat (#1568)
* Add warning about vanilla Vim integration

Fixes https://github.com/prettier/prettier/issues/743
Fixes https://github.com/prettier/prettier/issues/1191
Fixes https://github.com/prettier/prettier/issues/1466

* Recommend Neoformat over vanilla Vim integration

See https://github.com/prettier/prettier/issues/743
See https://github.com/prettier/prettier/issues/1191
See https://github.com/prettier/prettier/issues/1466

* Remove vanilla Vim integration from README

Since it's relatively broken, we don't want to recommend it.
See https://github.com/prettier/prettier/pull/1568#issuecomment-300270038

This also adds a TOC link for the "Other `autocmd` events" section,
which was previously missing.
2017-05-09 12:50:01 -07:00
Stephen Eisenhauer 93472d0998 Fix incorrect options documentation in README (#1564)
* Fix incorrect options documentation in README

The options section in the README (which appears to be the primary source of truth for documentation) had incorrectly conflated the bracketSpacing and jsxBracketSameLine options into a single table row (using the human readable name for one, the machine readable names for another, and combined descriptions of both). This patch splits the row into two accurate ones.

* Revise previous correction to options documention in README

Incorporating feedback in #1564
2017-05-09 12:06:40 -07:00
Joseph Frazier c56a685e5d tests: Rename `RUN_AST_TESTS` variable to `AST_COMPARE` (#1563)
This makes it match the environment variable, which is consistent with
the other variables.
2017-05-09 13:32:01 -04:00
Joseph Frazier 225fa57780 Mention --debug-check in CLI section of README (#1562)
* Prevent using --write with --debug-check

This addresses https://github.com/prettier/prettier/issues/1552#issuecomment-300043294

* Exit with a non-zero code if --debug-check fails

This makes it easier to use programmatically. See
https://github.com/prettier/prettier/issues/1552#issuecomment-300042417

* Mention --debug-check in CLI section of README

This addresses https://github.com/prettier/prettier/issues/1552#issuecomment-300043294
2017-05-09 02:51:04 -07:00
Joseph Frazier 09fd8de526 Also run normal tests when AST_COMPARE=1 (#1561)
This makes it easier to just use `AST_COMPARE=1 npm test`, instead of
having to run `npm test` separately.
2017-05-08 20:23:51 -07:00
Joseph Frazier 18fd014985 Run AST comparison tests on Travis (#1553)
* Run AST comparison tests on Travis

It looks like some of these currently fail, so we should probably also
sort that out.

Inspired by https://github.com/prettier/prettier/issues/1552

* tests: Use specified parser when AST_COMPARE=1

This fixes some of the tests with AST_COMPARE=1

* Move cleanAST() into prettier.__debug

This makes it available for tests to use.

* AST_COMPARE=1 uses cleanAst() instead of removeEmptyStatements()

Ths fixes some of the tests with AST_COMPARE=1

* Export parse() from src/parser.js

This makes it available for tests to use.

* tests: Use specified parser more when AST_COMPARE=1

This is a continuation of commit 86437a66d326919897fe89891a25824870f5bb79

This fixes some of the tests with AST_COMPARE=1

* massageAST: remove leadingComments/trailingComments

This fixes some of the tests with AST_COMPARE=1

* massageAST: remove `extra`

This fixes some of the tests with AST_COMPARE=1

* tests_config/run_spec.js: Rename variables for clarity

* AST_COMPARE=1 tests compare unstringified objects

This makes the test error output shorter.

* fixup! Export parse() from src/parser.js

* Revert "Run AST comparison tests on Travis"

See https://github.com/prettier/prettier/pull/1553#issuecomment-300027747

This reverts commit 49873a956c532f23fd216551a35ae35c1a18407e.

* fixup! fixup! Export parse() from src/parser.js

* parser: Require babel-code-frame only when needed

This addresses:
* https://github.com/prettier/prettier/pull/1553#discussion_r115386253
* https://github.com/prettier/prettier/pull/1553#discussion_r115386250

* parser: Don't export now-unused parseWith* functions

Addresses https://github.com/prettier/prettier/pull/1553#discussion_r115386964

* Move cleanAST/massageAST into own file, don't export

This addresses:
* https://github.com/prettier/prettier/pull/1553#discussion_r115386993
* https://github.com/prettier/prettier/pull/1553#discussion_r115386611

* Don't destructure require() result (Node v4 compat.)

* Fix copy/paste error
2017-05-08 18:16:35 -07:00
Joseph Frazier 2ce6632082 Fix variable name in getParsersToVerify() (#1554)
It previously referred to an undefined variable.
2017-05-08 17:27:39 -07:00
Lucas Azzola 44934da349 feat(typescript): add fallback for JSX detection (#1551) 2017-05-08 05:57:19 -07:00
Lucas Azzola eabff629dd chore(build): update snapshot test (#1549) 2017-05-07 20:04:32 -07:00
Lucas Azzola fa27e5838c feat(typescript): add TSTypeAssertionExpression and naive TSX detection (#1545) 2017-05-07 08:09:52 -07:00
Lucas Azzola 3471ce4584 feat(typescript): print semi instead of comma in TS interface (#1548) 2017-05-07 07:39:21 -07:00
Lucas Azzola f655233ba2 fix(typescript): handle declare global syntax (#1546) 2017-05-07 03:44:41 -07:00
Lucas Azzola 5cc7878902 fix(typescript): fix a handful of ast(prettier(input)) issues (#1544) 2017-05-06 22:34:47 -07:00
Lucas Azzola 92d5a57122 fix(typescript): add TSNamespaceFunctionDeclaration to ast-types (#1543) 2017-05-06 21:33:07 -07:00
Lucas Azzola 0fa38cce33 fix(typescript): remove extraneous newline with namespace exports (#1542) 2017-05-06 20:28:49 -07:00
Lucas Azzola e22bd00815 fix(typescript): ArrowFunctionExpression needs parens in TSAsExpression (#1541) 2017-05-06 20:03:17 -07:00
Lucas Azzola 5fd9cd01de test(typescript): do not fail debug check on Literal -> Identifier (#1540) 2017-05-06 19:39:19 -07:00
Christopher Chedeau 97ea416c69 Better syntax error message for typescript (#1536)
This makes uses the fancy babylon error printer instead of just printing the message and line/column.
2017-05-06 12:44:06 -07:00
Lucas Azzola 3d45278ea7 fix(typescript): print readonly and ? tokens in TSMappedType (#1535) 2017-05-06 10:30:59 -07:00
Lucas Azzola 4629db6b0d TypeScript: improve handling of computed properties (#1532)
* fix(typescript): improve handling of computed properties

* test(typescript): add Symbol computed property test

* fix(typescript): do not print brackets for literals
2017-05-06 08:00:26 -07:00
Prathik Shetty c2bdcbe996 Include pre-commit plugin (#1493)
* Update README.md

* Update README.md

* Update README.md

* Update README.md
2017-05-06 07:59:23 -07:00
Simen Bekkhus ed24bff251 Upgrade jest (#1534)
* Upgrade jest

* yarn upgrade
2017-05-06 07:40:40 -07:00
Lucas Azzola c337c83043 fix(typescript): workaround eslint/typescript-eslint-parser#257 (#1533) 2017-05-06 06:19:33 -07:00
Lucas Azzola 11e3d8241f TypeScript: print modifiers on TSIndexSignature and TSPropertySignature (#1531)
* fix(typescript): print modifiers on TSIndexSignature

* fix(typescript): print modifiers on TSPropertySignature and reformat TSMappedType
2017-05-06 06:18:23 -07:00
Lucas Azzola 8a8a67b9fe fix(typescript): print typeArguments in TSExpressionWithTypeArguments (#1530) 2017-05-06 06:17:48 -07:00
Igor Oleinikov f51822c16d fix(TypeScript): define TSFunctionType AST node (#1529)
- fixes printing of comments inside function type node
2017-05-05 22:14:12 -07:00
Christopher Chedeau bb232d48a3 Inline chained conditionals inside of jsx attribute (#1519)
Fixes #1515
2017-05-05 21:44:50 -07:00
Christopher Chedeau c63e21b52b Do not put parens for single argument with end of line comment (#1518)
Fixes #1517
2017-05-05 21:44:42 -07:00
Christopher Chedeau 3d964b18bb Add parens around `as` (#1528)
I put it at the same place where `a in b` is handled.

Fixes #1524
2017-05-05 21:39:20 -07:00
Christopher Chedeau c8984f392a Fix TypeScript regex (#1527)
Turns out n.value is NaN for regexes in typescript, go figure. Just moving the two if statements is working to fix the issue.

Fixes #1526
2017-05-05 21:39:11 -07:00
Lucas Azzola b9a7549e47 TypeScript: correctly print nested namespaces (#1522)
* fix(typescript): correctly print nested namespaces

* test(typescript): update snapshots
2017-05-05 21:14:07 -07:00
Lucas Azzola b23c16d05d fix(typescript): print typeParameters on TSMethodSignature (#1523) 2017-05-05 21:11:13 -07:00
Lucas Azzola c689f2a0e7 Fix module block, add enum initializers and fix type parameters (#1501)
* fix(typescript): fix module block, add enum initializers and fix type parameters

* fix(typescript): use printStatementSequence for TSModuleBlock

* fix(type-params): move typeParameters out of printFunctionParams

* refactor(type-params): move typeParameters out of printArgumentList
2017-05-05 19:44:26 -07:00
Dorian Karter d3d5d57984 Use setlocal in all vim examples (#1403) 2017-05-05 09:13:08 -07:00
Paul Carduner af754adb7b Make prettier into a global minor mode that can be toggled on and off (#1496) 2017-05-05 09:10:59 -07:00
Jake Trent 3cfc37d411 Options readme (#1406)
* add options table to readme

* remove options from api usage in favor of options table

and link a few paragraphs to the options section
2017-05-05 09:10:23 -07:00
Kevin Gibbons e290514a9e Parenthesize `new F(await a)` and `x[await a]` correctly (#1513) 2017-05-05 08:10:56 -07:00
Brian Ng ccf509abb6 Fix empty line with flow union (#1511) 2017-05-04 19:06:30 -07:00
Christopher Chedeau 1a1e6fc1dd Print empty member lookup (#1506)
I have no idea if it's even valid but it threw on 8 typescript tests, now it doesn't.

```js
TypeError: Cannot read property 'type' of null
at printMemberLookup (prettier/src/printer.js:3062:16)
```
2017-05-04 11:20:52 -07:00
Danny Arnold 1fca1eeddf add TSTypeParameter to typescript ast nodes (#1508) 2017-05-04 11:20:35 -07:00
Danny Arnold 14636947b6 add TSParameterProperty to typescript ast nodes (#1507) 2017-05-04 11:19:50 -07:00
Danny Arnold c1a8ee011d add TSAbstractKeyword (#1505) 2017-05-04 09:48:24 -07:00
Christopher Chedeau bdf6050434 Do not throw on an empty file with a ; (#1503)
Fixes "TypeError: Cannot read property 'replace' of undefined"

This was discovered by #1480 and also affects non-typescript
2017-05-04 09:40:11 -07:00
Danny Arnold e6eee0467d add TSConstKeyword (#1502) 2017-05-04 09:37:00 -07:00