Skip to content

Commit 168f58f

Browse files
Merge pull request #697 from lorenzwalthert/issue-696
- Allow unary + before function call (#697).
2 parents 491f3c3 + 166c17e commit 168f58f

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
- `style_dir()` and `style_pkg()` now apply directory exclusion recursively with
2727
`exclude_dirs` (#676).
28+
- unary `+` before a function call does not give an error anymore, as before
29+
version 1.3.0 (#697).
2830
- cache is now correctly invalidated when style guide arguments change (#647).
2931
- empty lines are now removed between pipes (#645).
3032
- overhaul pgkdown site: Add search (#623), group function in Reference (#625).

R/rules-line-break.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ remove_line_break_in_fun_call <- function(pd, strict) {
286286

287287

288288
set_linebreak_after_ggplot2_plus <- function(pd) {
289-
is_plus_raw <- pd$token == "'+'"
289+
# if expression is unary, first token is +. Exclude this case.
290+
is_plus_raw <- c(FALSE, pd$token[-1] == "'+'")
290291
if (any(is_plus_raw)) {
291292
first_plus <- which(is_plus_raw)[1]
292293
next_non_comment <- next_non_comment(pd, first_plus)

tests/testthat/line_breaks_and_other/ggplot2-in.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ x[1]+ c()
3636
g() + x[1]
3737

3838
g()[2] + x[1]
39+
40+
# don't do anything on unary + and function call
41+
+sin(x)

tests/testthat/line_breaks_and_other/ggplot2-in_tree

Lines changed: 29 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/line_breaks_and_other/ggplot2-out.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ x[1] + c()
4545
g() + x[1]
4646

4747
g()[2] + x[1]
48+
49+
# don't do anything on unary + and function call
50+
+sin(x)

tests/testthat/line_breaks_and_other/pipe-line-breaks-in_tree

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)