From 7dc421414920b5e6ed80710afedcbd1d422bdd85 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 17 Jul 2025 13:39:29 -0700 Subject: [PATCH] Normalize \ to / in diff output on Windows (fixes #3240) --- CHANGELOG.md | 1 + src/ShellCheck/Formatter/Diff.hs | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f907ab7..3f834aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ re-enabled with `--enable=useless-use-of-cat` or equivalent directive. - SC2015 about `A && B || C` no longer triggers when B is a test command. - SC3012: Do not warn about `\<` and `\>` in test/[] as specified in POSIX.1-2024 +- Diff output now uses / as path separator on Windows ### Fixed - SC2218 about function use-before-define is now more accurate. - SC2317 about unreachable commands is now less spammy for nested ones. diff --git a/src/ShellCheck/Formatter/Diff.hs b/src/ShellCheck/Formatter/Diff.hs index 15d00d7..c00da1a 100644 --- a/src/ShellCheck/Formatter/Diff.hs +++ b/src/ShellCheck/Formatter/Diff.hs @@ -191,11 +191,17 @@ splitLast x = let (last, rest) = splitAt 1 $ reverse x in (reverse rest, last) +-- git patch does not like `\` on Windows +normalizePath path = + case path of + c:rest -> (if c == pathSeparator then '/' else c) : normalizePath rest + [] -> [] + formatDoc color (DiffDoc name lf regions) = let (most, last) = splitLast regions in - (color bold $ "--- " ++ ("a" name)) ++ "\n" ++ - (color bold $ "+++ " ++ ("b" name)) ++ "\n" ++ + (color bold $ "--- " ++ (normalizePath $ "a" name)) ++ "\n" ++ + (color bold $ "+++ " ++ (normalizePath $ "b" name)) ++ "\n" ++ concatMap (formatRegion color LinefeedOk) most ++ concatMap (formatRegion color lf) last