1
- good_package_commas <- " box::use(
2
- dplyr,
3
- stringr[
4
- select,
5
- mutate
6
- ],
7
- )"
8
-
9
- good_package_commas_inline <- " box::use(dplyr, stringr[select, mutate], )"
10
-
11
- good_module_commas <- " box::use(
12
- path/to/file1,
13
- path/to/file2[
14
- first_function,
15
- second_function
16
- ],
17
- )"
18
-
19
- good_module_commas_inline <- " box::use(path/to/file1, path/to/file2, )"
20
-
21
- bad_package_commas <- " box::use(
22
- dplyr,
23
- stringr
24
- )"
25
-
26
- bad_package_commas_inline <- " box::use(dplyr, stringr)"
27
-
28
- bad_package_function_commas <- " box::use(
29
- dplyr,
30
- stringr[
31
- select,
32
- mutate
33
- ],
34
- )"
35
-
36
- bad_pkg_function_commas_inline <- " box::use(stringr[select, mutate],)"
37
-
38
- bad_module_commas <- " box::use(
39
- path/to/file1,
40
- path/to/file2
41
- )"
42
-
43
- bad_module_commas_inline <- " box::use(path/to/file1, path/to/file2)"
44
-
45
- bad_module_function_commas <- " box::use(
46
- path/to/file2[
47
- first_function,
48
- second_function
49
- ],
50
- )"
1
+ test_that(" box_trailing_commas_linter skips allowed package import usage" , {
2
+ linter <- box_trailing_commas_linter()
51
3
52
- bad_mod_function_commas_inline <- " box::use(path/to/file2[first_function, second_function], )"
4
+ good_package_commas <- " box::use(
5
+ dplyr,
6
+ stringr[
7
+ select,
8
+ mutate
9
+ ],
10
+ )"
53
11
54
- should_not_lint <- " x <- c(1, 2, 3 )"
12
+ good_package_commas_inline <- " box::use(dplyr, stringr[select, mutate], )"
55
13
56
- paren_lint_msg <- rex :: rex(" Always have a trailing comma at the end of imports, before a `)`." )
57
- bracket_lint_msg <- rex :: rex(" Always have a trailing comma at the end of imports, before a `]`." )
14
+ good_module_commas <- " box::use(
15
+ path/to/file1,
16
+ path/to/file2[
17
+ first_function,
18
+ second_function
19
+ ],
20
+ )"
58
21
59
- test_that(" box_trailing_commas_linter skips allowed package import usage" , {
60
- linter <- box_trailing_commas_linter()
22
+ good_module_commas_inline <- " box::use(path/to/file1, path/to/file2, )"
61
23
62
24
lintr :: expect_lint(good_package_commas , NULL , linter )
63
25
lintr :: expect_lint(good_package_commas_inline , NULL , linter )
@@ -68,33 +30,76 @@ test_that("box_trailing_commas_linter skips allowed package import usage", {
68
30
test_that(" box_trailing_commas_linter blocks no trailing commas in package imports" , {
69
31
linter <- box_trailing_commas_linter()
70
32
33
+ bad_package_commas <- " box::use(
34
+ dplyr,
35
+ stringr
36
+ )"
37
+
38
+ bad_package_commas_inline <- " box::use(dplyr, stringr)"
39
+
40
+ paren_lint_msg <- rex :: rex(" Always have a trailing comma at the end of imports, before a `)`." )
41
+
71
42
lintr :: expect_lint(bad_package_commas , list (message = paren_lint_msg ), linter )
72
43
lintr :: expect_lint(bad_package_commas_inline , list (message = paren_lint_msg ), linter )
73
44
})
74
45
75
46
test_that(" box_trailing_commas_linter check_functions = TRUE blocks no trailing commas" , {
76
47
linter <- box_trailing_commas_linter(check_functions = TRUE )
77
48
49
+ bracket_lint_msg <- rex :: rex(" Always have a trailing comma at the end of imports, before a `]`." )
50
+
51
+ bad_package_function_commas <- " box::use(
52
+ dplyr,
53
+ stringr[
54
+ select,
55
+ mutate
56
+ ],
57
+ )"
58
+
59
+ bad_pkg_function_commas_inline <- " box::use(stringr[select, mutate],)"
60
+
78
61
lintr :: expect_lint(bad_package_function_commas , list (message = bracket_lint_msg ), linter )
79
62
lintr :: expect_lint(bad_pkg_function_commas_inline , list (message = bracket_lint_msg ), linter )
80
63
})
81
64
82
65
test_that(" box_trailing_comma_linter blocks no trailing commas in module imports" , {
83
66
linter <- box_trailing_commas_linter()
84
67
68
+ bad_module_commas <- " box::use(
69
+ path/to/file1,
70
+ path/to/file2
71
+ )"
72
+
73
+ bad_module_commas_inline <- " box::use(path/to/file1, path/to/file2)"
74
+
75
+ paren_lint_msg <- rex :: rex(" Always have a trailing comma at the end of imports, before a `)`." )
76
+
85
77
lintr :: expect_lint(bad_module_commas , list (message = paren_lint_msg ), linter )
86
78
lintr :: expect_lint(bad_module_commas_inline , list (message = paren_lint_msg ), linter )
87
79
})
88
80
89
81
test_that(" box_trailing_commas_linter check_functions = TRUE blocks no trailing commas" , {
90
82
linter <- box_trailing_commas_linter(check_functions = TRUE )
91
83
84
+ bad_module_function_commas <- " box::use(
85
+ path/to/file2[
86
+ first_function,
87
+ second_function
88
+ ],
89
+ )"
90
+
91
+ bad_mod_function_commas_inline <- " box::use(path/to/file2[first_function, second_function], )"
92
+
93
+ bracket_lint_msg <- rex :: rex(" Always have a trailing comma at the end of imports, before a `]`." )
94
+
92
95
lintr :: expect_lint(bad_module_function_commas , list (message = bracket_lint_msg ), linter )
93
96
lintr :: expect_lint(bad_mod_function_commas_inline , list (message = bracket_lint_msg ), linter )
94
97
})
95
98
96
99
test_that(" box_trailing_commas_linter should not lint outside of `box::use()`" , {
97
100
linter <- box_trailing_commas_linter()
98
101
102
+ should_not_lint <- " x <- c(1, 2, 3)"
103
+
99
104
lintr :: expect_lint(should_not_lint , NULL , linter )
100
105
})
0 commit comments