unnecessary_nested_if_linter: Avoid unnecessary nested 'if' conditional statements

unnecessary_nested_if_linterR Documentation

Avoid unnecessary nested if conditional statements

Description

Avoid unnecessary nested if conditional statements

Usage

unnecessary_nested_if_linter()

Tags

best_practices, readability

See Also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
writeLines("if (x) { \n  if (y) { \n   return(1L) \n  } \n}")
lint(
  text = "if (x) { \n  if (y) { \n   return(1L) \n  } \n}",
  linters = unnecessary_nested_if_linter()
)

# okay
writeLines("if (x && y) { \n  return(1L) \n}")
lint(
  text = "if (x && y) { \n  return(1L) \n}",
  linters = unnecessary_nested_if_linter()
)

writeLines("if (x) { \n  y <- x + 1L\n  if (y) { \n   return(1L) \n  } \n}")
lint(
  text = "if (x) { \n  y <- x + 1L\n  if (y) { \n   return(1L) \n  } \n}",
  linters = unnecessary_nested_if_linter()
)


lintr documentation built on May 29, 2024, 11:31 a.m.