Skip to content

Commit 3db44a2

Browse files
adapt for language: r
1 parent 3c88a02 commit 3db44a2

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,16 @@ pre-commit](https://pre-commit.com/#r). Hence, it should have `language: r` in `
2020
Hooks should be tested by checking both the positive outcome (hook passes) and
2121
the negative outcome (hook fails) by adding two `run_test()` statements to
2222
[`./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
31-
`pre-commit try-repo` as described in the
32-
[documentation](https://pre-commit.com/#pre-commit-try-repo).
23+
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`.
3325

3426
# Summary
3527

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.
3729

3830
- register hook in `.pre-commit-hooks.yaml`.
3931

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).
4133

4234
- add a description of the new hook to `vignettes/available-hooks.Rmd`. Both description and
4335
`yaml` example code.

0 commit comments

Comments
 (0)