Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(graphql): Keep useful empty lines in description #13013

Merged
merged 6 commits into from Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 34 additions & 0 deletions changelog_unreleased/graphql/13013.md
@@ -0,0 +1,34 @@
#### Keep useful empty lines in description (#13013 by @chimurai)

<!-- prettier-ignore -->
```graphql
# Input
"""
First line
Second Line
"""
type Person {
name: String
}

# Prettier 2.7.0
"""
First line
Second Line
"""
type Person {
name: String
}


# Prettier main
"""
First line
Second Line
"""
type Person {
name: String
}
```
9 changes: 5 additions & 4 deletions src/language-graphql/printer-graphql.js
Expand Up @@ -130,10 +130,11 @@ function genericPrint(path, options, print) {
lines[0] = lines[0].trim();
}

return join(
hardline,
['"""', ...(lines.length > 0 ? lines : []), '"""'].filter(Boolean)
fisker marked this conversation as resolved.
Show resolved Hide resolved
);
if (lines.every((line) => line === "")) {
lines.length = 0;
}

return join(hardline, ['"""', ...lines, '"""']);
}
return [
'"',
Expand Down
97 changes: 97 additions & 0 deletions tests/format/graphql/string/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -32,6 +32,55 @@ type Person {name: String}
"""
type Person {name: String}


"""


Empty lines before
"""
type Person {name: String}

"""
Empty lines after


"""
type Person {name: String}

"""


Empty lines around


"""
type Person {name: String}

"""
First line

Second Line
"""
type Person {name: String}

"""


First line

Second Line
"""
type Person {name: String}

"""
First line

Second Line


"""
type Person {name: String}

=====================================output=====================================
"""
Customer
Expand Down Expand Up @@ -74,6 +123,54 @@ type Person {
name: String
}

"""
Empty lines before
"""
type Person {
name: String
}

"""
Empty lines after
"""
type Person {
name: String
}

"""
Empty lines around
"""
type Person {
name: String
}

"""
First line

Second Line
"""
type Person {
name: String
}

"""
First line

Second Line
"""
type Person {
name: String
}

"""
First line

Second Line
"""
type Person {
name: String
}

================================================================================
`;

Expand Down
49 changes: 49 additions & 0 deletions tests/format/graphql/string/description.graphql
Expand Up @@ -23,3 +23,52 @@ type Person {name: String}
2
"""
type Person {name: String}


"""
Empty lines before
"""
type Person {name: String}

"""
Empty lines after
"""
type Person {name: String}

"""
Empty lines around
"""
type Person {name: String}

"""
First line
Second Line
"""
type Person {name: String}

"""
First line
Second Line
"""
type Person {name: String}

"""
First line
Second Line
"""
type Person {name: String}