If I run dotnet build in PowerShell to build a .NET project, at the end of the output, I see a message that tells me how many warnings and errors the compiler generated while building my project. I have attached an example below.
How can I get an error count with GHC? I am using stack, which uses cabal, which in turn uses GHC. A solution at any of those levels is fine.
I can get counts of the warnings or errors by piping the standard error of stack build into vim and using some search functionality in vim. However, I do not always get the correct results. When my source code or source file names contain the word "warning" or the word "error", the results of my search include false positives.
I would like a simple way to get the exact error and warning count. Perhaps, there is a command line flag or a simple wrapper that I can use? I looked through the man page for GHC and found no flag for error and/or warning counts.
I have read this similar stack overflow post for gcc. The answer to that question is not very encouraging, but I am curious if anyone else has some insight to share, and I am hoping GHC has a different story.
NOTE: I am using bash as my shell, so please gear any shell scripting towards bash.

You can use the
-ddump-jsonflag to produce output as JSON and then usejqto filter based on severity. Finally, you have the good oldwc -lfor counting. This is how you get the number of errors, for example: