Skip to content

object_usage_linter gets line number wrong in multi-NSE case #1914

@MichaelChirico

Description

@MichaelChirico

Here, note that NSE is used in both the formula and the data= argument, and it's throwing off the line number detection:

lintr::lint("
foo <- function(x) {
  lm(
    y ~ z,
    data = x[!is.na(y)]
  )
}
", lintr::object_usage_linter())
# <text>:4:5: warning: [object_usage_linter] no visible binding for global variable 'y'
#     y ~ z,
#     ^

This makes it look like codetools is confused by the LHS of the formula, but actually what's being marked is the data= argument on the next line.

codetools itself only provides a range:

codetools::checkUsage(foo)
# <anonymous>: no visible binding for global variable ‘y’ (:2-5)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions