Skip to content
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: context-sensitive lintr configuration #1499

Open
russHyde opened this issue Aug 12, 2022 · 2 comments
Open

Feature: context-sensitive lintr configuration #1499

russHyde opened this issue Aug 12, 2022 · 2 comments

Comments

@russHyde
Copy link
Collaborator

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?

@russHyde
Copy link
Collaborator Author

Original thread (on {precommit}): lorenzwalthert/precommit#440

@MichaelChirico
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants