---
title: "The effect of `strict = FALSE`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{The effect of `strict = FALSE`}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  results = "hide"
)

styler::cache_deactivate()

knitr::knit_engines$set(list(
  styler = function(options) {
    options$comment <- ""
    knitr::engine_output(
      options,
      {
        before <- options$code
        after <- as.character(styler::style_text(options$code, strict = FALSE))
        if (!identical(trimws(before, "right"), after)) {
          stop(
            "Before unlike after. Before:", paste(before, sep = "\n"),
            "After: ", paste(after, sep = "\n")
          )
        }
        after
      },
      ""
    )
  }
))
```

This vignette shows how output from styler might differ when `strict = FALSE`. For brevity, we don't show the output of `strict = TRUE`, but it should be pretty simple for the user to derive it from the bullet point(s) or simply paste the code in the console to see the output.

```{r setup}
library(styler)
```

-   multi-line function declarations without curly braces are tolerated.

```{styler}
function()
  NULL
```

-   Spaces before opening parenthesis, tilde as well as around comments and math token must be at least one, not exactly one.

```{styler}
1  +    (1 + 3)
1 ~  more()   #   comment
```

-   Line breaks between curly and round braces are not removed.

```{styler}
test({
  1
}
)
```

-   Multi-line calls don't put the closing brace on a new line nor trigger a line break after the opening brace.

```{styler}
call(
  this)
call(2,
  more
)
```

-   No line break inserted after pipes nor ggplot2 or pipe expressions.

```{styler}
ggplot2::ggplot(data, aes(x, y)) + geom_line() + scale_x_continuous()

this %>% is() %>% a() %>% long() %>% pipe()
```

-   ifelse statements don't get curly braces added when multi-line.

```{styler}
if (TRUE) 3  else 
  5
```
