-
-
Notifications
You must be signed in to change notification settings - Fork 51
Description
Before filing a bug
- I have installed the latest dev version of {precommit} with
remotes::install_github('lorenzwalthert/precommit') - I have installed the latest hook revisions (update with
precommit::autoupdate()) - I have installed the latest release of the upstream Python framework pre-comit as described under the update instructions.
Describe the bug
Lintr hook seems to not respect NAMESPACE / use roxygenize hook correctly?
Here is a minimal package with this function:
#' @importFrom checkmate assert_count
plus_one <- function(n) {
assert_count(n)
n + 1
}
Lintr works fine on the package:
> roxygen2::roxygenize()
First time using roxygen2. Upgrading automatically...
ℹ Setting RoxygenNote to "7.3.3"
ℹ Loading PrecommitRTest
Writing NAMESPACE
> library(devtools)
> load_all()
ℹ Loading PrecommitRTest
> lintr:::addin_lint_package()
ℹ No lints found.
But when trying to use precommit:
$ git commit -m "Test"
[INFO] Initializing environment for https://github.com/lorenzwalthert/precommit.
[INFO] Initializing environment for https://github.com/lorenzwalthert/precommit:checkmate.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/pre-commit-ci/pre-commit-ci-config.
[INFO] Installing environment for https://github.com/lorenzwalthert/precommit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/lorenzwalthert/precommit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit-ci/pre-commit-ci-config.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
style-files..............................................................Passed
roxygenize...............................................................Passed
use-tidy-description.....................................................Passed
spell-check..............................................................Passed
lintr....................................................................Failed
- hook id: lintr
- exit code: 1
- The project is out-of-sync -- use `renv::status()` for details.
- The project is out-of-sync -- use `renv::status()` for details.
Warning message:
We detected multiple pre-commit executables. This is likely going to get you into trouble in the future, e.g. when you want to upgrade, as you easily loose track
of different versions. We strongly suggest to only keep one pre-commit executable and uninstall (or delete) the other ones. Here are the locations where we detected executables:
- C:\Users\name\AppData\Roaming\Python\PYTHON~2\Scripts\PRE-CO~1.EXE
- C:/Users/name/AppData/Roaming/Python/Python312/Scripts/pre-commit.exe
Note that in all local repos where you used pre-commit, the executable path is hardcoded (in .git/hooks/pre-commit). Deleting a referenced executable will break pre-commit for that local repo. A simple re-initialization with `precommit::use_precommit()` or `$ pre-commit install` will fix this for pre-commit hooks.
If you have hook types other than pre-commit such as pre-push (you can check which files are in .git/hooks/), you need to name the type and use the command line,
i.e. `$ pre-commit install -t pre-push`.
File `R/hello.R` is not lint free
C:/Users/name/Documents/GitHub/PrecommitRTest/R/hello.R:3:3: warning: [object_usage_linter] no visible global function definition for 'assert_count'
assert_count(n)
^~~~~~~~~~~~
Error: File R/hello.R is not lint free
Execution halted
readme-rmd-rendered..................................(no files to check)Skipped
parsable-R...............................................................Passed
no-browser-statement.....................................................Passed
no-print-statement.......................................................Passed
no-debug-statement.......................................................Passed
deps-in-desc.............................................................Passed
pkgdown..................................................................Passed
check for added large files..............................................Passed
file contents sorter.....................................................Passed
fix end of files.........................................................Passed
check pre-commit.ci config...............................................Passed
Don't commit common R artifacts......................(no files to check)Skipped
It doesn't seem to use the NAMESPACE file / roxygenize hook correctly?
It also seems to give a (fake?) warning about multiple pre-commit executable? I think it's just the same path that it prints in two different ways? For reference here is the content of the folder ...\Python
PS C:\Users\name> Get-ChildItem -Force -Directory "C:\Users\name\AppData\Roaming\Python"
Directory: C:\Users\name\AppData\Roaming\Python
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 1/19/2025 10:29 AM etc
d----- 10/20/2025 5:12 PM Python312
d----- 1/19/2025 10:29 AM share
To Reproduce
Steps to reproduce the behavior:
- Go to Rstudio -> File -> New Project -> New Directory -> R Package
- Change hello.R to this:
#' @importFrom checkmate assert_count
plus_one <- function(n) {
assert_count(n)
n + 1
}
- Run the following code:
> file.remove("NAMESPACE")
[1] TRUE
> library(devtools)
Loading required package: usethis
> use_package("checkmate")
✔ Setting active project to "C:/Users/name/Documents/GitHub/PrecommitRTest".
✔ Adding checkmate to Imports field in DESCRIPTION.
☐ Refer to functions with `checkmate::fun()`.
> roxygen2::roxygenize()
First time using roxygen2. Upgrading automatically...
ℹ Setting RoxygenNote to "7.3.3"
ℹ Loading PrecommitRTest
Writing NAMESPACE
> load_all()
ℹ Loading PrecommitRTest
> lintr:::addin_lint_package()
ℹ No lints found.
lintr works fine.
- Now use precommit:
> precommit::use_precommit()
ℹ Using local config from C:/Users/name/AppData/Local/R/win-library/4.5/precommit/pre-commit-config-pkg.yaml.
✔ Copied .pre-commit-config.yaml to C:/Users/name/Documents/GitHub/PrecommitRTest
✔ Adding ^\.pre-commit-config\.yaml$ to C:/Users/name/Documents/GitHub/PrecommitRTest/.Rbuildignore.
• Edit .precommit-config.yaml to (de)activate the hooks you want to use.
• All available hooks: https://pre-commit.com/hooks.html
• R specific hooks: https://github.com/lorenzwalthert/precommit
✔ Ran `pre-commit autoupdate ()` to get the latest version of the hooks.
ℹ Installing hooks in non-blocking background process. If you experience problems or prefer a blocking process, use `options("precommit.block_install_hooks" = TRUE)`.
• Sign in with GitHub to authenticate <https://pre-commit.ci> and then come back to complete the set-up process.
• It seems like you are using the roxygenize hook. This requires further edits in your `.pre-commit-config.yaml`, please run
`precommit::snippet_generate('additional-deps-roxygenize')` to proceed.
> precommit::snippet_generate('additional-deps-roxygenize')
Generating snippet using CRAN versions. If you need another source, specify with syntax that `renv::install()` understands (see examples in help file).
- id: roxygenize
# roxygen requires loading pkg -> add dependencies from DESCRIPTION
additional_dependencies:
- checkmate
• Replace the `id: roxygenize` key in `.pre-commit-config.yaml` with the above code.
ℹ Note that CI services like <pre-commit.ci> have build-time restrictions and installing the above dependencies may exceed those, resulting in a timeout. In addition, system dependencies are not supported for <pre-commit.ci>. See `vignette("ci", package = "precommit")` for details and solutions.
Modify .precommit-config.yaml as specified
4. Try to commit with git
$ pre-commit clean
Cleaned C:\Users\name\.cache\pre-commit.
$ git add .
warning: in the working copy of '.Rbuildignore', CRLF will be replaced by LF the next time Git touches it
warning: in the working copy of '.gitignore', CRLF will be replaced by LF the next time Git touches it
warning: in the working copy of '.pre-commit-config.yaml', CRLF will be replaced by LF the next time Git touches it
warning: in the working copy of 'PrecommitRTest.Rproj', CRLF will be replaced by LF the next time Git touches it
warning: in the working copy of 'R/hello.R', CRLF will be replaced by LF the next time Git touches it
warning: in the working copy of 'man/hello.Rd', CRLF will be replaced by LF the next time Git touches it
$ git commit -m "Test"
[INFO] Initializing environment for https://github.com/lorenzwalthert/precommit.
[INFO] Initializing environment for https://github.com/lorenzwalthert/precommit:checkmate.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Initializing environment for https://github.com/pre-commit-ci/pre-commit-ci-config.
[INFO] Installing environment for https://github.com/lorenzwalthert/precommit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/lorenzwalthert/precommit.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/pre-commit-ci/pre-commit-ci-config.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
style-files..............................................................Passed
roxygenize...............................................................Passed
use-tidy-description.....................................................Passed
spell-check..............................................................Passed
lintr....................................................................Failed
- hook id: lintr
- exit code: 1
- The project is out-of-sync -- use `renv::status()` for details.
- The project is out-of-sync -- use `renv::status()` for details.
Warning message:
We detected multiple pre-commit executables. This is likely going to get you into trouble in the future, e.g. when you want to upgrade, as you easily loose track
of different versions. We strongly suggest to only keep one pre-commit executable and uninstall (or delete) the other ones. Here are the locations where we detected executables:
- C:\Users\name\AppData\Roaming\Python\PYTHON~2\Scripts\PRE-CO~1.EXE
- C:/Users/name/AppData/Roaming/Python/Python312/Scripts/pre-commit.exe
Note that in all local repos where you used pre-commit, the executable path is hardcoded (in .git/hooks/pre-commit). Deleting a referenced executable will break pre-commit for that local repo. A simple re-initialization with `precommit::use_precommit()` or `$ pre-commit install` will fix this for pre-commit hooks.
If you have hook types other than pre-commit such as pre-push (you can check which files are in .git/hooks/), you need to name the type and use the command line,
i.e. `$ pre-commit install -t pre-push`.
File `R/hello.R` is not lint free
C:/Users/name/Documents/GitHub/PrecommitRTest/R/hello.R:3:3: warning: [object_usage_linter] no visible global function definition for 'assert_count'
assert_count(n)
^~~~~~~~~~~~
Error: File R/hello.R is not lint free
Execution halted
readme-rmd-rendered..................................(no files to check)Skipped
parsable-R...............................................................Passed
no-browser-statement.....................................................Passed
no-print-statement.......................................................Passed
no-debug-statement.......................................................Passed
deps-in-desc.............................................................Passed
pkgdown..................................................................Passed
check for added large files..............................................Passed
file contents sorter.....................................................Passed
fix end of files.........................................................Passed
check pre-commit.ci config...............................................Passed
Don't commit common R artifacts......................(no files to check)Skipped
- Change hello.R to use checkmate::assert_count:
plus_one <- function(n) {
checkmate::assert_count(n)
n + 1
}
Use lintr in R:
> roxygen2::roxygenize()
Writing NAMESPACE
ℹ Loading PrecommitRTest
> lintr:::addin_lint_package()
ℹ No lints found.
- Commit again and see it works:
$ git commit -m "Test"
style-files..............................................................Passed
roxygenize...............................................................Passed
use-tidy-description.....................................................Passed
spell-check..............................................................Passed
lintr....................................................................Passed
readme-rmd-rendered..................................(no files to check)Skipped
parsable-R...............................................................Passed
no-browser-statement.....................................................Passed
no-print-statement.......................................................Passed
no-debug-statement.......................................................Passed
deps-in-desc.............................................................Passed
pkgdown..................................................................Passed
check for added large files..............................................Passed
file contents sorter.....................................................Passed
fix end of files.........................................................Passed
check pre-commit.ci config...............................................Passed
Don't commit common R artifacts......................(no files to check)Skipped
[main (root-commit) ac09110] Test
9 files changed, 149 insertions(+)
create mode 100644 .Rbuildignore
create mode 100644 .gitignore
create mode 100644 .pre-commit-config.yaml
create mode 100644 DESCRIPTION
create mode 100644 NAMESPACE
create mode 100644 PrecommitRTest.Rproj
create mode 100644 R/hello.R
create mode 100644 inst/WORDLIST
create mode 100644 man/hello.Rd
Notice also the (fake?) warning from lintr hook about multiple pre-commit executeable didn't appear again.
Expected behavior
That @importFrom / NAMESPACE / roxygenize hook works correctly for lintr hook.
Additional context
- My operating system is: Windows 11
- My project uses {renv}.
- the output of
packageVersion('renv')1.1.5