From 84cdc87e0f34b06a258769b823c2299b2e9fa3e0 Mon Sep 17 00:00:00 2001 From: Alexander Rosenstock Date: Sun, 31 Jan 2021 14:02:52 +0100 Subject: [PATCH] fixes #451 --- NEWS.md | 1 + R/comment_linters.R | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index ee044e6ed..971cf7f3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -45,6 +45,7 @@ * Set the default `complexity_limit` in `cyclocomp_linter` to 15. This is the same complexity limit that is enforced via `default_linters` (#693, #695, @AshesITR). * `lint_package()` now lints files in the `demo` directory by default (#703, @dmurdoch). +* `commented_code_linter()` now no longer lints parts of actual code (#451, @AshesITR) # lintr 2.0.1 diff --git a/R/comment_linters.R b/R/comment_linters.R index 98b120806..6204bdf57 100644 --- a/R/comment_linters.R +++ b/R/comment_linters.R @@ -45,6 +45,16 @@ commented_code_linter <- function(source_file) { line_numbers <- rownames(na.omit(res)) lapply(line_numbers, function(line_number) { line <- source_file$file_lines[as.numeric(line_number)] + line_code_end <- max( + source_file$full_parsed_content[source_file$full_parsed_content$line1 == line_number & + source_file$full_parsed_content$line2 == line_number, "col2"], + 0 + ) + if (res[line_number, "code.start"] < line_code_end) { + # regex matched a part of actual code + return() + } + is_parsable <- parsable(substr(line, res[line_number, "code.start"], res[line_number, "code.end"]))