@@ -26,7 +26,19 @@ test_that("finds seq(...) expressions", {
26
26
27
27
expect_lint(
28
28
" function(x) { seq(nrow(x)) }" ,
29
- rex(" seq(nrow(...))" , anything , " Use seq_len(...)" ),
29
+ rex(" seq(nrow(...))" , anything , " Use seq_len(nrow(...))" ),
30
+ linter
31
+ )
32
+
33
+ expect_lint(
34
+ " function(x) { rev(seq(length(x))) }" ,
35
+ rex(" seq(length(...))" , anything , " Use seq_along(...)" ),
36
+ linter
37
+ )
38
+
39
+ expect_lint(
40
+ " function(x) { rev(seq(nrow(x))) }" ,
41
+ rex(" seq(nrow(...))" , anything , " Use seq_len(nrow(...))" ),
30
42
linter
31
43
)
32
44
})
@@ -99,6 +111,10 @@ test_that("1L is also bad", {
99
111
})
100
112
101
113
test_that(" reverse seq is ok" , {
114
+ linter <- seq_linter()
115
+ expect_lint(" function(x) { rev(seq_along(x)) }" , NULL , linter )
116
+ expect_lint(" function(x) { rev(seq_len(nrow(x))) }" , NULL , linter )
117
+
102
118
expect_lint(
103
119
" function(x) { length(x):1 }" ,
104
120
rex(" length(...):1" , anything , " Use seq_along" ),
@@ -110,8 +126,8 @@ test_that("Message vectorization works for multiple lints", {
110
126
expect_lint(
111
127
" c(1:length(x), 1:nrow(y))" ,
112
128
list (
113
- rex :: rex(" 1:length(...)" , anything , " seq_along()" ),
114
- rex :: rex(" 1:nrow(...)" , anything , " seq_len()" )
129
+ rex :: rex(" 1:length(...)" , anything , " seq_along(... )" ),
130
+ rex :: rex(" 1:nrow(...)" , anything , " seq_len(nrow(...) )" )
115
131
),
116
132
seq_linter()
117
133
)
@@ -120,7 +136,7 @@ test_that("Message vectorization works for multiple lints", {
120
136
" c(seq(length(x)), 1:nrow(y))" ,
121
137
list (
122
138
rex :: rex(" seq(length(...))" , anything , " seq_along(...)" ),
123
- rex :: rex(" 1:nrow(...)" , anything , " seq_len()" )
139
+ rex :: rex(" 1:nrow(...)" , anything , " seq_len(nrow(...) )" )
124
140
),
125
141
seq_linter()
126
142
)
@@ -129,7 +145,16 @@ test_that("Message vectorization works for multiple lints", {
129
145
" c(seq(length(x)), seq(nrow(y)))" ,
130
146
list (
131
147
rex :: rex(" seq(length(...))" , anything , " seq_along(...)" ),
132
- rex :: rex(" seq(nrow(...))" , anything , " seq_len(...)" )
148
+ rex :: rex(" seq(nrow(...))" , anything , " seq_len(nrow(...))" )
149
+ ),
150
+ seq_linter()
151
+ )
152
+
153
+ expect_lint(
154
+ " c(1:NROW(x), seq(NCOL(y)))" ,
155
+ list (
156
+ rex :: rex(" 1:NROW(...)" , anything , " seq_len(NROW(...)" ),
157
+ rex :: rex(" seq(NCOL(...))" , anything , " seq_len(NCOL(...))" )
133
158
),
134
159
seq_linter()
135
160
)
0 commit comments