Make `-f diff` stop saying it found more issues when it didn't.

This commit is contained in:
Vidar Holen 2019-07-28 20:50:50 -07:00
parent b7b4d5d29e
commit c175971bf0
2 changed files with 16 additions and 9 deletions

View File

@ -1,3 +1,7 @@
## v0.7.1 - soon
### Fixed
- `-f diff` no longer claims that it found more issues when it didn't
## v0.7.0 - 2019-07-28 ## v0.7.0 - 2019-07-28
### Added ### Added
- Precompiled binaries for macOS and Linux aarch64 - Precompiled binaries for macOS and Linux aarch64

View File

@ -43,14 +43,15 @@ ltt x = trace (show x) x
format :: FormatterOptions -> IO Formatter format :: FormatterOptions -> IO Formatter
format options = do format options = do
didOutput <- newIORef False foundIssues <- newIORef False
reportedIssues <- newIORef False
shouldColor <- shouldOutputColor (foColorOption options) shouldColor <- shouldOutputColor (foColorOption options)
let color = if shouldColor then colorize else nocolor let color = if shouldColor then colorize else nocolor
return Formatter { return Formatter {
header = return (), header = return (),
footer = checkFooter didOutput color, footer = checkFooter foundIssues reportedIssues color,
onFailure = reportFailure color, onFailure = reportFailure color,
onResult = reportResult didOutput color onResult = reportResult foundIssues reportedIssues color
} }
@ -69,9 +70,10 @@ printErr :: ColorFunc -> String -> IO ()
printErr color = hPutStrLn stderr . color bold . color red printErr color = hPutStrLn stderr . color bold . color red
reportFailure color file msg = printErr color $ file ++ ": " ++ msg reportFailure color file msg = printErr color $ file ++ ": " ++ msg
checkFooter didOutput color = do checkFooter foundIssues reportedIssues color = do
output <- readIORef didOutput found <- readIORef foundIssues
unless output $ output <- readIORef reportedIssues
when (found && not output) $
printErr color "Issues were detected, but none were auto-fixable. Use another format to see them." printErr color "Issues were detected, but none were auto-fixable. Use another format to see them."
type ColorFunc = (Int -> String -> String) type ColorFunc = (Int -> String -> String)
@ -79,9 +81,10 @@ data LFStatus = LinefeedMissing | LinefeedOk
data DiffDoc a = DiffDoc String LFStatus [DiffRegion a] data DiffDoc a = DiffDoc String LFStatus [DiffRegion a]
data DiffRegion a = DiffRegion (Int, Int) (Int, Int) [Diff a] data DiffRegion a = DiffRegion (Int, Int) (Int, Int) [Diff a]
reportResult :: (IORef Bool) -> ColorFunc -> CheckResult -> SystemInterface IO -> IO () reportResult :: (IORef Bool) -> (IORef Bool) -> ColorFunc -> CheckResult -> SystemInterface IO -> IO ()
reportResult didOutput color result sys = do reportResult foundIssues reportedIssues color result sys = do
let comments = crComments result let comments = crComments result
unless (null comments) $ writeIORef foundIssues True
let suggestedFixes = mapMaybe pcFix comments let suggestedFixes = mapMaybe pcFix comments
let fixmap = buildFixMap suggestedFixes let fixmap = buildFixMap suggestedFixes
mapM_ output $ M.toList fixmap mapM_ output $ M.toList fixmap
@ -91,7 +94,7 @@ reportResult didOutput color result sys = do
case file of case file of
Right contents -> do Right contents -> do
putStrLn $ formatDoc color $ makeDiff name contents fix putStrLn $ formatDoc color $ makeDiff name contents fix
writeIORef didOutput True writeIORef reportedIssues True
Left msg -> reportFailure color name msg Left msg -> reportFailure color name msg
hasTrailingLinefeed str = hasTrailingLinefeed str =