Skip to content

object_name_linter() complains about ns-hooks (e.g. .onLoad) #500

Closed

Description

@salim-b

Reprex:

example_file <- tempfile()

readr::write_file(".onLoad <- function(libname, pkgname) {\n  # some action\n}\n",
                  path = example_file)

lintr::lint(filename = example_file, linters = lintr::object_name_linter())

R's hooks for namespace events are CamelCase and you can't change that AFAIK, so lintr complaining about

Variable and function name style should be snake_case.

is pointless.

Activity

  1. AshesITR commented on Sep 1, 2020

    @AshesITR
    Collaborator

    Thanks for reporting this.

    The following function names are special in this regard:

    .onLoad(libname, pkgname)
    .onAttach(libname, pkgname)
    .onUnload(libpath)
    .onDetach(libpath)
    .Last.lib(libpath)

    Additionally, .Rprofile files may also define .First and .Last.

    I think a good place to add that would be in a new is_special_function() for use at https://github.com/jimhester/lintr/blob/83a73fc8698bcd2dbc82c9a12d2b4e929a811a73/R/object_name_linters.R#L129-L133

    @jimhester What do you think about this?

  2. added a commit that references this issue on Nov 28, 2020
    0b7c3a8
  3. added a commit that references this issue on Nov 29, 2020
    e48ace4
  4. jimhester commented on Nov 30, 2020

    @jimhester
    Member

    Yeah, that sounds like a good plan to special case these names.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions