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

Fix some lints in the tests folder #6051

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

etiennebacher
Copy link
Contributor

Same as #6050 but used flint::fix_dir("tests") this time (to avoid having too many changed files in the same PR).

Changes include:

  • expect_equal(names(x), ...) -> expect_named(x, ...)
  • expect_equal(x, NULL) -> expect_null(x)
  • expect_equal(x, TRUE) -> expect_true(x)

and more.

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting together a PR! I like almost all of these changes, with the exception of some relating to anyDuplicated().

@@ -73,7 +73,7 @@ test_that("boxes with variable widths do not overlap", {
d <- get_layer_data(p)[c("xmin", "xmax")]
xid <- find_x_overlaps(d)

expect_false(any(duplicated(xid)))
expect_false(anyDuplicated(xid) > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that anyDuplicated() is more efficient, but the mental effort to understand what this expectation is doing is increased by this change.

Suggested change
expect_false(anyDuplicated(xid) > 0)
expect_equal(anyDuplicated(xid), 0)

@@ -32,7 +32,7 @@ test_that("rectangles are dodged", {
p <- ggplot(df, aes(xmin = xmin, xmax = xmax, ymin = ymin, ymax = ymax)) +
geom_rect(aes(fill = fill), position = "dodge2", alpha = 0.8)

expect_false(any(duplicated(find_x_overlaps(get_layer_data(p)))))
expect_false(anyDuplicated(find_x_overlaps(get_layer_data(p))) > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect_false(anyDuplicated(find_x_overlaps(get_layer_data(p))) > 0)
expect_equal(anyDuplicated(find_x_overlaps(get_layer_data(p))), 0)

@@ -44,7 +44,7 @@ test_that("cols at the same x position are dodged", {
p <- ggplot(df, aes(1, n, fill = x)) +
geom_col(position = "dodge2", alpha = 0.5)

expect_false(any(duplicated(find_x_overlaps(get_layer_data(p)))))
expect_false(anyDuplicated(find_x_overlaps(get_layer_data(p))) > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect_false(anyDuplicated(find_x_overlaps(get_layer_data(p))) > 0)
expect_equal(anyDuplicated(find_x_overlaps(get_layer_data(p))), 0)

@etiennebacher
Copy link
Contributor Author

etiennebacher commented Aug 20, 2024

Fair enough, I also think anyDuplicated(x) > 0 is harder to read, I just adopted the lintr defaults. I removed those changes.

Copy link
Collaborator

@teunbrand teunbrand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for this!

@teunbrand teunbrand merged commit 1a6e495 into tidyverse:main Aug 20, 2024
13 checks passed
@etiennebacher etiennebacher deleted the fix-tests-lints branch August 20, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants