# will produce lints
code_lines <- "f <- function() {\n return(1 + 1)\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "if (FALSE) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "while (FALSE) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "f <- function() {\n return(1)\n # end skip\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
# okay
code_lines <- "f <- function() {\n return(1 + 1)\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "if (foo) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "while (foo) {\n 2 + 2\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter()
)
code_lines <- "f <- function() {\n return(1)\n # end skip\n}"
writeLines(code_lines)
lint(
text = code_lines,
linters = unreachable_code_linter(allow_comment_regex = "# end skip")
)
Run the code above in your browser using DataLab