Skip to content

FR: use_lintr function to help set up code linting for package #579

Closed

Description

@leonawicz

The package does not have a use_lintr helper, but I use the lintr package with all of my packages and it is helpful to have a function that can automate the set up of this piece of package scaffolding. Others may find it similarly useful.

I see three typical ways to use lintr with a package:

  • local interactive use
  • automatic use on Travis CI post-build (non-failing)
  • automatic local and Travis CI as a unit test (failing)

I think the first option should be the default. It is the simplest. The second option is the official recommended approach, which involves adding to .travis.yml:

after_success:
  - R CMD INSTALL $PKG_TARBALL
  - Rscript -e 'lintr::lint_package()'

but this option is specifically for cases where someone does not wish to have a unit test, or a build failure when the linter finds style issues.

The third option is the most rigorous and is intended to fail a build, locally and on Travis, if there are style issues present. Personally, I use this option almost exclusively in my packages, but it should not be the default because it is the most complex and also may not be desirable for long-running test suites.

I have an initial version of a function and will submit a pull request.

Activity

  1. added
    feature
    code 🖥️
    on Mar 17, 2019
  2. added this to the Backlog milestone on Mar 28, 2019
  3. jennybc commented on Apr 7, 2019

    @jennybc
    Member

    Example of a good thing to check for users of devtools/usethis:

    Any top-level instance of usethis::use_SOMETHING() below R/ is almost certainly an error, i.e. some package development code has been left behind in the package source. An example of this came up during the usethis v1.5.0 submission vis-a-vis KSPM.

  4. removed this from the Backlog milestone on Apr 10, 2019
  5. hadley commented on Oct 21, 2019

    @hadley
    Member

    In the not-to-distant future, I think the obvious way to implement this will be as a GitHub action.

  6. jimhester commented on Mar 17, 2020

    @jimhester
    Member

    There is now a linting workflow example (https://github.com/r-lib/actions/tree/master/examples#lint-workflow). You can use it from dev usethis with usethis::use_github_action("lint")

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    code 🖥️feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions