-
Notifications
You must be signed in to change notification settings - Fork 186
Remove false negatives with seq()
in seq_linter()
#1468
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
Changes from all commits
e466e1c
33a258e
8b8f1b2
01813fd
a91eae2
808b493
aa53a34
72d2b9b
093d30c
0287c35
3f6d546
9fa1b9b
7e08407
2efe0ab
c5f3710
9dc90ea
1bd9daa
c3be79e
80cea29
53fcd90
90e2ad6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,32 @@ test_that("other : expressions are fine", { | |
expect_lint("function(x) { 1:(length(x) || 1) }", NULL, linter) | ||
}) | ||
|
||
test_that("seq_len(...) or seq_along(...) expressions are fine", { | ||
linter <- seq_linter() | ||
|
||
expect_lint("function(x) { seq_len(x) }", NULL, linter) | ||
expect_lint("function(x) { seq_along(x) }", NULL, linter) | ||
|
||
expect_lint("function(x) { seq(2, length(x)) }", NULL, linter) | ||
expect_lint("function(x) { seq(length(x), 2) }", NULL, linter) | ||
}) | ||
|
||
test_that("finds seq(...) expressions", { | ||
linter <- seq_linter() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add a test for seq(dim(x)[1]) which is how dim would usually be used? it's pretty rare (never seen it before myself), so if the current approach doesn't work, just file a follow-up issue. but if the current xpath is good enough just add tests to prevent regression There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current approach does work. Added a test. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, wait. This should actually produce a lint: seq(dim(data.frame())[1])
#> [1] 1 0 Created on 2022-07-26 by the reprex package (v2.0.1) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right... don't worry about it though. just please file a follow-up issue There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and plz revert the incorrect test :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it okay if I add the correct test but comment it out for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created issue to track this: #1474 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep that's fine, though we'll have to be wary of comment_linter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see :) |
||
|
||
expect_lint( | ||
"function(x) { seq(length(x)) }", | ||
rex("seq(length(...))", anything, "Use seq_along(...)"), | ||
linter | ||
) | ||
|
||
expect_lint( | ||
"function(x) { seq(nrow(x)) }", | ||
rex("seq(nrow(...))", anything, "Use seq_len(...)"), | ||
linter | ||
) | ||
}) | ||
|
||
test_that("finds 1:length(...) expressions", { | ||
linter <- seq_linter() | ||
|
||
|
@@ -89,4 +115,22 @@ test_that("Message vectorization works for multiple lints", { | |
), | ||
seq_linter() | ||
) | ||
|
||
expect_lint( | ||
"c(seq(length(x)), 1:nrow(y))", | ||
list( | ||
rex::rex("seq(length(...))", anything, "seq_along(...)"), | ||
rex::rex("1:nrow(...)", anything, "seq_len()") | ||
), | ||
seq_linter() | ||
) | ||
|
||
expect_lint( | ||
"c(seq(length(x)), seq(nrow(y)))", | ||
list( | ||
rex::rex("seq(length(...))", anything, "seq_along(...)"), | ||
rex::rex("seq(nrow(...))", anything, "seq_len(...)") | ||
), | ||
seq_linter() | ||
) | ||
}) |
Uh oh!
There was an error while loading. Please reload this page.