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

Upstreaming linters from Google's internal linting suite #884

Closed
76 tasks done
Tracked by #1108
MichaelChirico opened this issue Nov 10, 2021 · 12 comments
Closed
76 tasks done
Tracked by #1108

Upstreaming linters from Google's internal linting suite #884

MichaelChirico opened this issue Nov 10, 2021 · 12 comments

Comments

@MichaelChirico
Copy link
Collaborator

MichaelChirico commented Nov 10, 2021

Internally at Google we use lintr to power our in-editor and CI-based R linting tools. Over the last year+ (in addition to working directly on lintr) we have been building out a set of linters that extends the suite offered by lintr. Currently, the package has >60 such linters, almost all of which we think are widely relevant. They have all been test on & applied to existing internal R code at Google.

We are happy to contribute any subset of these to lintr. Here is a brief summary of all of them; I can elaborate more as needed:

What do you think is the best way to decide about which are in/out of scope for lintr? Does it make sense to delay this until 3.0 is released, or push to include with the major version bump?

@jimhester
Copy link
Member

I think it would be great to include these in the 3.0 release. It would also give people more incentive to upgrade.

It might also be worthwhile to package these as a separate object, so it would be easy to use them all as google_linters like we currently have for default_linters.

As to which of them should be on by default I leave that to others to discuss.

@AshesITR
Copy link
Collaborator

That sounds really great! I also like the idea of adding google_linters. In the same spirit, should we add all_linters as well?
At the moment, non-default linters are somewhat hard to discover. We ended up going through the entire ?linters manpage and look at all linters to decide whether we might want to use it.
With all_linters the workflow for deciding on a subset could be to first enable all and then disable those that actually cause unwanted lints in the code.

To decide on the defaults, it will probably help to look at the concrete implementations.

Curious side question regarding ScalarInLinter: That construct is my go-to way to check if x == "a" when x is known to contain NAs. Is there a better, equally efficient, way to do this?
Illustrative code:

x <- c(NA, "a", "b", "c", NA)
x == "a" # c(NA, TRUE, FALSE, FALSE, NA)
x %in% "a" # c(FALSE, TRUE, FALSE, FALSE, FALSE) -- much safer for e.g. indexing

@MichaelChirico
Copy link
Collaborator Author

no, it's a known false positive of the linter. we decided it's better for readability to treat NA handling explicitly, if so intended, and put that caveat in the lint message:

!is.na(x) & x == "a"

@MichaelChirico
Copy link
Collaborator Author

@AshesITR with #958 we'll finish up the current set of 13 testthat-related linters we have.

I think now is a good time to think if we want to triage the prep for lintr 3.0.0 -- have have O(100) linters ready for upstreaming, which would put us at about June to finish, assuming we keep up the current (quite high) pace of new PRs.

Should we prioritize instead? Pick some set of particularly neat/high-impact linters to include in the 3.0.0 release, then focus on tidying up 3.0.0 and putting it on CRAN before returning to new google linters?

@AshesITR
Copy link
Collaborator

AshesITR commented Mar 19, 2022

Sounds good to me.
Do you have any linters in mind that fire frequently and could be considered high-impact?
We could aim for a 3.0.1 release containing the rest of the google linters.

@AshesITR
Copy link
Collaborator

@MichaelChirico I edited your OP with a checklist and linked all PRs / issues I was aware of.
Are there new linters to be upstreamed or is the list complete?

@LukasDSauer
Copy link

Hello! I am interested in applying the Google R Style Guide to one of our packages. Thus, I am thrilled to see that you consider supplying a lintr::google_linters list to the lintr package. Is this list in planning and will it be added to the package in the near future?

@MichaelChirico
Copy link
Collaborator Author

there are a slew already added -- see #962

@LukasDSauer
Copy link

Hi Michael and thank you for the quick reply. As far as I understand, #962 contains a list of Google linters already added to lintr. Jim Hester suggested above that available Google linters could be packaged in a separate object:

It might also be worthwhile to package these as a separate object, so it would be easy to use them all as google_linters like we currently have for default_linters.

Has this already been done or would I have to include all of the linters in #962 one-by-one?

@MichaelChirico
Copy link
Collaborator Author

With #2321, that's it!

Special shout-out to @AshesITR and @IndrajeetPatil for your time and insights during the review process! The suite is now much better thanks to you! Thanks also to others who have filed follow-ups/tested the new linters on your own projects.

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

5 participants