lintr
lintr copied to clipboard
Feature: context-sensitive lintr configuration
lintr can be used in several settings: precommit, CI, interactively etc
I found that when using lintr in precommit, object-usage was throwing a lot of false positives. This arose because only the commit set gets linted, so if you are lint()ing a file that refers to an object defined elsewhere in the package, lintr assumes that object doesn't exist.
In CI, I can load the package prior to linting it - taking care of any object-usage lints. But I can't easily load the package in precommit because that would require adding all my package's dependencies to the env where the lintr hook runs.
So I was wondering whether there is a way to conditionally specify whether a linter is active, e.g. based on environment variables:
# .lintr
linters: linters_with_defaults(
object_usage_linter = if (Sys.getenv("THIS_IS_A_CI_RUN")) object_usage_linter() else NULL,
...snip ...
)
Is there a neater way to encode conditions under which the configured linters should run?
Original thread (on {precommit}): https://github.com/lorenzwalthert/precommit/issues/440
I think it's more natural to do the sort of if()
branching you mentioned now that we support configs in plain R sources.
I suspect that closes this issue, leaving open for now for further comment.