Skip to content

Commit 9eee2a0

Browse files
authored
fix(fmt): return None if sql fmt result is the same (#27014)
Similar with #25848, we need to make `format_sql` to return `None` so we do not flag well formatted sql files as being wrong. Signed-off-by: m4rc3l05 <[email protected]>
1 parent 5462b58 commit 9eee2a0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

cli/tools/fmt.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,11 @@ pub fn format_sql(
549549
// Add single new line to the end of file.
550550
formatted_str.push('\n');
551551

552-
Ok(Some(formatted_str))
552+
Ok(if formatted_str == file_text {
553+
None
554+
} else {
555+
Some(formatted_str)
556+
})
553557
}
554558

555559
/// Formats a single TS, TSX, JS, JSX, JSONC, JSON, MD, IPYNB or SQL file.

tests/specs/fmt/sql/__test__.jsonc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"flag": {
99
"args": "fmt --unstable-sql",
10-
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
10+
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
1111
},
1212
"config_file": {
1313
"steps": [{
@@ -18,8 +18,12 @@
1818
"output": "[WILDCARD]"
1919
}, {
2020
"args": "fmt",
21-
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
21+
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
2222
}]
23+
},
24+
"well_formatted_check": {
25+
"args": "fmt --unstable-sql --check well_formatted.sql",
26+
"output": "Checked 1 file\n"
2327
}
2428
}
2529
}

0 commit comments

Comments
 (0)