Skip to content

Commit 2cd7761

Browse files
committed
address comments/suggestions in PR
1 parent 3197a07 commit 2cd7761

File tree

3 files changed

+67
-57
lines changed

3 files changed

+67
-57
lines changed

R/linter_box_trailing_commas_linter.R renamed to R/box_linters.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#' @param check_functions Boolean flag to include function imports between `[` and `]`.
88
#' Defaults to FALSE.
99
#'
10+
#' @return A custom linter function for use with `r-lib/lintr`
11+
#'
1012
#' @examples
1113
#' # will produce lints
1214
#' lintr::lint(

man/box_trailing_commas_linter.Rd

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,25 @@
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()
513

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+
)"
5311

54-
should_not_lint <- "x <- c(1, 2, 3)"
12+
good_package_commas_inline <- "box::use(dplyr, stringr[select, mutate], )"
5513

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+
)"
5821

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, )"
6123

6224
lintr::expect_lint(good_package_commas, NULL, linter)
6325
lintr::expect_lint(good_package_commas_inline, NULL, linter)
@@ -68,33 +30,76 @@ test_that("box_trailing_commas_linter skips allowed package import usage", {
6830
test_that("box_trailing_commas_linter blocks no trailing commas in package imports", {
6931
linter <- box_trailing_commas_linter()
7032

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+
7142
lintr::expect_lint(bad_package_commas, list(message = paren_lint_msg), linter)
7243
lintr::expect_lint(bad_package_commas_inline, list(message = paren_lint_msg), linter)
7344
})
7445

7546
test_that("box_trailing_commas_linter check_functions = TRUE blocks no trailing commas", {
7647
linter <- box_trailing_commas_linter(check_functions = TRUE)
7748

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+
7861
lintr::expect_lint(bad_package_function_commas, list(message = bracket_lint_msg), linter)
7962
lintr::expect_lint(bad_pkg_function_commas_inline, list(message = bracket_lint_msg), linter)
8063
})
8164

8265
test_that("box_trailing_comma_linter blocks no trailing commas in module imports", {
8366
linter <- box_trailing_commas_linter()
8467

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+
8577
lintr::expect_lint(bad_module_commas, list(message = paren_lint_msg), linter)
8678
lintr::expect_lint(bad_module_commas_inline, list(message = paren_lint_msg), linter)
8779
})
8880

8981
test_that("box_trailing_commas_linter check_functions = TRUE blocks no trailing commas", {
9082
linter <- box_trailing_commas_linter(check_functions = TRUE)
9183

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+
9295
lintr::expect_lint(bad_module_function_commas, list(message = bracket_lint_msg), linter)
9396
lintr::expect_lint(bad_mod_function_commas_inline, list(message = bracket_lint_msg), linter)
9497
})
9598

9699
test_that("box_trailing_commas_linter should not lint outside of `box::use()`", {
97100
linter <- box_trailing_commas_linter()
98101

102+
should_not_lint <- "x <- c(1, 2, 3)"
103+
99104
lintr::expect_lint(should_not_lint, NULL, linter)
100105
})

0 commit comments

Comments
 (0)