You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+4-12Lines changed: 4 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,24 +20,16 @@ pre-commit](https://pre-commit.com/#r). Hence, it should have `language: r` in `
20
20
Hooks should be tested by checking both the positive outcome (hook passes) and
21
21
the negative outcome (hook fails) by adding two `run_test()` statements to
22
22
[`./tests/testthat/test-hooks.R`](https://github.com/lorenzwalthert/precommit/blob/main/tests/testthat/test-hooks.R). Look at existing examples and [the documentation
23
-
of `run_test()`](https://lorenzwalthert.github.io/precommit/reference/run_test.html). Note that this won't actually use pre-commit. It will simply
24
-
call the hook script the same way as pre-commit would, with the difference that
25
-
the test uses a path to the `Rscript` executable whereas with pre-commit, the
26
-
shebang is needed. Hence, omitting the shebang in your script will indicated
27
-
passed tests, but this will be false positive. Also, there is no easy way to
28
-
test if a hook is correctly registered in `.pre-commit-hooks.yaml`
29
-
30
-
For this reason, always test the hook manually end-to-end with
of `run_test()`](https://lorenzwalthert.github.io/precommit/reference/run_test.html). Note that this won't interact with pre-commit. It will simply
24
+
run `Rscript path/to/script.R` (whereas with pre-commit, a {renv} will be activated before running the script). Also, there are [tests](https://github.com/lorenzwalthert/precommit/blob/main/.github/workflows/end-to-end.yml) to ensure that hooks are correctly registered in `.pre-commit-hooks.yaml`.
33
25
34
26
# Summary
35
27
36
-
- add your script in `inst/hooks/exported` and make it executable. Only R scripts are currently supported as testing is done with `Rscript ...`. See other scripts in `inst/hooks/exported` for a starting point for setting up your script.
28
+
- add your R (with extension) script in `inst/hooks/exported` and make it executable. See other scripts in `inst/hooks/exported` for a starting point for setting up your script.
37
29
38
30
- register hook in `.pre-commit-hooks.yaml`.
39
31
40
-
- add two unit tests, test manually with `pre-commit try-repo`.
32
+
- add two unit tests, test manually with `pre-commit try-repo` and adapt the [end-to-end test](https://github.com/lorenzwalthert/precommit/blob/main/.github/workflows/end-to-end.yml).
41
33
42
34
- add a description of the new hook to `vignettes/available-hooks.Rmd`. Both description and
0 commit comments