Skip to content
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

Add a less verbose second hook #269

Open
randolf-scholz opened this issue May 2, 2024 · 4 comments
Open

Add a less verbose second hook #269

randolf-scholz opened this issue May 2, 2024 · 4 comments

Comments

@randolf-scholz
Copy link

randolf-scholz commented May 2, 2024

pyright's output is quite verbose for a pre-commit hook. We can combine it with grep to give much less verbose output:

hooks:
  - id: pyright
    entry: bash -c '! pyright "$@" | grep -Po "(?<=$PWD/)(.*:.*)"' --

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.

@randolf-scholz
Copy link
Author

randolf-scholz commented May 2, 2024

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/)(.*:.*)"' --

@randolf-scholz
Copy link
Author

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
          ' --

@RobertCraigie
Copy link
Owner

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?

@RobertCraigie RobertCraigie reopened this Aug 14, 2024
@randolf-scholz
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants