From d44909087d3b6feb1053eab6d5be2840861ff8a1 Mon Sep 17 00:00:00 2001 From: Jim Hester Date: Fri, 27 Sep 2019 11:12:40 -0400 Subject: [PATCH] Do not treat Rmd files without code as being all code Fixes #370 --- NEWS.md | 1 + R/extract.R | 2 +- tests/testthat/test-knitr_formats.R | 6 ++---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index d36e8f0b7..0b909ee6b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,5 @@ # lintr 1.0.3.9000 # +* R Markdown files that do not contain chunks are no longer treated as code (#370). * `open_curly_linter()` and `closed_curly_linter()` now do not lint double curly syntax (#388) * `open_curly_linter()` now allows comments after the curly braces (#188) * `lint_package()` now excludes `R/RcppExports.R` by default (#282) diff --git a/R/extract.R b/R/extract.R index a9a0707a4..627402e08 100644 --- a/R/extract.R +++ b/R/extract.R @@ -14,7 +14,7 @@ extract_r_source <- function(filename, lines) { # no chunks found, so just return the lines if (length(starts) == 0 || length(ends) == 0) { - return(lines) + return(character()) } if (length(starts) != length(ends)) { diff --git a/tests/testthat/test-knitr_formats.R b/tests/testthat/test-knitr_formats.R index 707b5f9ca..baf9c2831 100644 --- a/tests/testthat/test-knitr_formats.R +++ b/tests/testthat/test-knitr_formats.R @@ -86,9 +86,7 @@ test_that("it does _not_ handle brew", { }) test_that("it does _not_ error with inline \\Sexpr", { - expect_lint("#' text \\Sexpr{1 + 1} more text\n", - checks = list( - rex("Trailing blank lines are superfluous.") - ), + expect_lint("#' text \\Sexpr{1 + 1} more text", + NULL, default_linters) })