33
33
# ' transformers <- tidyverse_style()
34
34
# ' pd_nested <- styler:::compute_parse_data_nested(c(
35
35
# ' "call(",
36
- # ' " ab = 1 ,",
36
+ # ' " ab = 1L ,",
37
37
# ' " a = 2",
38
38
# ' ")"
39
39
# ' )) %>%
@@ -50,7 +50,7 @@ token_is_on_aligned_line <- function(pd_flat) {
50
50
pd_flat $ .lag_spaces <- lag(pd_flat $ spaces )
51
51
pd_by_line <- split(pd_flat , line_idx )
52
52
pd_by_line [purrr :: map_lgl(pd_by_line , ~ any(.x $ stylerignore ))] <- NULL
53
- if (length(pd_by_line ) < 1 ) {
53
+ if (length(pd_by_line ) < 1L ) {
54
54
return (TRUE )
55
55
}
56
56
last_line_is_closing_brace_only <- nrow(last(pd_by_line )) == 1
@@ -93,7 +93,7 @@ token_is_on_aligned_line <- function(pd_flat) {
93
93
}
94
94
95
95
pd_by_line <- alignment_drop_comments(pd_by_line )
96
- if (length(pd_by_line ) < 1 ) {
96
+ if (length(pd_by_line ) < 1L ) {
97
97
return (TRUE )
98
98
}
99
99
pd_by_line <- alignment_drop_last_expr(pd_by_line ) %> %
@@ -104,10 +104,9 @@ token_is_on_aligned_line <- function(pd_flat) {
104
104
# now, pd only contains arguments separated by values, ideal for iterating
105
105
# over columns.
106
106
n_cols <- map_int(pd_by_line , ~ sum(.x $ token == " ','" ))
107
- previous_line <- 0
108
- current_col <- 0
109
- start_eval <- ifelse(alignment_col1_all_named(pd_by_line ), 1 , 2 )
110
- for (column in seq2(1 , max(n_cols ))) {
107
+ previous_line <- current_col <- 0L
108
+ start_eval <- ifelse(alignment_col1_all_named(pd_by_line ), 1L , 2L )
109
+ for (column in seq2(1L , max(n_cols ))) {
111
110
by_line <- alignment_serialize_column(pd_by_line , column ) %> %
112
111
compact() %> %
113
112
unlist() %> %
@@ -120,7 +119,7 @@ token_is_on_aligned_line <- function(pd_flat) {
120
119
current_col <- nchar(by_line ) - as.integer(column > 1 )
121
120
# Problem `by_line` counting from comma before column 3, previous_line
122
121
# counting 1 space before ~
123
- if (column > 1 ) {
122
+ if (column > 1L ) {
124
123
previous_line <- previous_line [
125
124
intersect(names(previous_line ), names(by_line ))
126
125
]
@@ -129,28 +128,28 @@ token_is_on_aligned_line <- function(pd_flat) {
129
128
}
130
129
131
130
is_aligned <- length(unique(current_col )) == 1L
132
- if (! is_aligned || length(current_col ) < 2 ) {
131
+ if (! is_aligned || length(current_col ) < 2L ) {
133
132
# check 2: left aligned after , (comma to next token)
134
133
current_col <- " ^(,[\\ s\\ t]*)[^ ]*.*$" %> %
135
134
gsub(" \\ 1" , by_line , perl = TRUE ) %> %
136
135
nchar() %> %
137
136
magrittr :: subtract(1 )
138
137
139
- if (column > 1 ) {
138
+ if (column > 1L ) {
140
139
# must add previous columns, as first column might not align
141
140
current_col <- previous_line + current_col
142
141
}
143
- if (length(current_col ) > 1 ) {
142
+ if (length(current_col ) > 1L ) {
144
143
is_aligned <- length(unique(current_col )) == 1L
145
144
} else {
146
- is_aligned <- current_col - max_previous_col == 1
145
+ is_aligned <- current_col - max_previous_col == 1L
147
146
current_col <- max_previous_col + current_col
148
147
}
149
148
150
149
if (is_aligned ) {
151
150
# if left aligned after ,
152
- start_eval <- 2
153
- previous_line <- nchar(by_line ) - 1 + previous_line # comma to comma
151
+ start_eval <- 2L
152
+ previous_line <- nchar(by_line ) - 1L + previous_line # comma to comma
154
153
}
155
154
} else {
156
155
previous_line <- current_col
@@ -162,22 +161,22 @@ token_is_on_aligned_line <- function(pd_flat) {
162
161
# match left aligned after =
163
162
start_after_eq <- regexpr(" = [^ ]" , by_line )
164
163
names(start_after_eq ) <- names(by_line )
165
- start_after_eq <- start_after_eq [start_after_eq > 0 ]
164
+ start_after_eq <- start_after_eq [start_after_eq > 0L ]
166
165
167
166
if (column > = start_eval ) {
168
- if (length(start_after_eq ) == 0 ) {
167
+ if (length(start_after_eq ) == 0L ) {
169
168
return (FALSE )
170
169
}
171
170
# when match via , unsuccessful, matching by = must yield at least one =
172
- if (column == 1 ) {
171
+ if (column == 1L ) {
173
172
current_col <- start_after_eq
174
173
} else {
175
174
current_col <- start_after_eq +
176
175
previous_line [intersect(names(previous_line ), names(start_after_eq ))]
177
176
}
178
177
is_aligned <- all(
179
- length(unique(current_col )) == 1 ,
180
- length(start_after_eq ) > 1
178
+ length(unique(current_col )) == 1L ,
179
+ length(start_after_eq ) > 1L
181
180
)
182
181
if (! is_aligned ) {
183
182
return (FALSE )
0 commit comments