Skip to content

Missing object_usage_linter due to line break #507

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

Closed
bersbersbers opened this issue Jul 22, 2020 · 2 comments · Fixed by #758
Closed

Missing object_usage_linter due to line break #507

bersbersbers opened this issue Jul 22, 2020 · 2 comments · Fixed by #758
Labels
bug an unexpected problem or unintended behavior

Comments

@bersbersbers
Copy link

foo <- function() {
    unknown_function(1)

    unknown_function(
        1
    )

    unknown_function(1)
}

I get this in VS Code, while in my opinion, the middle call should also be detected.

image
image

@russHyde russHyde added the bug an unexpected problem or unintended behavior label Dec 9, 2020
@infotroph
Copy link
Contributor

A variant of this that bit me today: multiline conditionals.

foo <- function() {

    # warns
    if (unknown_function()) NULL 

    # does not warn
    if (unknown_function()) {
    	NULL
    }

}

@AshesITR
Copy link
Collaborator

Thanks for reporting.
The issue is in parse_check_usage when multiline warnings are issued:

foo <- function() {

    # warns
    if (unknown_function()) NULL 

    # does not warn
    if (unknown_function()) {
        NULL
    }

}

codetools::checkUsage(foo)
#> <anonymous>: no visible global function definition for 'unknown_function' (<text>:4)
#> <anonymous>: no visible global function definition for 'unknown_function' (<text>:7-9)
lintr:::parse_check_usage(foo)
#>                                                        message             name
#> 1 no visible global function definition for 'unknown_function' unknown_function
#> 2                                                         <NA>             <NA>
#>     path line_number
#> 1 <text>           4
#> 2   <NA>        <NA>

Created on 2021-02-15 by the reprex package (v1.0.0)

AshesITR added a commit that referenced this issue Feb 18, 2021
)

* Correctly parse checkUsage when a multiline warning is encountered

fixes #507

* 100% coverage for object_usage_linter

* improve location detection, nolint new false positive lints.

* fix single-line case

add tests for 100% coverage

* nzchar over !=""

* add comments

* clean up globalVariables() and remove nolint sections

Co-authored-by: Michael Chirico <[email protected]>
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.

4 participants