-
Notifications
You must be signed in to change notification settings - Fork 186
Add library call linter #2027
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
Add library call linter #2027
Conversation
I'm not sure why the lint is returning multiple and causing the tests to fail. When I run this on my side it returns one and everything is running cleanly. library(lintr)
lint(
text = c("library(dplyr)", "print('test')", "library(tidyr)"),
linters = library_call_linter()
)
#> <text>:3:1: warning: [library_call_linter] Move all library calls to the top of the script.
#> library(tidyr)
#> ^~~~~~~ Created on 2023-07-28 with reprex v2.0.2 |
AFAIK the |
@AshesITR Thanks! I'll try (//element[@name='D'])[last()] as this post suggests to see if that gives me the last node, rather than the last element within each node. I'm still unclear why it returns the expected result on my end and fails when running through ci/cd here. It makes it so the only way I can test is to push updates and check the actions, which is probably destroying your email inbox with fail messages. Sorry about this. |
FWIW I don't get those. only the code coverage bot comments when CI passes. |
Good to know, thanks! Now I don't feel so bad hacking through it this way :) |
could be an R version thing? there are subtle differences in the XML structure between versions sometimes. To help, you could add |
Great idea! I'm not clear how would I retrieve this from the action? Can I access this somehow after the action is complete? |
@MichaelChirico nvm! This defaults to standard out! |
Codecov Report
@@ Coverage Diff @@
## main #2027 +/- ##
=======================================
Coverage 98.55% 98.56%
=======================================
Files 113 114 +1
Lines 4994 5011 +17
=======================================
+ Hits 4922 4939 +17
Misses 72 72
|
Good work. |
inst/lintr/linters.csv
Outdated
@@ -42,6 +42,7 @@ infix_spaces_linter,style readability default configurable | |||
inner_combine_linter,efficiency consistency readability | |||
is_numeric_linter,readability best_practices consistency | |||
lengths_linter,efficiency readability best_practices | |||
library_call_linter,style best_practices |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this counts as readability
to me too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might want to add an exception for library()
calls inside functions -- e.g. for libraries calling library()
on behalf of the user. The current logic seems tailored to scripts, but the linter will end up being used in packages too.
It would also be easy to consider require()
the same as library()
for this linter.
@MichaelChirico Would you be open to completing this PR as is and adding this as a new issue? I'm happy to continue to work on it to add these features, but it would allow me to get this functionality in so I can have another package use it for it's upcoming release. |
SGTM, please help to file follow-up issues |
I've got a use case where I need all
library()
calls to be at the top of the script so the search path is consistent across the entire script.I will incorporate this into the linting for the logrx package, but thought others might want this as well, so better in lintr than buried in a logging package. I hope you all agree.