Skip to content

Upstreaming linters from Google's internal linting suite #884

Closed

Description

@MichaelChirico

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?

Activity

  1. jimhester commented on Nov 10, 2021

    @jimhester
    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.

  2. AshesITR commented on Nov 11, 2021

    @AshesITR
    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
  3. MichaelChirico commented on Nov 11, 2021

    @MichaelChirico
    CollaboratorAuthor

    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"
    
  4. MichaelChirico commented on Mar 18, 2022

    @MichaelChirico
    CollaboratorAuthor

    @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?

  5. AshesITR commented on Mar 19, 2022

    @AshesITR
    Collaborator

    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.

  6. AshesITR commented on Mar 19, 2022

    @AshesITR
    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?

  7. LukasDSauer commented on Apr 26, 2022

    @LukasDSauer

    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?

  8. MichaelChirico commented on Apr 26, 2022

    @MichaelChirico
    CollaboratorAuthor

    there are a slew already added -- see #962

  9. LukasDSauer commented on Apr 26, 2022

    @LukasDSauer

    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?

  10. AshesITR commented on Apr 26, 2022

    @AshesITR
    Collaborator

    The new tag facility could be used for this. You would then be able to use linters_with_tags(tags = "google").
    Note though that some (default) linters are configured differently from the google style guide, so it may be necessary to provide a google_linters object for full compatibility, @MichaelChirico WDYT?

  11. llrs commented on Jul 15, 2022

    @llrs

    About Bioconductor's style mentioned in the blog (and with an open issue at #43), there is already a package which provides an approximation to the Bioconductor style using lintr. But how would that work?

    Should this follow the broom/tidymodels strategy to provide some basics and leave the different methods, styles in this case, to different packages or should all be "centralized" and organized here?

  12. MichaelChirico commented on Dec 6, 2023

    @MichaelChirico
    CollaboratorAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions