Skip to content

Infix operator lint metadata is not helpful for object_usage_linter #1497

Description

@MichaelChirico
lintr::lint("a <- function() {\n  1:10 %>% sum()\n}", lintr::object_usage_linter())
# <text>:1:6: warning: [object_usage_linter] no visible global function definition for ‘%>%’. Disable this with a comment: `# nolint` (one line) or `# lintr: disable` (multiple lines). See go/tidy-style#linting for more.
# a <- function() {
#      ^~~~~~~~~~~~

The linter anchors to the function definition, not to the usage of %>% itself. Similar goes for other infixes, e.g.

lintr::lint("a <- function() {\n  1:10 %>% sum()\n}", lintr::object_usage_linter())
# <text>:1:6: warning: [object_usage_linter] no visible global function definition for ‘:=’. Disable this with a comment: `# nolint` (one line) or `# lintr: disable` (multiple lines). See go/tidy-style#linting for more.
# a <- function(x) {
#      ^~~~~~~~~~~~~

I guess this is codetools' fault, but is there something we can do to patch it up? Or maybe we have a bad XPath?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorobject linters 🏀

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions