Skip to content

Commit 34cc545

Browse files
authored
Merge branch 'main' into chore/remove-unused-core-babel-deps
2 parents a61ab5e + a211e03 commit 34cc545

1 file changed

Lines changed: 26 additions & 4 deletions

File tree

crates/vp_migration/src/vite_config.rs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -917,12 +917,9 @@ fn indent_multiline(s: &str, spaces: usize) -> String {
917917
let indent = " ".repeat(spaces);
918918
let lines: Vec<&str> = s.lines().collect();
919919

920-
if lines.len() <= 1 {
921-
return s.to_string();
922-
}
923-
924920
// First line doesn't get indented (it's on the same line as the key)
925921
// Subsequent lines get the specified indent
922+
// Join even single-line input so the generated comma stays inside the YAML block.
926923
lines
927924
.iter()
928925
.enumerate()
@@ -1889,6 +1886,31 @@ export default defineConfig({});"#;
18891886
assert_eq!(indent_multiline(input, 4), expected);
18901887
}
18911888

1889+
#[test]
1890+
fn test_indent_multiline_trailing_line_endings() {
1891+
for ending in ["\n", "\r\n"] {
1892+
assert_eq!(indent_multiline(&format!("single line{ending}"), 4), "single line");
1893+
assert_eq!(
1894+
indent_multiline(&format!("first{ending}second{ending}"), 4),
1895+
"first\n second"
1896+
);
1897+
}
1898+
}
1899+
1900+
#[test]
1901+
fn test_merge_single_line_json_config_with_trailing_line_endings() {
1902+
let vite_config = "export default defineConfig({ plugins: [] });";
1903+
for ending in ["", "\n", "\r\n"] {
1904+
let oxfmt_config = format!("{{\"singleQuote\":true}}{ending}");
1905+
let result = merge_json_config_content(vite_config, &oxfmt_config, "fmt").unwrap();
1906+
assert!(result.updated);
1907+
assert_eq!(
1908+
result.content,
1909+
"export default defineConfig({\n fmt: {\"singleQuote\":true},\n plugins: []\n});"
1910+
);
1911+
}
1912+
}
1913+
18921914
#[test]
18931915
fn test_merge_json_config_content_no_trailing_comma() {
18941916
// Config WITHOUT trailing comma - lint is placed first to avoid comma issues

0 commit comments

Comments
 (0)