Commit Graph

846 Commits (06c9127f022642cbf6d47fd2bef0d74b5cbc17a5)

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