Skip to content

Implement if statement autobracing #340

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 21 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f80f39c
First draft of if statement autobracing
DavisVaughan May 1, 2025
5382eea
Correctly recurse into `consequence` when handling non-enclosed comments
DavisVaughan May 1, 2025
c73c951
Handle nested if statements in `consequence`
DavisVaughan May 1, 2025
7b7e458
Add failing test
DavisVaughan May 2, 2025
5f750da
Don't pass pre-computed `braced_expression` value through to nested i…
DavisVaughan May 2, 2025
f440204
Add one more test seen in data.table
DavisVaughan May 2, 2025
5cdef64
More test cases
DavisVaughan May 2, 2025
a7a7a62
Another test case
DavisVaughan May 2, 2025
4e48549
Another test
DavisVaughan May 2, 2025
a855327
Remove handling of comments not enclosed by the if statement
DavisVaughan May 2, 2025
27f782c
Prefer generating leading comments
DavisVaughan May 2, 2025
daeb004
Fix a typo buglet
DavisVaughan May 5, 2025
c178cec
Only allow one liner if statements in specific contexts
DavisVaughan May 8, 2025
dc989dc
Add symmetrical support for function parameters, to mirror call argum…
DavisVaughan May 8, 2025
eb94ecd
Refine end of line comments before `else`
DavisVaughan May 9, 2025
7a78f30
Remove context awareness from one liner computation
DavisVaughan May 14, 2025
3edba1c
Add additional tests from trying it on dplyr
DavisVaughan May 14, 2025
2d4b5af
Implement `SyntaxPosition` for `Value` vs `Effect` positioning
DavisVaughan May 15, 2025
0c586d7
Tweak outdated comments
DavisVaughan May 16, 2025
a26918a
Autobrace for loops, while loops, repeat loops, and function definiti…
DavisVaughan May 29, 2025
97b9c4e
Tweak a comment
DavisVaughan May 29, 2025
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
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@

# Development version

- Autobracing is a new feature applied to if statements, for loops, while loops,
repeat loops, and function definitions. This feature will automatically add
`{}` around the body of these code elements in certain cases to maximize
readability, consistency, and portability (#225, #334).

For example:

```r
if (condition)
a

# Becomes:
if (condition) {
a
}
```

```r
fn <- function(
a, b
) a + b

# Becomes:
fn <- function(
a,
b
) {
a + b
}
```

Single line if statements and function definitions are still allowed in certain contexts:

```r
list(a = if (is.null(x)) NA else x)

map(xs, function(x) x + 1)
```


# 0.5.0

Expand Down
Loading