Skip to content

Commit

Permalink
bugfix(graphql): Keep useful empty lines in description (prettier#13013)
Browse files Browse the repository at this point in the history
Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
2 people authored and medikoo committed Jan 4, 2024
1 parent 8e68ef5 commit 29a3ab3
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 4 deletions.
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)
);
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}

0 comments on commit 29a3ab3

Please sign in to comment.