Skip to content

Review: Alignment vignette #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions vignettes/detect-alignment.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,17 @@ fell(
```

**If not all arguments of the first column are named:**^[In the below example,
the first argument of the first column is named (`p = 2`), the second argument
of the first column is not (`31`)] Make all but the first column's commas match
position vertically and right align everything between the commas, except before
the first comma on a line, give priority to correctly indent (i.e. left align):
the first argument of the first column is named (`p = 2`). The second argument
of the first column is not (`31`).] Make **all except the first column's
commas** match position

- vertically

- right align everything between the commas

- except before the first comma on a line

- give priority to correctly indent (i.e. left align):

```{r}
# not all arguments of first column named, hence, only
Expand All @@ -104,8 +111,8 @@ gell(
By *align everything in between the commas*, we mean put zero space before a
comma and at least one after. Note that the arguments on the first line are
ignored when detecting alignment, which is best shown when code is formatted
such that no line breaks will be modified by styler (which is the case if all
names on the first line are unnamed and all subsequent are named), like here:
such that no line breaks will be modified by _styler_. This applies if all names
on the first line are unnamed and all subsequent are named:

```{r}
map(x, f,
Expand All @@ -116,7 +123,7 @@ map(x, f,

**Examples**

These typical examples match styler's definition of alignment.
These typical examples match _styler_'s definition of alignment.

```{r}
tibble::tribble(
Expand All @@ -134,14 +141,14 @@ purrr::map(x, fun, # arguments on same line as opening brace are not considered
## Technical definition

This section closely follows the implementation of the alignment detection and
is mostly aimed at developers for understanding styler internals.
is mostly aimed at developers for understanding _styler_ internals.

Function calls are aligned if **all** of the following conditions hold (for all
but the very first line (i.e. `call(` below):

* all rows in first column has same number of lag spaces. This basically means
that the indention is identical for all columns (except for the closing brace
if it is on its own line). The below example has one column, because the
* all rows in first column have the same number of lag spaces. This basically
means that the indention is identical for all columns (except for the closing
brace if it is on its own line). The below example has one column, because the
maximal number of commas on one line is one.

```{r}
Expand Down Expand Up @@ -181,12 +188,12 @@ call(
considered. The reason to exclude the first column is that, as in the example
below, it is possible that some arguments are named while others are not.
Then, it is not generally possible to keep the first rule (i.e. indention
identical across lines) as well as ensuring that the comma does not have any
spaces before it and that the comma is aligned with the other lines. This is
shown below with the line `f(x, y),`. For this reason, the requirements
exclude the first column in such cases. The *holds* example shows that is is
possible (but not required) for named arguments to also have the commas
separating the first and second column aligned.
identical across lines). Also ensuring that the comma does not have any spaces
before it and its alignment with other lines does not hold true. This is shown
below with the line `f(x, y),`. For this reason, the requirements exclude the
first column in such cases. The *holds* example shows that is is possible (but
not required) for named arguments to also have the commas separating the first
and second column aligned.

```{r}
# holds
Expand All @@ -205,7 +212,7 @@ call(
)
```

Note that the above definition does not check alignment of `=`, so styler will
Note that the above definition does not check alignment of `=`, so _styler_ will
treat the following as aligned:

```{r}
Expand Down