-
-
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
Feature: allow package-loading prior to lint hook #440
Comments
Thanks @russHyde. What about the option to lint the whole package instead of the staged files? Is that also an option? I prefer to not use |
That's interesting, I hadn't considered the environment where precommit/lintr is running. This might be something better handled on our (lintr's) end - for example, having a way to selectively deactivate linters based on environment variables, so that some linters are only active in CI. |
Is there smart caching built in in {lintr}, or is running it on all files significantly slower? |
any thoughts @MichaelChirico? |
lintr is typically taking O(10 seconds) on full packages, but yes there is an expression-level caching mechanism |
I think this sounds like introducing intransparency. Another option that we considered in #393 is to use
If you cache files, would it get significantly faster? Then that would be the solution in my eyes (offloading my own work to others has always been my easy way out 😄). |
Also note that theoretically, {lintr} does not have to offer the functionality to deactivate linters based on environment variables, even if we wanted to use env variables (or pre-commit arguments in |
I agree that the env-variables make it less transparent. I might experiment with writing a lintr hook that allows the user to specify a lintr config, so that I can have a .lintr.pre-commit (for use in local pre-commit) and a .lintr config (for use interactively and in CI) |
Yeah ok. Here's how I'd do it.
|
@lorenzwalthert I'm not familiar enough with the setup of
|
Like this: - repo: local
hooks:
- id: local-lintr
name: Run lintr with global R environment
entry: Rscript -e "devtools::load_all(); output <- lintr::lint(commandArgs(trailingOnly=TRUE)); print(output); if (length(output) > 0) stop('Files not lint free')"
language: system
files: '(\.[rR]profile|\.R|\.Rmd|\.Rnw|\.r|\.rmd|\.rnw)$'
You could also move the R code in |
Pre-commit passes the file names to |
@lorenzwalthert thanks! However, I noticed this only works if a single R file is being committed, since Below I have modified it to work on one or more R files:
|
(BTW I would be interested in running this with CI also if you could provide more details on that as well) |
Thanks for your snipped. Also, you may want to print For CI, this does not work (system hooks are not supported with pre-commit.ci). Potentially later with GitHub Actions and #450, but for now, maybe you could just use the lintr action from r-lib/actions? |
It does print the output (I just ran a test to verify): So for CI, there is no need to modify |
Not sure it skips the local hook by default, you could also skip it explicitly as mentioned in the pre-commit.ci docs: ci:
skip: [pylint]
repos:
- repo: local
hooks:
- id: pylint
# ... |
Great you achieved what you wanted. A solution to make this work withouth local hook would still be to
Or to use |
Is your feature request related to a problem? Please describe.
When running the lintr hook on a package, it flags many
object_usage_linter
errors.This happens because, unless the package is loaded, lintr is unable to distinguish when a referenced object is completely undefined from when it is defined within the package.
Typically, we would lint the whole package in CI but use pre-commit to only lint those files in a commit set.
We could turn off the
object_usage_linter
in the .lintr config, but that config affects both precommit and CI runs of lintr, so would mean that this useful linter would be unavailable in CI.Describe the solution you'd like
Would it be possible to add a command line option to the pre-commit linting script that determines whether the package in a repo should be loaded prior to running lintr. For example,
Rscript lintr.R <files>
would run as currently implemented. ButRscript lintr.R --load-package <files>
would runpkgload::load_all()
before running lintr on the files.The text was updated successfully, but these errors were encountered: