Skip to content

Print 10 violations in normal mode #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 17 additions & 6 deletions FixWhitespace.hs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,15 @@ main = do

fix :: Mode -> Verbose -> TabSize -> FilePath -> IO Bool
fix mode verbose tabSize f =
checkFile tabSize verbose f >>= \case
checkFile tabSize True f >>= \case

CheckOK -> do
when verbose $
putStrLn $ "[ Checked ] " ++ f
return False

CheckViolation s vs -> do
hPutStrLn stderr (msg vs)
Text.hPutStrLn stderr (msg vs)
when (mode == Fix) $
withFile f WriteMode $ \h -> do
hSetEncoding h utf8
Expand All @@ -227,9 +227,20 @@ fix mode verbose tabSize f =
where
msg vs
| mode == Fix =
"[ Violation fixed ] " ++ f
"[ Violation fixed ] " <> Text.pack f

| otherwise =
"[ Violation detected ] " ++ f ++
(if not verbose then "" else
":\n" ++ unlines (map (Text.unpack . displayLineError f) vs))
"[ Violation detected ]:\n" <> Text.pack f <>
(if not verbose then (displayViolations (Just 10) vs)
else (displayViolations Nothing vs))


displayViolations mlimit violations =
let (display_violations, more_violations) =
case mlimit of
Just limit -> splitAt limit violations
Nothing -> (violations, [])
in Text.unlines (map (displayLineError f) display_violations)
<> case more_violations of
[] -> mempty
(_:_) -> "\n... and " <> Text.pack (show (length more_violations)) <> " more violations."
Loading