Open randolf-scholz opened 4 months ago
A version that preserves the coloring of pyright
, based on https://stackoverflow.com/a/20401674:
entry: bash -c '! script -fqc "$(printf "%q " pyright "$@")" /dev/null | grep --color=never -Po "(?<=$PWD/)(.*:.*)"' --
EDIT: This should also work
entry: sh -c '! script -c "pyright $*" /dev/null | grep --color=never -Po "(?<=$PWD/)(.*:.*)"' --
There seems to be no interest in such a feature, therefore closing. People who want more concise output can use a config like:
- repo: https://github.com/RobertCraigie/pyright-python
rev: <version>
hooks:
- id: pyright
entry: |
sh -c '
result=$(script -c "pyright $*" /dev/null | grep --color=never -Po "(?<=$PWD/)(.*:.*)");
count=$(echo -n "$result" | grep -c "^");
if [ "$count" -ne 0 ]; then
echo "$result";
echo "\033[1;31mFound ${count} errors\033[0m";
exit 1;
fi
' --
Sorry for the lack of response @randolf-scholz, to be clear you'd want the ouptut to just include the number of errors / warnings, no additional information?
pyright
often gives detailed information that can be really useful, but feels too verbose for a pre-commit hook for my taste. The script above limits the output to one line per error message, and includes the total count of violations.
pyright
's output is quite verbose for a pre-commit hook. We can combine it with grep to give much less verbose output:Does it make sense to add this as a second hook, maybe "pyright-minimal"?
Of course, a caveat here is that it is less robust and could silently fail if
$PWD
contains funny special characters.