-
Notifications
You must be signed in to change notification settings - Fork 187
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
expect_s3_class_linter and expect_s4_class_linter #943
Conversation
BTW, one thing to consider -- with this linter active, it becomes somewhat cumbersome to test for the exact sequence of S3 classes, e.g. before you might write
this linter wants
The thinking is that it's usually preferable to check inheritance as opposed to an exact sequence of classes. One thing we could do is offer an option (I'm indifferent to the default) At Google, we've really aligned on |
What is wrong with library(testthat)
expect_s3_class(data.table::data.table(), c("data.frame", "data.table"))
expect_s3_class(data.table::data.table(), c("data.table", "data.frame")) Created on 2022-03-15 by the reprex package (v2.0.1) |
Oh actually I forgot how inherits works, it actually just returns true if any of the input classes are found, not all of them, so separate calls to |
Right, e.g. |
Another BTW, I have been running the new linters on
|
I think minor de-lints are fine if they don't make the PR too large. |
R/expect_s3_class_linter.R
Outdated
|
||
# (1) expect_{equal,identical}(class(x), C) | ||
# (2) expect_true(is.<class>(x)) and expect_true(inherits(x, C)) | ||
is_class_call <- xp_text_in_table(c(is_s3_class_calls, "inherits")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false positive lint caused by glue: local variable ‘is_class_call’ assigned but may not be used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost gtg
Part of #884
Close cousin of
expect_type_linter()