Skip to content

Generics defined in other files not detected by object_name_linter() and object_length_linter() #1808

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

Closed
AshesITR opened this issue Dec 7, 2022 · 0 comments · Fixed by #1842
Labels
false-positive code that shouldn't lint, but does

Comments

@AshesITR
Copy link
Collaborator

AshesITR commented Dec 7, 2022

R/generic.R

my_generic <- function(x, ...) {
  UseMethod("my_generic")
}

R/other.R

my_generic.other <- function(x, ...) {
  # code
}

Should not be linted by object_name_linter(), and object_length_linter() should only consider "other" for length computations.
I can see multiple options here:

  • Inspect all visible functions whether they are generics
  • Inspect the Package NAMESPACE file for S3method(my_generic,<anything>) to deduce my_generic must be an S3 generic

The former also works for non packages but is more expensive.
The latter should be easier, using unique(parseNamespaceFile("package", "..")$S3methods[, 1L]) similar to namespace_imports().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant