-
Notifications
You must be signed in to change notification settings - Fork 195
Correctly parse checkUsage when a multiline warning is encountered #758
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
9d7e75b
5278e25
0568039
fab1fac
5f65756
9209e7a
96dd22b
611aa1e
51a7697
2c7e758
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,3 +215,86 @@ test_that("used symbols are detected correctly", { | |
| object_usage_linter() | ||
| ) | ||
| }) | ||
|
|
||
| test_that("object_usage_linter finds lints spanning multiple lines", { | ||
| # Regression test for #507 | ||
| expect_lint( | ||
| trim_some(" | ||
| foo <- function() { | ||
| if (unknown_function()) NULL | ||
|
|
||
| if (unknown_function()) { | ||
| NULL | ||
| } | ||
| } | ||
| "), | ||
| list( | ||
| list(message = "unknown_function", line_number = 2L), | ||
| list(message = "unknown_function", line_number = 4L) | ||
| ), | ||
| object_usage_linter() | ||
| ) | ||
|
|
||
| # Linted symbol is not on the first line of the usage warning | ||
| expect_lint( | ||
| trim_some(" | ||
| foo <- function(x) { | ||
| with( | ||
| x, | ||
| unknown_symbol | ||
| ) | ||
| } | ||
| "), | ||
| list(message = "unknown_symbol", line_number = 4L, column_number = 5L), | ||
| object_usage_linter() | ||
| ) | ||
|
|
||
| # Kill regex match to enforce fallback to line 1 column 1 of the warning | ||
| expect_lint( | ||
| trim_some(" | ||
| foo <- function(x) { | ||
| with( | ||
| x, | ||
| `\u2019regex_kill` | ||
|
Collaborator
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 test here is a symbol name that's not matched by our regex? so that the linter has to default to where the expression starts
Collaborator
Author
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 test causes the |
||
| ) | ||
| } | ||
| "), | ||
| list(line_number = 2L, column_number = 1L), | ||
| object_usage_linter() | ||
| ) | ||
| }) | ||
|
|
||
| test_that("global variable detection works", { | ||
| old_globals <- utils::globalVariables(package = globalenv()) | ||
| utils::globalVariables("global_function", package = globalenv()) | ||
| on.exit(utils::globalVariables(old_globals, package = globalenv(), add = FALSE)) | ||
|
|
||
| expect_lint( | ||
| trim_some(" | ||
| foo <- function() { | ||
| if (global_function()) NULL | ||
|
|
||
| if (global_function()) { | ||
| NULL | ||
| } | ||
| } | ||
| "), | ||
| NULL, | ||
| object_usage_linter() | ||
| ) | ||
| }) | ||
|
|
||
| test_that("package detection works", { | ||
| expect_length( | ||
| lint_package("dummy_packages/package", linters = object_usage_linter(), parse_settings = FALSE), | ||
| 9L | ||
| ) | ||
| }) | ||
|
|
||
| test_that("robust against errors", { | ||
| expect_lint( | ||
| "assign(\"x\", unknown_function)", | ||
| NULL, | ||
| object_usage_linter() | ||
| ) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.