mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(formatter_graphql): improve major prettier diffs (#23419)
Fixed some minor formatting diffs by checking real world repo.
This commit is contained in:
1 parent
48e2d7855b
commit
3f355e5c22
3 files changed
+119
-2
No files matched your search
@@ -127,8 +127,14 @@ fn write_block_string(body: &str, f: &mut GraphqlFormatter<'_, '_>) {
|
||||
|
||||
// Prettier: re-escape, then `lines.length === 1` → trim,
|
||||
// all-blank → drop everything.
|
||||
let mut lines: Vec<String> =
|
||||
cooked_lines.iter().map(|l| l.cow_replace("\"\"\"", "\\\"\"\"").into_owned()).collect();
|
||||
// Trailing spaces/tabs are trimmed per line: Prettier's doc printer trims
|
||||
// them at every hardline. The core printer does the same, but a line
|
||||
// followed by a blank-line run gets its break from raw `\n` text (see
|
||||
// `write_block_string_break`), which bypasses that trim — so trim here.
|
||||
let mut lines: Vec<String> = cooked_lines
|
||||
.iter()
|
||||
.map(|l| l.trim_end_matches([' ', '\t']).cow_replace("\"\"\"", "\\\"\"\"").into_owned())
|
||||
.collect();
|
||||
if lines.len() == 1 {
|
||||
lines[0] = lines[0].trim().to_string();
|
||||
}
|
||||
|
||||
Vendored
+24
@@ -0,0 +1,24 @@
|
||||
type A {
|
||||
"""
|
||||
Trailing spaces after this sentence.
|
||||
|
||||
Trailing tab after this sentence.
|
||||
Last line before closing quotes also has them.
|
||||
"""
|
||||
a: String
|
||||
|
||||
"""
|
||||
The line below is whitespace-only, deeper than the common indent:
|
||||
|
||||
It must become a blank line, not indented whitespace.
|
||||
"""
|
||||
b: String
|
||||
|
||||
"""
|
||||
Multiple blank lines below keep their run length:
|
||||
|
||||
|
||||
even when they are whitespace-only in the source.
|
||||
"""
|
||||
c: String
|
||||
}
|
||||
Vendored
+87
@@ -0,0 +1,87 @@
|
||||
---
|
||||
source: crates/oxc_formatter_graphql/tests/fixtures/mod.rs
|
||||
---
|
||||
==================== Input ====================
|
||||
type A {
|
||||
"""
|
||||
Trailing spaces after this sentence.
|
||||
|
||||
Trailing tab after this sentence.
|
||||
Last line before closing quotes also has them.
|
||||
"""
|
||||
a: String
|
||||
|
||||
"""
|
||||
The line below is whitespace-only, deeper than the common indent:
|
||||
|
||||
It must become a blank line, not indented whitespace.
|
||||
"""
|
||||
b: String
|
||||
|
||||
"""
|
||||
Multiple blank lines below keep their run length:
|
||||
|
||||
|
||||
even when they are whitespace-only in the source.
|
||||
"""
|
||||
c: String
|
||||
}
|
||||
|
||||
==================== Output ====================
|
||||
------------------
|
||||
{ printWidth: 80 }
|
||||
------------------
|
||||
type A {
|
||||
"""
|
||||
Trailing spaces after this sentence.
|
||||
|
||||
Trailing tab after this sentence.
|
||||
Last line before closing quotes also has them.
|
||||
"""
|
||||
a: String
|
||||
|
||||
"""
|
||||
The line below is whitespace-only, deeper than the common indent:
|
||||
|
||||
It must become a blank line, not indented whitespace.
|
||||
"""
|
||||
b: String
|
||||
|
||||
"""
|
||||
Multiple blank lines below keep their run length:
|
||||
|
||||
|
||||
even when they are whitespace-only in the source.
|
||||
"""
|
||||
c: String
|
||||
}
|
||||
|
||||
-------------------
|
||||
{ printWidth: 100 }
|
||||
-------------------
|
||||
type A {
|
||||
"""
|
||||
Trailing spaces after this sentence.
|
||||
|
||||
Trailing tab after this sentence.
|
||||
Last line before closing quotes also has them.
|
||||
"""
|
||||
a: String
|
||||
|
||||
"""
|
||||
The line below is whitespace-only, deeper than the common indent:
|
||||
|
||||
It must become a blank line, not indented whitespace.
|
||||
"""
|
||||
b: String
|
||||
|
||||
"""
|
||||
Multiple blank lines below keep their run length:
|
||||
|
||||
|
||||
even when they are whitespace-only in the source.
|
||||
"""
|
||||
c: String
|
||||
}
|
||||
|
||||
===================== End =====================
|
||||
Reference in new issue
Block a user