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

Update to lintr needed? #451

Closed
3 tasks done
joelnitta opened this issue Nov 15, 2022 · 4 comments
Closed
3 tasks done

Update to lintr needed? #451

joelnitta opened this issue Nov 15, 2022 · 4 comments

Comments

@joelnitta
Copy link

Before filing a bug

  • I have installed the latest dev version of {precommit} with remotes::install_github('lorenzwalthert/precommit')
  • I have installed the latest hook revisions (update with precommit::autoupdate())
  • I have installed the latest release of the upstream Python framework pre-comit as described under the update instructions.

Describe the bug

Internal (non-exported) functions that are defined in a separate file from an exported function (e.g., functions in a utils.R file) trigger the lintr "[object_usage_linter] no visible global function definition" warning. I do not encounter this behavior when running lintr myself with lintr v3.0.2. It seems {precommit} is running v3.0.1 so I suspect that may be causing the problem:

"Version": "3.0.1",

To Reproduce
Steps to reproduce the behavior:

  1. Create utils.R with a non-exported function
  2. Call that function from another file (e.g., exported.R)
  3. Try to commit exported.R

Expected behavior
No warning from the lintr

Additional context

  • My operating system is: Mac OSX
  • My project does not use renv
@lorenzwalthert
Copy link
Owner

Thanks @joelnitta. The difference is probably due to the way {lintr} is called. We don't your whole source package prior to calling {lintr}, but we only lint the files staged for commit. This is arguably different from what you do when you call {lintr} interactively. Please see #440.

@joelnitta
Copy link
Author

@lorenzwalthert it certainly looks like you are right - I think I've encountered the same thing as #440. There's one thing I don't understand though: It looks like {precommit} calls lintr::lint(path), but when I run lintr::lint("path_to_R_script") I don't get any [object_usage_linter] warnings like I do from {precommit}.

@lorenzwalthert
Copy link
Owner

lorenzwalthert commented Nov 15, 2022

Ok. Make sure to not devtools::load_all() before the {lintr} call. But have you tried also outside RStudio like

Rscript -e "lintr::lint(path)" 

With the same result? I think maybe {lintr} runs devtools::load_all() in RStudio or something like this. cc: @russHyde.

@joelnitta
Copy link
Author

Ah, that does make the difference. I'm not using RStudio (I use vs-code), but if I run lintr::lint("path") in a fresh R session I get the object_usage_linter warnings; if I run devtools::load_all() first, no warnings. So yes this is the same thing. Closing now since it's a duplicate of #440.

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

No branches or pull requests

2 participants