lintr icon indicating copy to clipboard operation
lintr copied to clipboard

False positive in `unnecessary_nested_if_linter()`

Open IndrajeetPatil opened this issue 2 years ago • 5 comments

'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
  }
}

IndrajeetPatil avatar Jan 06 '23 14:01 IndrajeetPatil