Skip to content

Commit bc7c8e9

Browse files
fix: preserve <<- in custom styler, update contributing guide
1 parent 4d674f4 commit bc7c8e9

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ source("inst/styler/bgms_style.R")
2929
styler::style_pkg(style = bgms_style)
3030
```
3131

32+
After styling, check test files for assignment captures inside function
33+
calls, such as `expect_message(result <- foo(), "pattern")`. These must
34+
remain `<-`, because `=` would be interpreted as a named argument.
35+
3236
## Documentation
3337

3438
- **Exported R functions** get full roxygen2 blocks (`@title`,

inst/styler/bgms_style.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ bgms_style <- function() {
1313

1414
# "a <- 1" -> "a = 1"
1515
#
16-
# Preserves <- inside function-call arguments, where = would be interpreted
17-
18-
# as a named argument (e.g. expect_message(result <- foo(), "pattern")).
16+
# Preserves <<- everywhere and preserves <- inside function-call arguments,
17+
# where = would be interpreted as a named argument
18+
# (e.g. expect_message(result <- foo(), "pattern")).
1919
# Detection: the LHS expr's child node has token_before == "'('" when the
2020
# assignment sits inside a call's argument list.
2121
style$token$force_assignment_op <- function(pd) {
2222
to_replace <- pd$token %in% c("EQ_ASSIGN", "LEFT_ASSIGN")
23+
to_replace[pd$text == "<<-"] <- FALSE
2324
if(any(to_replace & pd$token == "LEFT_ASSIGN")) {
2425
for(i in which(to_replace & pd$token == "LEFT_ASSIGN")) {
2526
lhs_row <- i - 1

0 commit comments

Comments
 (0)