-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --root argument to lintr hook #600
Conversation
Sorry I don't understand what you mean. Can you provide more context? |
My bad! Hopefully laying everything out will make it clear. Context{box.linters} relies on importing {box} modules during linting. These imports are relative—typically to the root of a repo. Running However,
I am looking for a way fix that. What came to my mind was adding the Example for Testing
|
Sorry @TymekDev I took so long to answer. I can reproduce your problem, thanks for the detailed report. In case this was not evident already, here's how I'd adapt the repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: 10bd189ec3421926bdbc32aba94b873a7a597e53
hooks:
- id: lintr
additional_dependencies:
- box
- Appsilon/[email protected]
args: [--root=/Users/lorenz/git/precommit.box.linter] But the error is the one you described above. In addition, we can avoid using renv under the hood and just use the hook script with our global R package library:
This won't solve the problem either. The working directory at the time of hook execution is guaranteed to be the git root. You can go one level deeper and just execute the hook script that lives in the pre-commit cache transparently from the project root, and you get the same error: $ /Users/lorenz/.cache/pre-commit/repouv8mdctt/inst/hooks/exported/lintr.R main.R
Error: Linter 'box_unused_attached_mod_linter' failed in /Users/lorenz/git/precommit.box.linter/main.R: unable to load module “./main”; not found in “/Users/lorenz/.cache/pre-commit/repouv8mdctt/inst/hooks/exported”
Execution halted
The Having said that, I am not sure what the problem is. It seems like So overall, I can't help further with this, as it seems a problem on the side of {box.linters}... 😩 |
@lorenzwalthert thanks for taking time to look into this! Ultimately, I have settled for running a local repos:
- repo: local
hooks:
- id: lint-r-app
name: run rhino::lint_r() on app/ files
language: script
entry: /usr/bin/env Rscript -e 'rhino::lint_r(commandArgs(trailingOnly = TRUE))'
files: |
(?x)^(
\.Rprofile|
app/.*\.R
)$ It might not be ideal, as part of the idea of having pre-commit is separating the dev tooling from the project, but for the time being... it just works. :^) {box.linters} doesn't complain, because the hook runs in the repo and the project being a {rhino}-based application means I am closing this PR as it's not really solving what I thought it would. Feel free to re-open if these changes are still needed. |
I have stumbled upon {box.linters} failing to run its checks as it relies on loading relative paths. Specifying a root directory with the newly-added
--root
flag solves this.Edit: I just realized that it helped in a synthetic test—when invoked by hand. I cannot figure out how to pass absolute path to the repo via pre-commit's args. I tried
$PWD
,pwd
,$(git rev-parse --show-top-leell)
, but each was treated as a string and not expanded at all 🤔