shellcheck icon indicating copy to clipboard operation
shellcheck copied to clipboard

[new feature request] shellcheck summary with stats

Open weakcamel opened this issue 3 years ago • 1 comments

For new checks and feature suggestions

  • [x] https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this (not applicable)
  • [x] I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

I believe it would be interesting to see a very simple summary of findings by shellcheck

  • to be able to "roughly" assess the quality, provide a report etc.
  • potentially, to be able to extract the number of findings and e.g. fail the CI build if number of findings has increased

Here's a snippet or screenshot that shows the problem:

#!/bin/bash

FOO=test.sh

ls $0

Here's what shellcheck currently says:

$ shellcheck test.sh

In test.sh line 3:
FOO=test.sh
^-^ SC2034: FOO appears unused. Verify use (or export if used externally).


In test.sh line 5:
ls $0
   ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
ls "$0"

For more information:
  https://www.shellcheck.net/wiki/SC2034 -- FOO appears unused. Verify use (o...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

Here's what I wanted or expected to see:

$ shellcheck test.sh

In test.sh line 3:
FOO=test.sh
^-^ SC2034: FOO appears unused. Verify use (or export if used externally).


In test.sh line 5:
ls $0
   ^-- SC2086: Double quote to prevent globbing and word splitting.

Did you mean:
ls "$0"

For more information:
  https://www.shellcheck.net/wiki/SC2034 -- FOO appears unused. Verify use (o...
  https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...

Summary of findings:
  error: 0
  warning: 1
  info: 1
  style: 0
  TOTAL: 2

weakcamel avatar Jul 17 '20 14:07 weakcamel

This would be awesome to have! I've been spoiled by other popular linters...

Here is my temporary hack of a bash function in the meantime:

function shellcheck-summary {
  # `script` here works like `tee` but preserves colored output
  # - https://stackoverflow.com/a/3515296/149428
  script -q out.txt ./lint.sh

  errors=$(grep -o '(error)' out.txt | wc -l | xargs)
  warns=$(grep -o '(warning)' out.txt | wc -l | xargs)
  infos=$(grep -o '(info)' out.txt | wc -l | xargs)
  styles=$(grep -o '(style)' out.txt | wc -l | xargs)
  
  echo -e "\nshellcheck summary\n"
  echo "- error:   ${errors}"
  echo "- warning: ${warns}"
  echo "- info:    ${infos}"
  echo "- style:   ${styles}"

  rm out.txt
}

(lint.sh is a script that runs my shellcheck command and some other stuff, but you could probably just put the shellcheck command in here directly as an alternative)

tedmiston avatar Jul 14 '22 18:07 tedmiston