Skip to content

Indentation issue in multi-line conditional expressions #1065

@IndrajeetPatil

Description

@IndrajeetPatil

Currently, the multi-line conditional expressions don't have the same indentation.

E.g., the following code, when styled with {styler} remains unchanged:

communicate_warning <- function(changed, transformers) {
  if (any(changed, na.rm = TRUE) &&
    !parse_tree_must_be_identical(transformers) &&
    !getOption("styler.quiet", FALSE)
  ) {
    cat("Please review the changes carefully!", fill = TRUE)
  }
}

Shouldn't it instead be styled to the following?

communicate_warning <- function(changed, transformers) {
  if (any(changed, na.rm = TRUE) &&
      !parse_tree_must_be_identical(transformers) &&
      !getOption("styler.quiet", FALSE)
  ) {
    cat("Please review the changes carefully!", fill = TRUE)
  }
}

As an aside, the current behaviour in {styler} conflicts with {lintr}, which produces lint for the styled code (cc @AshesITR):

library(lintr)

code <- 'communicate_warning <- function(changed, transformers) {
  if (any(changed, na.rm = TRUE) &&
    !parse_tree_must_be_identical(transformers) &&
    !getOption("styler.quiet", FALSE)
  ) {
    cat("Please review the changes carefully!", fill = TRUE)
  }
}'

lint(
  text = code,
  linters = indentation_linter()
)
#> <text>:3:4: style: [indentation_linter] Indentation should be 6 spaces but is 4 spaces.
#>     !parse_tree_must_be_identical(transformers) &&
#>    ^~~

Created on 2022-11-21 with reprex v2.0.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions