Skip to content

Rmd: Markdown fenced code blocks with language identifier cause Error: Malformed file! #505

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

Closed
salim-b opened this issue Jul 3, 2020 · 2 comments

Comments

@salim-b
Copy link
Contributor

salim-b commented Jul 3, 2020

Problem

Consider the following reprex:

example_file <- tempfile()

readr::write_file(path = example_file,
                  x = '# Rmd example file

## R code chunk

The following is linted fine:

```{r}
print ("hi" )
```

## Plain code block

The following fenced code block _without_ a language identifier is not linted (also fine!):

```
print ("hi" )
```

## Code block with language identifier

The language identifier of the following code block triggers a \'malformed file\' error (bad!):

```r
print ("hi" )
```
')

lintr::lint(filename = example_file)
#> Error: Malformed file!

Created on 2020-07-03 by the reprex package (v0.3.0)

Markdown code blocks with a language identifier are valid R Markdown syntax and should simply be excluded from linting.

Possibly related

If I understand it correctly, R Markdown files should be supported by lintr as of 50ab86d fixing #32.

In #252, a similar issue was raised which has been solved by fdd1950, assumedly without properly handling language identifiers. I'm not familiar with lintr's internals and didn't dive into the code, but I guess the R code extraction logic in https://github.com/jimhester/lintr/blob/master/R/extract.R is erroneous. Maybe @russHyde or @jimhester could have a look at this?

Maybe also related: #322

@russHyde
Copy link
Collaborator

russHyde commented Jul 3, 2020

could you confirm this error using the current master branch of lintr, we have a test case that covers the case:

```r
abc = 123
```

@salim-b
Copy link
Contributor Author

salim-b commented Jul 5, 2020

could you confirm this error using the current master branch of lintr

Just tested the current master branch: The issue is gone, no more error. 👍 I should have tested this before opening this issue 🙈 Thanks for the hint!

@salim-b salim-b closed this as completed Jul 5, 2020
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

No branches or pull requests

2 participants