Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
with prettier 1.16.1 update
  • Loading branch information
Christopher J. Brody committed Jan 22, 2019
2 parents 3e332fe + 7faa260 commit ae7889f
Show file tree
Hide file tree
Showing 44 changed files with 1,166 additions and 96 deletions.
5 changes: 5 additions & 0 deletions .azure-pipelines/steps/install-nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ steps:
inputs:
versionSpec: "$(node_version)"
displayName: "Install Node.js"

# workaround for https://github.com/yarnpkg/yarn/issues/6900
- script: npm install -g yarn@1.12.3
displayName: "Install Node v4 compatible Yarn"
condition: eq(variables.node_version, 4)
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/formatting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Tip! Don't write this stuff manually.
-->

**Prettier 1.15.3**
**Prettier 1.16.1**
[Playground link](https://prettier.io/playground/#.....)
```sh
# Options (if any):
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ BEFORE SUBMITTING AN ISSUE:
-->

**Environments:**
- Prettier Version: 1.15.3
- Prettier Version: 1.16.1
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v6, Chrome v67, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
Expand Down
1 change: 1 addition & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

- [ ] I’ve added tests to confirm my change works.
- [ ] (If changing the API or CLI) I’ve documented the changes I’ve made (in the `docs/` directory)
- [ ] (If not an internal change) I’ve added my changes to the `CHANGELOG.unreleased.md` file following the template.
- [ ] I’ve read the [contributing guidelines](https://github.com/prettier/prettier/blob/master/CONTRIBUTING.md).

**[Try the playground for this PR](https://prettier.io/playground-redirect)**
121 changes: 120 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,126 @@ $ git log --pretty=format:"- %s" rev1..rev2 | sed 's/#\([0-9]*\)/\[prettier\/pre

## prettierx 0.3.1-dev

TBD
### prettier 1.16.1

[diff](https://github.com/prettier/prettier/compare/1.16.0...1.16.1)

- JavaScript: Do not format functions with arguments as react hooks ([#5778] by [@SimenB])

The formatting added in Prettier 1.16 would format any function receiving an
arrow function and an array literal to match React Hook's documentation.
Prettier will now format this the same as before that change if the arrow
function receives any arguments.

<!-- prettier-ignore -->
```js
// Input
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
(allColors, color) => {
return allColors.concat(color);
},
[]
);

// Output (Prettier 1.16.0)
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce((
allColors,
color
) => {
return allColors.concat(color);
}, []);

// Output (Prettier 1.16.1)
["red", "white", "blue", "black", "hotpink", "rebeccapurple"].reduce(
(allColors, color) => {
return allColors.concat(color);
},
[]
);
```

- JavaScript: Add necessary parentheses for decorators ([#5785] by [@ikatyang])

Parentheses for decorators with nested call expressions are optional for legacy decorators
but they're required for decorators in the current [proposal](https://tc39.github.io/proposal-decorators/#sec-syntax).

<!-- prettier-ignore -->
```js
// Input
class X {
@(computed().volatile())
prop
}

// Output (Prettier 1.16.0)
class X {
@computed().volatile()
prop
}

// Output (Prettier 1.16.1)
class X {
@(computed().volatile())
prop
}
```

- TypeScript: Stable parentheses for function type in the return type of arrow function ([#5790] by [@ikatyang])

There's a regression introduced in 1.16 that
parentheses for function type in the return type of arrow function were kept adding/removing.
Their parentheses are always printed now.

<!-- prettier-ignore -->
```ts
// Input
const foo = (): (() => void) => (): void => null;
const bar = (): () => void => (): void => null;

// First Output (Prettier 1.16.0)
const foo = (): () => void => (): void => null;
const bar = (): (() => void) => (): void => null;

// Second Output (Prettier 1.16.0)
const foo = (): (() => void) => (): void => null;
const bar = (): () => void => (): void => null;

// Output (Prettier 1.16.1)
const foo = (): (() => void) => (): void => null;
const bar = (): (() => void) => (): void => null;
```

- MDX: Correctly recognize inline JSX ([#5783] by [@ikatyang])

Previously, some inline JSXs are wrongly recognized as block HTML/JSX,
which causes unexpected behaviors. This issue is now fixed.

<!-- prettier-ignore -->
```md
<!-- Input -->
_foo <InlineJSX /> bar_

<!-- Output (Prettier 1.16.0) -->
_foo

<InlineJSX /> bar_

<!-- Output (Prettier 1.16.1) -->
_foo <InlineJSX /> bar_
```

[@ikatyang]: https://github.com/ikatyang
[@simenb]: https://github.com/SimenB
[#5778]: https://github.com/prettier/prettier/pull/5778
[#5783]: https://github.com/prettier/prettier/pull/5783
[#5785]: https://github.com/prettier/prettier/pull/5785
[#5790]: https://github.com/prettier/prettier/pull/5790

### prettier 1.16.0

[diff](https://github.com/prettier/prettier/compare/1.15.3...1.16.0)

🔗 [Release Notes](https://prettier.io/blog/2019/01/20/1.16.0.html)

## prettierx 0.3.0

Expand Down
43 changes: 43 additions & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!--
Format:
- Category: Title ([#PR] by [@user])
Description
```
// Input
Code Sample
// Output (Prettier stable)
Code Sample
// Output (Prettier master)
Code Sample
```
Details:
Description: optional if the `Title` is enough to explain everything.
Examples:
- TypeScript: Correctly handle `//` in TSX ([#5728] by [@JamesHenry])
Previously, putting `//` as a child of a JSX element in TypeScript led to an error
because it was interpreted as a comment. Prettier master fixes this issue.
<!-- prettier-ignore --\>
```js
// Input
const link = <a href="example.com">http://example.com</a>
// Output (Prettier stable)
// Error: Comment location overlaps with node location
// Output (Prettier master)
const link = <a href="example.com">http://example.com</a>;
```
-->
2 changes: 1 addition & 1 deletion docs/editors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ For more details see [the Vim setup guide](vim.md).

## Visual Studio Code

`prettier-vscode` can be installed using the extension sidebar. Search for `Prettier - Code formatter`. It can also be installed using `ext install prettier-vscode` in the command palette. [Check its repository for configuration and shortcuts](https://github.com/prettier/prettier-vscode).
`prettier-vscode` can be installed using the extension sidebar. Search for `Prettier - Code formatter`. It can also be installed using `ext install esbenp.prettier-vscode` in the command palette. [Check its repository for configuration and shortcuts](https://github.com/prettier/prettier-vscode).

If you'd like to toggle the formatter on and off, install [`vscode-status-bar-format-toggle`](https://marketplace.visualstudio.com/items?itemName=tombonnike.vscode-status-bar-format-toggle).

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"jest-snapshot-serializer-raw": "1.1.0",
"jest-watch-typeahead": "0.1.0",
"mkdirp": "0.5.1",
"prettier": "1.15.3",
"prettier": "1.16.1",
"prettylint": "1.0.0",
"rimraf": "2.6.2",
"rollup": "0.47.6",
Expand Down
5 changes: 5 additions & 0 deletions scripts/release/steps/update-version.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const execa = require("execa");
const { logPromise, readJson, writeJson, processFile } = require("../utils");

async function bump({ version }) {
Expand All @@ -14,6 +15,10 @@ async function bump({ version }) {
processFile(".github/ISSUE_TEMPLATE/integration.md", content =>
content.replace(/^(- Prettier Version: ).*?$/m, `$1${version}`)
);

await execa("yarn", ["update-stable-docs"], {
cwd: "./website"
});
}

module.exports = async function(params) {
Expand Down
20 changes: 14 additions & 6 deletions src/common/load-plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const path = require("path");
const resolve = require("resolve");
const thirdParty = require("./third-party");
const internalPlugins = require("./internal-plugins");
const partition = require("../utils/partition");

function loadPlugins(plugins, pluginSearchDirs) {
if (!plugins) {
Expand All @@ -24,7 +25,12 @@ function loadPlugins(plugins, pluginSearchDirs) {
}
}

const externalManualLoadPluginInfos = plugins.map(pluginName => {
const [externalPluginNames, externalPluginInstances] = partition(
plugins,
plugin => typeof plugin === "string"
);

const externalManualLoadPluginInfos = externalPluginNames.map(pluginName => {
let requirePath;
try {
// try local files
Expand Down Expand Up @@ -69,12 +75,14 @@ function loadPlugins(plugins, pluginSearchDirs) {
const externalPlugins = uniqBy(
externalManualLoadPluginInfos.concat(externalAutoLoadPluginInfos),
"requirePath"
).map(externalPluginInfo =>
Object.assign(
{ name: externalPluginInfo.name },
eval("require")(externalPluginInfo.requirePath)
)
.map(externalPluginInfo =>
Object.assign(
{ name: externalPluginInfo.name },
eval("require")(externalPluginInfo.requirePath)
)
)
);
.concat(externalPluginInstances);

return internalPlugins.concat(externalPlugins);
}
Expand Down
12 changes: 1 addition & 11 deletions src/language-js/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,18 +610,8 @@ function printHtmlTemplateLiteral(path, print, textToDoc, parser) {
}

const placeholderIndex = +component;

parts.push(
concat([
"${",
group(
concat([
indent(concat([softline, expressionDocs[placeholderIndex]])),
softline
])
),
"}"
])
concat(["${", group(expressionDocs[placeholderIndex]), "}"])
);
}

Expand Down
54 changes: 49 additions & 5 deletions src/language-js/needs-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,35 @@ function needsParens(path, options) {
return true;
}

if (parent.type === "Decorator" && parent.expression === node) {
let hasCallExpression = false;
let hasMemberExpression = false;
let current = node;
while (current) {
switch (current.type) {
case "MemberExpression":
hasMemberExpression = true;
current = current.object;
break;
case "CallExpression":
if (
/** @(x().y) */ hasMemberExpression ||
/** @(x().y()) */ hasCallExpression
) {
return true;
}
hasCallExpression = true;
current = current.callee;
break;
case "Identifier":
return false;
default:
return true;
}
}
return true;
}

if (
(parent.type === "ArrowFunctionExpression" &&
parent.body === node &&
Expand Down Expand Up @@ -276,11 +305,6 @@ function needsParens(path, options) {
parent.left === node &&
(node.type === "TSTypeAssertion" || node.type === "TSAsExpression")
);
case "Decorator":
return (
parent.expression === node &&
(node.type === "TSTypeAssertion" || node.type === "TSAsExpression")
);

case "BinaryExpression":
case "LogicalExpression": {
Expand Down Expand Up @@ -329,6 +353,20 @@ function needsParens(path, options) {

case "TSParenthesizedType": {
const grandParent = path.getParentNode(1);

/**
* const foo = (): (() => void) => (): void => null;
* ^ ^
*/
if (
getUnparenthesizedNode(node).type === "TSFunctionType" &&
parent.type === "TSTypeAnnotation" &&
grandParent.type === "ArrowFunctionExpression" &&
grandParent.returnType === parent
) {
return true;
}

if (
(parent.type === "TSTypeParameter" ||
parent.type === "TypeParameter" ||
Expand Down Expand Up @@ -695,6 +733,12 @@ function isStatement(node) {
);
}

function getUnparenthesizedNode(node) {
return node.type === "TSParenthesizedType"
? getUnparenthesizedNode(node.typeAnnotation)
: node;
}

function endsWithRightBracket(node) {
switch (node.type) {
case "ObjectExpression":
Expand Down
1 change: 1 addition & 0 deletions src/language-js/printer-estree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3979,6 +3979,7 @@ function printArgumentsList(path, options, print) {
if (
args.length === 2 &&
args[0].type === "ArrowFunctionExpression" &&
args[0].params.length === 0 &&
args[0].body.type === "BlockStatement" &&
args[1].type === "ArrayExpression" &&
!args.find(arg => arg.leadingComments || arg.trailingComments)
Expand Down

0 comments on commit ae7889f

Please sign in to comment.