Skip to content
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

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

Closed
stufield opened this issue Feb 26, 2018 · 6 comments · Fixed by #394
Closed

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

stufield opened this issue Feb 26, 2018 · 6 comments · Fixed by #394

Comments

@stufield
Copy link
Collaborator

stufield commented Feb 26, 2018

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]
              )
        }
    })
}
@jimhester
Copy link
Member

You are right, these helper functions should be exported and using ::: is the best you can do at the moment.

@stufield
Copy link
Collaborator Author

Great, thanks. Just wanted to make sure this was the only current option.
Cheers

@stufield
Copy link
Collaborator Author

Hi Jim,
Would you like me to submit a PR to export these functions? In particular:

  • ids_with_token()
  • with_id()

Happy to do so, I know it's been a long time, but since I'm a heavy user of lintr (and a fan), I'd be happy to contribute.

@jimhester
Copy link
Member

Definitely, thanks!

@stufield
Copy link
Collaborator Author

Crap! Did I just volunteer to write a bunch of documentation? :) Ha ha ha.

@stufield
Copy link
Collaborator Author

Working on this now ... PR coming. Sorry for the delay :(

jimhester pushed a commit that referenced this issue Sep 3, 2019
- rm 'ids_with_token' and 'with_id' from utils.R
- add new files 'ids_with_token.R' and 'with_id.R'
- roxygen updated NAMESPACE for new exports
- new docs; combined into 'ids_with_tokens.Rd'
- add *.R files to Collate entry of DESCRIPTION
- add 'Encoding' field to DESCRIPTION to avoid Roxygen warning
- Update NEWS.md
- Closes #297
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants