Open philiporlando opened 1 week ago
Thanks. This is likely unrelated to pre-commit, but a conflict between styler and lintr. Please see renv.lock
of this repo for the version used for each package. That way you should be able to figure out the problem. Also note I pushed a hook release < 1 hour ago, maybe the problem resolves itself if you precommit::autoupdate()
.
Note that both styler and lintr run in a separate renv (invisible to you), i.e. they don't match your global (or renv project specific) version most likely.
packageVersion("styler")
# [1] ‘1.10.3’
packageVersion("lintr")
# [1] ‘3.1.2’
I'm able to run styler::style_dir()
interactively, and it uses the indent_by=2L
as expected. Only the pre-commit hook is giving me trouble.
I'm currently experiencing this error:
git commit -m 'test commit'
style-files....................................................Failed
- hook id: style-files
- exit code: 1
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
Error in packageVersion("precommit") :
there is no package called ‘precommit’
Execution halted
But I do not see this issue when loading {precommit} interactively:
renv::status()
# No issues found -- the project is in a consistent state.
packageVersion("precommit")
# [1] ‘0.4.3’
precommit::version_precommit()
# [1] "3.4.0"
precommit::autoupdate()
# ✔ Ran `pre-commit autoupdate ()` to get the latest version of the hooks.
It seems like my RStudio session and my git terminal are using separate pre-commit environments? I'm not sure where to go from here. Any troubleshooting support here is greatly appreciated!
Note that both styler and lintr run in a separate renv (invisible to you), i.e. they don't match your global (or renv project specific) version most likely.
Again, the renv in your project is unrelated to the renv precommit uses. These are two differen renvs. The one pre-commit uses is stored in a caching directory so you don't see it. If you use the latest version of the hooks, you can check here what versions of {styler} and {lintr} are used:
They match. So you should be able to reproduce your problem with these versions.
Prior to using {precommit} and {styler} calling lintr::lint_dir() was running successfully without any linting errors. However, now that I'm trying to auto-style on commit, I'm seeing the below linting errors: [...] This is telling me that {styler} is continuing to use four spaces, instead of the expected two...
So you say that calling styler thorugh pre-commit created additional indention? Did you verify that by looking at the file contents? Maybe create a reprex, it's hard to help otherwise. Also, if styler makes changes, you need to stage them and try to commit again for the hook to pass, otherwise the hook will repeatedly fail.
Before filing a bug
remotes::install_github('lorenzwalthert/precommit')
precommit::autoupdate()
)Describe the bug
I am trying to incorporate
{styler}
as a pre-commit hook within my R project. I have already been using{lintr}
with some custom config. This is what my.lintr
looks like:Prior to using
{precommit}
and{styler}
callinglintr::lint_dir()
was running successfully without any linting errors. However, now that I'm trying to auto-style on commit, I'm seeing the below linting errors:Here is what my
.pre-commit-config.yaml
looks like:To Reproduce
Still working on a full reprex. Will update soon.
Expected behavior
I would expect
{styler}
to respect myindent_by=2
argument, and to not use four spaces. While the{styler}
pre-commit hook passes, the{lintr}
hook fails... This is telling me that{styler}
is continuing to use four spaces, instead of the expected two...Any insight here is appreciated!
Additional context
packageVersion('renv')
: 1.0.7