Skip to content

Commit 4133cf3

Browse files
authored
Merge pull request #18 from jorenham/pyrefly-coverage-check
Add a pre-commit hook for `pyrefly coverage check`
2 parents 4424888 + 20aaea4 commit 4133cf3

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎.pre-commit-hooks.yaml‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77
pass_filenames: false
88
require_serial: true
99
stages: [pre-commit, pre-merge-commit, pre-push, manual]
10+
11+
- id: pyrefly-coverage-check
12+
name: pyrefly coverage check
13+
description: "Run `pyrefly coverage check` to enforce a minimum type coverage."
14+
entry: pyrefly coverage check
15+
language: python
16+
types_or: [python, pyi]
17+
pass_filenames: false
18+
require_serial: true
19+
stages: [pre-commit, pre-merge-commit, pre-push, manual]

‎README.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ repos:
4646
Note that you must list all of your project's dependencies (aside from `pyrefly`, which is bundled with the hook)
4747
in `additional_dependencies` for type checking to work correctly.
4848

49+
### Enforcing Type Coverage
50+
51+
To check type coverage on every commit, add the `pyrefly-coverage-check` hook to your
52+
[prek](https://prek.j178.dev/) or [pre-commit](https://pre-commit.com/) config:
53+
54+
```yaml
55+
repos:
56+
- repo: https://github.com/facebook/pyrefly-pre-commit
57+
rev: <pyrefly version> # 1.5.0 or later
58+
hooks:
59+
- id: pyrefly-coverage-check
60+
args: [--fail-under=80]
61+
```
62+
63+
The hook fails if the type coverage is below the `--fail-under` percentage (default: 100).
64+
See the [Pyrefly docs](https://pyrefly.org/en/docs/report/#checking-coverage-against-a-threshold)
65+
for how coverage is measured and how the threshold works.
66+
Like `pyrefly-check`, it uses the `pyrefly` bundled with the hook. Add `language: system` to
67+
use the `pyrefly` on your `PATH` instead.
68+
4969
### Examples
5070

5171
See the [`examples/`](examples/) directory for complete working examples of both approaches:

0 commit comments

Comments
 (0)