Repository navigation
Skip linting eval=FALSE chunks - #3072
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3072 +/- ##
=======================================
Coverage 99.25% 99.26%
=======================================
Files 128 128
Lines 7417 7436 +19
=======================================
+ Hits 7362 7381 +19
Misses 55 55 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Gemini review: Summary of ChangesThe PR aims to skip linting of R Markdown/Quarto/Sweave chunks that are marked as Review Findings1. Robustness: Parsing Transient Code (Critical)During background linting in IDEs, files are often in a transient, syntactically malformed state. Recommendation: Wrap both option parsing calls in is_eval_chunk <- function(start, end, lines, pattern) {
header <- lines[start]
params_src <- trimws(gsub(pattern$chunk.begin, "\\1", header))
header_params <- tryCatch(
suppressWarnings(xfun::csv_options(params_src)),
error = function(e) NULL
)
code <- lines[(start + 1L):(end - 1L)]
body_params <- tryCatch(
suppressWarnings(xfun::divide_chunk("r", code)$options),
error = function(e) NULL
)
eval_value <- body_params$eval %||% header_params$eval
if (identical(eval_value, quote(F))) {
return(FALSE)
}
!isFALSE(eval_value)
}2. Design: Avoid Double NegationThe current implementation uses Recommendation:
Suggested refactoring for @@ -73,8 +73,12 @@
starts <- starts[nonempty_keep]
ends <- ends[nonempty_keep]
- eval_keep <- !as.logical(Map(\(start, end) non_eval_chunk(start, end, lines, pattern), starts, ends))
- starts <- starts[eval_keep]
- ends <- ends[eval_keep]
+ eval_keep <- vapply(
+ seq_along(starts),
+ function(i) is_eval_chunk(starts[i], ends[i], lines, pattern),
+ FUN.VALUE = logical(1)
+ )
+ starts <- starts[eval_keep]
+ ends <- ends[eval_keep]3. TestsThe added tests in
|
Closes #1964. Initial pass authored by Gemini (I'll try and keep LLM edits pristine and marked as such in the commit log in the PR before ultimately squashing), though you can see it was a bit off on the code quality mark.