Skip to content

Writing Own Linters ... ids_with_token() Not Exported #297

@stufield

Description

@stufield

Hi Jim,

I apologize in advance if I've misunderstood your vignette here:

https://cran.r-project.org/web/packages/lintr/vignettes/creating_linters.html

... but when I write my own linter function, which I basically stole from the assignment_linter(), in your example you suggest using ids_with_token(). However this is not exported by lintr. Same for with_id(). I was able to subvert the "function not found" error by cheating and using the ":::" operator, but that's not an ideal solution.

Am I using it wrong? Maybe the next version could export some of the functions necessary to create your own linters?

Thanks,
Stu

Here is the code ... I'm writing a quick linter to identify old deprecated functions that are mapped in a list object called "deprecate_list":

deprecated_linter <- function(source_file) {
      lapply(lintr:::ids_with_token(source_file, "SYMBOL_FUNCTION_CALL"), function(id) {
         parsed <- lintr:::with_id(source_file, id)
         func   <- parsed$text
         if ( func %in% names(deprecate_list) ) {
           lintr::Lint(filename = source_file$filename,
                       line_number = parsed$line1,
                       column_number = parsed$col1,
                       type = "style",
                       message = str_glue("Don't use deprecated {func} ... use {deprecate_list[[func]]}."),
                       linter = "deprecated_linter",
                       line = source_file$lines[parsed$line1]
              )
        }
    })
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions