Skip to content
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

object_length_linter should detect generics #871

Closed
AshesITR opened this issue Oct 8, 2021 · 6 comments · Fixed by #873
Closed

object_length_linter should detect generics #871

AshesITR opened this issue Oct 8, 2021 · 6 comments · Fixed by #873
Labels
bug an unexpected problem or unintended behavior

Comments

@AshesITR
Copy link
Collaborator

AshesITR commented Oct 8, 2021

As the object_name_linter already does, class suffixes for S3 generics shouldn't be part of the linted symbol.
That is, object_length_linter(30) (the default) shouldn't lint this example:

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

my_generic_function.my_cool_class <- function(x, ...) {
  cat("How cool and generic!\n")
}
@AshesITR AshesITR added the bug an unexpected problem or unintended behavior label Oct 8, 2021
@stufield
Copy link
Collaborator

stufield commented Oct 9, 2021

Yes! I've been bitten by this many times and have # nolint scattered throughout my generics definition files.
Looking forward to this.

@AshesITR
Copy link
Collaborator Author

AshesITR commented Oct 9, 2021

For now, I've even disabled the linter alltogether in the .lintr config because it didn't have any true positives in my project.

@MichaelChirico
Copy link
Collaborator

Should this be an option?

@AshesITR
Copy link
Collaborator Author

AshesITR commented Oct 9, 2021

I'd be happy to make it optional. What should the default be? The old behaviour?

@MichaelChirico
Copy link
Collaborator

I think the new behavior is a happier default -- often it's out of your control if you're defining a method for someone else's class.

WDYT about a third option -- enforce the length on two parts (class name and generic name)? not sure it's worth the implementation & maintenance effort but it does make some sense

@AshesITR
Copy link
Collaborator Author

AshesITR commented Oct 9, 2021

We could combine both by specifying two maximum lengths?

MichaelChirico added a commit that referenced this issue Mar 21, 2022
* Refactor `object_length_linter` to properly handle generics

Fixes #871

* document()

* incorporate feedback

* put S3 tests in their own unit

Co-authored-by: Michael Chirico <chiricom@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants