lintr
lintr copied to clipboard
False positive in `unnecessary_nested_if_linter()`
'if (a) {
if (b) {
if (c) {
message("hi")
}
t <- 1L
}
}' -> code
library(lintr)
lint(
text = code,
linters = unnecessary_nested_if_linter()
)
#> <text>:2:3: warning: [unnecessary_nested_if_linter] Don't use nested `if` statements, where a single `if` with the combined conditional expression will do. For example, instead of `if (x) { if (y) { ... }}`, use `if (x && y) { ... }`.
#> if (b) {
#> ^~~~~~~~
Created on 2023-01-06 with reprex v2.0.2
But the suggested modification is not equivalent to the original code:
if (a) {
if (b && c) {
message("hi")
t <- 1L
}
}