diff --git a/cli/tools/fmt.rs b/cli/tools/fmt.rs index 9c2c709129..c2c2a6bb6b 100644 --- a/cli/tools/fmt.rs +++ b/cli/tools/fmt.rs @@ -549,7 +549,11 @@ pub fn format_sql( // Add single new line to the end of file. formatted_str.push('\n'); - Ok(Some(formatted_str)) + Ok(if formatted_str == file_text { + None + } else { + Some(formatted_str) + }) } /// Formats a single TS, TSX, JS, JSX, JSONC, JSON, MD, IPYNB or SQL file. diff --git a/tests/specs/fmt/sql/__test__.jsonc b/tests/specs/fmt/sql/__test__.jsonc index a335e79c24..27c08abd83 100644 --- a/tests/specs/fmt/sql/__test__.jsonc +++ b/tests/specs/fmt/sql/__test__.jsonc @@ -7,7 +7,7 @@ }, "flag": { "args": "fmt --unstable-sql", - "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" + "output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n" }, "config_file": { "steps": [{ @@ -18,8 +18,12 @@ "output": "[WILDCARD]" }, { "args": "fmt", - "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" + "output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n" }] + }, + "well_formatted_check": { + "args": "fmt --unstable-sql --check well_formatted.sql", + "output": "Checked 1 file\n" } } }