Skip to contents

Check that each step in a pipeline is on a new line, or the entire pipe fits on one line.

Usage

pipe_continuation_linter()

See also

Examples

# will produce lints
code_lines <- "1:3 %>%\n mean() %>% as.character()"
writeLines(code_lines)
#> 1:3 %>%
#>  mean() %>% as.character()
lint(
  text = code_lines,
  linters = pipe_continuation_linter()
)
#> ::warning file=<text>,line=2,col=9::file=<text>,line=2,col=9,[pipe_continuation_linter] `%>%` should always have a space before it and a new line after it, unless the full pipeline fits on one line.

code_lines <- "1:3 |> mean() |>\n as.character()"
writeLines(code_lines)
#> 1:3 |> mean() |>
#>  as.character()
lint(
  text = code_lines,
  linters = pipe_continuation_linter()
)
#> ::warning file=<text>,line=1,col=15::file=<text>,line=1,col=15,[pipe_continuation_linter] `|>` should always have a space before it and a new line after it, unless the full pipeline fits on one line.

# okay
lint(
  text = "1:3 %>% mean() %>% as.character()",
  linters = pipe_continuation_linter()
)

code_lines <- "1:3 %>%\n mean() %>%\n as.character()"
writeLines(code_lines)
#> 1:3 %>%
#>  mean() %>%
#>  as.character()
lint(
  text = code_lines,
  linters = pipe_continuation_linter()
)

lint(
  text = "1:3 |> mean() |> as.character()",
  linters = pipe_continuation_linter()
)

code_lines <- "1:3 |>\n mean() |>\n as.character()"
writeLines(code_lines)
#> 1:3 |>
#>  mean() |>
#>  as.character()
lint(
  text = code_lines,
  linters = pipe_continuation_linter()
)