Skip to content

Commit

Permalink
Merge tag '2.1.2' into elastic
Browse files Browse the repository at this point in the history
Release 2.1.2
  • Loading branch information
medikoo committed Nov 16, 2020
2 parents 4a5f3cf + 8eb8f9e commit 505e77e
Show file tree
Hide file tree
Showing 22 changed files with 520 additions and 57 deletions.
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 2.1.1**
**Prettier 2.1.2**
[Playground link](https://prettier.io/playground/#.....)

```sh
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 @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:

**Environments:**

- Prettier Version: 2.1.1
- Prettier Version: 2.1.2
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
Expand Down
122 changes: 122 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,125 @@
# 2.1.2

[diff](https://github.com/prettier/prettier/compare/2.1.1...2.1.2)

#### Fix formatting for directives in fields ([#9116](https://github.com/prettier/prettier/pull/9116) by [@sosukesuzuki](https://github.com/sosukesuzuki))

<!-- prettier-ignore -->
```graphql
# Input
type Query {
someQuery(id: ID!, someOtherData: String!): String! @deprecated @isAuthenticated
versions: Versions!
}


# Prettier stable
type Query {
someQuery(id: ID!, someOtherData: String!): String!
@deprecated
@isAuthenticated
versions: Versions!
}

# Prettier master
type Query {
someQuery(id: ID!, someOtherData: String!): String!
@deprecated
@isAuthenticated
versions: Versions!
}

```

#### Fix line breaks for CSS in JS ([#9136](https://github.com/prettier/prettier/pull/9136) by [@sosukesuzuki](https://github.com/sosukesuzuki))

<!-- prettier-ignore -->
```js
// Input
styled.div`
// prettier-ignore
@media (aaaaaaaaaaaaa) {
z-index: ${(props) => (props.isComplete ? '1' : '0')};
}
`;
styled.div`
${props => getSize(props.$size.xs)}
${props => getSize(props.$size.sm, 'sm')}
${props => getSize(props.$size.md, 'md')}
`;

// Prettier stable
styled.div`
// prettier-ignore
@media (aaaaaaaaaaaaa) {
z-index: ${(props) =>
props.isComplete ? "1" : "0"};
}
`;
styled.div`
${(props) => getSize(props.$size.xs)}
${(props) => getSize(props.$size.sm, "sm")}
${(props) =>
getSize(props.$size.md, "md")}
`;

// Prettier master
styled.div`
// prettier-ignore
@media (aaaaaaaaaaaaa) {
z-index: ${(props) => (props.isComplete ? "1" : "0")};
}
`;
styled.div`
${(props) => getSize(props.$size.xs)}
${(props) => getSize(props.$size.sm, "sm")}
${(props) => getSize(props.$size.md, "md")}
`;

```

#### Fix comment printing in mapping and sequence ([#9143](https://github.com/prettier/prettier/pull/9143), [#9169](https://github.com/prettier/prettier/pull/9169) by [@sosukesuzuki](https://github.com/sosukesuzuki), [@fisker](https://github.com/fisker), fix in `yaml-unist-parser` by [@ikatyang](https://github.com/ikatyang))

<!-- prettier-ignore -->
```yaml
# Input
- a
# Should indent
- bb

---
- a: a
b: b

# Should print one empty line before
- another

# Prettier stable
- a
# Should indent
- bb

---
- a: a
b: b


# Should print one empty line before
- another

# Prettier master
- a
# Should indent
- bb

---
- a: a
b: b

# Should print one empty line before
- another
```

# 2.1.1

[diff](https://github.com/prettier/prettier/compare/2.1.0...2.1.1)
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@
"ignoreRegExpList": [
"<!-- prettier-ignore -->\\n(`{3,})\\w*\\n[\\s\\S]+?\\1",
"\\[(\\*{2})?@[-\\w]+?\\1\\]",
"by @[-\\w]+(?:, @[-\\w]+)?",
"\\[`\\w+`\\]",
"ve{2,}r{2,}y",
"ve+r+y+long\\w*",
Expand Down
12 changes: 6 additions & 6 deletions docs/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ See [Usage](#usage) below for examples.
### Global

```html
<script src="https://unpkg.com/prettier@2.1.1/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.1.1/parser-graphql.js"></script>
<script src="https://unpkg.com/prettier@2.1.2/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.1.2/parser-graphql.js"></script>
<script>
prettier.format("query { }", {
parser: "graphql",
Expand All @@ -46,8 +46,8 @@ prettier.format("query { }", {

```js
define([
"https://unpkg.com/prettier@2.1.1/standalone.js",
"https://unpkg.com/prettier@2.1.1/parser-graphql.js",
"https://unpkg.com/prettier@2.1.2/standalone.js",
"https://unpkg.com/prettier@2.1.2/parser-graphql.js",
], (prettier, ...plugins) => {
prettier.format("query { }", { parser: "graphql", plugins });
});
Expand All @@ -66,7 +66,7 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker

```js
importScripts("https://unpkg.com/prettier@2.1.1/standalone.js");
importScripts("https://unpkg.com/prettier@2.1.1/parser-graphql.js");
importScripts("https://unpkg.com/prettier@2.1.2/standalone.js");
importScripts("https://unpkg.com/prettier@2.1.2/parser-graphql.js");
prettier.format("query { }", { parser: "graphql", plugins: prettierPlugins });
```
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prettier-elastic",
"version": "2.1.1",
"version": "2.1.2",
"description": "Prettier is an opinionated code formatter",
"bin": "./bin/prettier.js",
"repository": "prettier/prettier",
Expand Down Expand Up @@ -81,7 +81,7 @@
"unicode-regex": "3.0.0",
"unified": "9.2.0",
"vnopts": "1.0.2",
"yaml-unist-parser": "1.3.0"
"yaml-unist-parser": "1.3.1"
},
"devDependencies": {
"@babel/core": "7.11.4",
Expand Down Expand Up @@ -117,7 +117,7 @@
"jest-snapshot-serializer-raw": "1.1.0",
"jest-watch-typeahead": "0.6.0",
"npm-run-all": "4.1.5",
"prettier": "2.1.0",
"prettier": "2.1.1",
"rimraf": "3.0.2",
"rollup": "2.26.5",
"rollup-plugin-node-globals": "1.4.0",
Expand Down
15 changes: 15 additions & 0 deletions src/document/doc-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"use strict";

const { literalline, concat } = require("./doc-builders");

// Using a unique object to compare by reference.
const traverseDocOnExitStackMarker = {};

Expand Down Expand Up @@ -258,6 +260,18 @@ function normalizeDoc(doc) {
});
}

function replaceNewlinesWithLiterallines(doc) {
return mapDoc(doc, (currentDoc) =>
typeof currentDoc === "string" && currentDoc.includes("\n")
? concat(
currentDoc
.split(/(\n)/g)
.map((v, i) => (i % 2 === 0 ? v : literalline))
)
: currentDoc
);
}

module.exports = {
isEmpty,
willBreak,
Expand All @@ -270,4 +284,5 @@ module.exports = {
stripTrailingHardline,
normalizeParts,
normalizeDoc,
replaceNewlinesWithLiterallines,
};
8 changes: 7 additions & 1 deletion src/language-graphql/printer-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,13 @@ function printDirectives(path, print, n) {
return "";
}

return group(concat([line, join(line, path.map(print, "directives"))]));
const printed = join(line, path.map(print, "directives"));

if (n.kind === "FragmentDefinition" || n.kind === "OperationDefinition") {
return group(concat([line, printed]));
}

return concat([" ", group(indent(concat([softline, printed])))]);
}

function printSequence(sequencePath, options, print) {
Expand Down
4 changes: 2 additions & 2 deletions src/language-js/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const {
group,
dedentToRoot,
},
utils: { mapDoc },
utils: { mapDoc, replaceNewlinesWithLiterallines },
} = require("../document");
const { isBlockComment, hasLeadingComment } = require("./comments");

Expand Down Expand Up @@ -301,7 +301,7 @@ function replacePlaceholders(quasisDoc, expressionDocs) {
part.split(/@prettier-placeholder-(\d+)-id/).forEach((component, idx) => {
// The placeholder is always at odd indices
if (idx % 2 === 0) {
replacedParts.push(component);
replacedParts.push(replaceNewlinesWithLiterallines(component));
return;
}

Expand Down
16 changes: 2 additions & 14 deletions src/language-markdown/embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const { getParserName, getMaxContinuousCount } = require("../common/util");
const {
builders: { hardline, literalline, concat, markAsRoot },
utils: { mapDoc },
builders: { hardline, concat, markAsRoot },
utils: { replaceNewlinesWithLiterallines },
} = require("../document");
const { print: printFrontMatter } = require("../utils/front-matter");
const { getFencedCodeBlockValue } = require("./utils");
Expand Down Expand Up @@ -66,18 +66,6 @@ function embed(path, print, textToDoc, options) {
}

return null;

function replaceNewlinesWithLiterallines(doc) {
return mapDoc(doc, (currentDoc) =>
typeof currentDoc === "string" && currentDoc.includes("\n")
? concat(
currentDoc
.split(/(\n)/g)
.map((v, i) => (i % 2 === 0 ? v : literalline))
)
: currentDoc
);
}
}

module.exports = embed;
14 changes: 11 additions & 3 deletions src/language-yaml/printer-yaml.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ function genericPrint(path, options, print) {
])
)
: "",
nextEmptyLine,
hasEndComments(node) && !isNode(node, ["documentHead", "documentBody"])
shouldPrintEndComments(node)
? align(
node.type === "sequenceItem" ? 2 : 0,
concat([
Expand All @@ -153,6 +152,7 @@ function genericPrint(path, options, print) {
])
)
: "",
nextEmptyLine,
]);
}

Expand Down Expand Up @@ -703,6 +703,12 @@ function needsSpaceInFrontOfMappingValue(node) {
return node.key.content && node.key.content.type === "alias";
}

function shouldPrintEndComments(node) {
return (
hasEndComments(node) && !isNode(node, ["documentHead", "documentBody"])
);
}

function printNextEmptyLine(path, originalText) {
const node = path.getValue();
const root = path.stack[0];
Expand All @@ -713,7 +719,9 @@ function printNextEmptyLine(path, originalText) {
if (!root.isNextEmptyLinePrintedChecklist[node.position.end.line]) {
if (isNextLineEmpty(node, originalText)) {
root.isNextEmptyLinePrintedChecklist[node.position.end.line] = true;
return softline;
if (!shouldPrintEndComments(path.getParentNode())) {
return softline;
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/graphql/directives/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ query MyQuery @directive(arg: 5) {
field @skip(if: true) @nope
otherField
...fragmentSpread
@include(if: ["this isn't even a boolean", "wow, that's really odd"])
@include(if: ["this isn't even a boolean", "wow, that's really odd"])
}
fragment YouCanHaveDirectivesHereToo on SomeType @yesReally(what: "yes") {
Expand All @@ -45,10 +45,10 @@ fragment YouCanHaveDirectivesHereToo on SomeType @yesReally(what: "yes") {
}
thisFieldHasALotOfDirectives
@thisIsthefirst
@thisIsTheSecond
@thisIsTheThird
@thisIstheFourthWillBeTooLongForSure(and: "it has arguments as well")
@thisIsthefirst
@thisIsTheSecond
@thisIsTheThird
@thisIstheFourthWillBeTooLongForSure(and: "it has arguments as well")
}
query QueryWVars($x: String) @directive {
Expand Down
14 changes: 7 additions & 7 deletions tests/graphql/newline/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ query MyQuery
arg2: 10
) {
field
@skip(
if: true
@skip(
if: true
# comment
cursor: 10
)
@nope
# comment
cursor: 10
)
@nope
otherField
...fragmentSpread
@include(if: ["this isn't even a boolean", "wow, that's really odd"])
@include(if: ["this isn't even a boolean", "wow, that's really odd"])
}
================================================================================
Expand Down

0 comments on commit 505e77e

Please sign in to comment.