Skip to content

User-defined S3 methods & object_name_linter #737

Description

@russHyde

This has been raised in a few issues (which I think have all been closed). But it isn't an issue that has really been solved.

If a newly minted package defines a generic and an S3-method based on that generic:

#' drink_me
#' @description empty
#'
#' @export
drink_me <- function(x, ...) {
  UseMethod("drink_me")
}

#' drink_me for most things
#' @export
drink_me.default <- function(x, ...) {
  1
}

#' drink_me for lists
#' @export
drink_me.list <- function(x, ...) {
  NULL
}

#' drink_me for data.frames
#' @export
drink_me.data.frame <- function(x, ...) {
  NULL
}

then, IMO, the expected behaviour when running lint_package(linters = object_name_linter("snake_case")) is for no lints to be thrown. Only the name of the generic should be subject to the snake-case linter.

But the .<className> suffix throws a lint because of there being multiple dots in the drink_me.data.frame

To reproduce

  • open rstudio
  • make new package ~/temp/temppkg using rstudio package template
  • delete the NAMESPACE
  • add the above code to drink.R
  • document()
  • Use devtools::load_all("path/to/lintr") to load current lintr master
  • lint_package(linters = object_name_linter("snake_case"))
  • Note the lint on drink_me.data.frame
  • ... then
  • load the temp package using devtools::load_all()
  • Run lint_package again
  • note that the lints are present whether or not the package-under-development is loaded.

This is an issue that arose while experimenally running lint_package(linters = object_name_linter(c("snake_case", "camelCase", "symbols"))) on {targets} (https://github.com/ropensci/targets)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behavior

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions