Day 23: precommit

Welcome back for the 23rd day of the #packagecalendar, today we will be taking a look at the precommit package by Lorenz Walthert.

The package is not yet available from CRAN but can be downloaded with the following line of code. Also you need to have conda installed.

remotes::install_github("lorenzwalthert/precommit")
precommit::install_precommit()

Once you installed what you need you just run

precommit::use_precommit()

to initiate the use of pre-commit. Now every time you run git commit the hooks listed in your .pre-commit-config.yaml will be executed before the commit.

The package website includes a section on available hooks included in the package. This includes things like

and

Simply run precommit::open_config() to start configuring the hooks you want.

Lastly, I’ll quote a word of warning from the README > Do not abort while hooks are running. Non-staged changes are stashed to a temp directory when the hooks are run and may not easily be recovered afterwards.