-
Notifications
You must be signed in to change notification settings - Fork 187
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
lintr::lint fails with `` #566
Comments
It looks the problem arises from https://github.com/jimhester/lintr/blob/master/R/get_source_expressions.R#L83 where the Looks like
In this case where |
Is there any other character sequence that can cause this?
doesn't fail (this is curious because evaluating said code will produce said error). I'm thinking this edge case might be aided by |
I've done some digging through R's parser implementation and didn't see any obvious other errors from parse without line data. AFAIK we should be safe to assume that the parse error Error cases: parse(text = "``")
parse(text = "``()")
parse(text = "''()")
parse(text = '""()')
parse(text = "fun('' = 42)")
parse(text = 'fun("" = 42)') Non-error cases: parse(text = "'' <- 42")
parse(text = '"" <- 42') |
It will fail as long as there's empty backticked symbol > parse(text = "a + `` + b")
Error in parse(text = "a + `` + b") :
attempt to use zero-length variable name If there are mixed ones in strings, then paste0("```r", ``, "```", collapse = "\n") |
Thanks for the nice findings of those cases that produce the same error! |
In case you want to dig further, the meat of the parser is here: The question is whether a 90% solution that greps for the first suspicious token is more useful than throwing in the user's face. Maybe the lint message could contain a caveat like "error location may be inaccurate"? |
The source to throw this error is https://github.com/wch/r-source/blob/trunk/src/main/names.c#L1248. Looks like the error is not from the parser but an attempt to create an empty symbol object during or after the parsing.
I guess a simple grep should be enough in most cases to notice user? |
Yep, the parser calls grep sounds good. Maybe fallback to line 1 col 1 if all else fails so we dont error out in any case. |
If the code contains the following double backticks
``
then
lintr::lint()
will fail:Parsing the text will produce the following error:
The text was updated successfully, but these errors were encountered: