Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions crates/vp_migration/src/vite_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -917,12 +917,9 @@ fn indent_multiline(s: &str, spaces: usize) -> String {
let indent = " ".repeat(spaces);
let lines: Vec<&str> = s.lines().collect();

if lines.len() <= 1 {
return s.to_string();
}

// First line doesn't get indented (it's on the same line as the key)
// Subsequent lines get the specified indent
// Join even single-line input so the generated comma stays inside the YAML block.
lines
.iter()
.enumerate()
Expand Down Expand Up @@ -1889,6 +1886,31 @@ export default defineConfig({});"#;
assert_eq!(indent_multiline(input, 4), expected);
}

#[test]
fn test_indent_multiline_trailing_line_endings() {
for ending in ["\n", "\r\n"] {
assert_eq!(indent_multiline(&format!("single line{ending}"), 4), "single line");
assert_eq!(
indent_multiline(&format!("first{ending}second{ending}"), 4),
"first\n second"
);
}
}

#[test]
fn test_merge_single_line_json_config_with_trailing_line_endings() {
let vite_config = "export default defineConfig({ plugins: [] });";
for ending in ["", "\n", "\r\n"] {
let oxfmt_config = format!("{{\"singleQuote\":true}}{ending}");
let result = merge_json_config_content(vite_config, &oxfmt_config, "fmt").unwrap();
assert!(result.updated);
assert_eq!(
result.content,
"export default defineConfig({\n fmt: {\"singleQuote\":true},\n plugins: []\n});"
);
}
}

#[test]
fn test_merge_json_config_content_no_trailing_comma() {
// Config WITHOUT trailing comma - lint is placed first to avoid comma issues
Expand Down
Loading