diff --git a/R/todo_comment_linter.R b/R/todo_comment_linter.R index 68225d80d..8b7169bae 100644 --- a/R/todo_comment_linter.R +++ b/R/todo_comment_linter.R @@ -2,7 +2,7 @@ #' #' Check that the source contains no TODO comments (case-insensitive). #' -#' @param todo Vector of strings that identify TODO comments. +#' @param todo Vector of case-insensitive strings that identify TODO comments. #' #' @examples #' # will produce lints @@ -42,23 +42,18 @@ #' @export todo_comment_linter <- function(todo = c("todo", "fixme")) { todo_comment_regex <- rex(one_or_more("#"), any_spaces, or(todo)) - Linter(function(source_expression) { - tokens <- with_id(source_expression, ids_with_token(source_expression, "COMMENT")) - are_todo <- re_matches(tokens[["text"]], todo_comment_regex, ignore.case = TRUE) - tokens <- tokens[are_todo, ] - lapply( - split(tokens, seq_len(nrow(tokens))), - function(token) { - Lint( - filename = source_expression[["filename"]], - line_number = token[["line1"]], - column_number = token[["col1"]], - type = "style", - message = "Remove TODO comments.", - line = source_expression[["lines"]][[as.character(token[["line1"]])]], - ranges = list(c(token[["col1"]], token[["col2"]])) - ) - } + + Linter(linter_level = "expression", function(source_expression) { + xml <- source_expression$xml_parsed_content + + comment_expr <- xml_find_all(xml, "//COMMENT") + are_todo <- re_matches(xml_text(comment_expr), todo_comment_regex, ignore.case = TRUE) + + xml_nodes_to_lints( + comment_expr[are_todo], + source_expression = source_expression, + lint_message = "Remove TODO comments.", + type = "style" ) }) } diff --git a/man/todo_comment_linter.Rd b/man/todo_comment_linter.Rd index 5b12d7b58..e2c92aa68 100644 --- a/man/todo_comment_linter.Rd +++ b/man/todo_comment_linter.Rd @@ -7,7 +7,7 @@ todo_comment_linter(todo = c("todo", "fixme")) } \arguments{ -\item{todo}{Vector of strings that identify TODO comments.} +\item{todo}{Vector of case-insensitive strings that identify TODO comments.} } \description{ Check that the source contains no TODO comments (case-insensitive).