Commit Graph

875 Commits (db0f2ee428fd521085b0c8b9883f0105ddf13450)

Author SHA1 Message Date
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