-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #535 from Appsilon/feature/box_trailing_commas_linter
Box trailing commas linter
- Loading branch information
Showing
11 changed files
with
265 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: rhino | ||
Title: A Framework for Enterprise Shiny Applications | ||
Version: 1.6.0.9001 | ||
Version: 1.6.0.9002 | ||
Authors@R: | ||
c( | ||
person("Kamil", "Żyła", role = c("aut", "cre"), email = "[email protected]"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
linters: | ||
linters_with_defaults( | ||
line_length_linter = line_length_linter(100), | ||
box_trailing_commas_linter = rhino::box_trailing_commas_linter(), | ||
box_universal_import_linter = rhino::box_universal_import_linter(), | ||
object_usage_linter = NULL # Does not work with `box::use()`. | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
tests/testthat/test-linter_box_trailing_commas_linter.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
test_that("box_trailing_commas_linter skips allowed package import usage", { | ||
linter <- box_trailing_commas_linter() | ||
|
||
good_package_commas <- "box::use( | ||
dplyr, | ||
stringr[ | ||
select, | ||
mutate | ||
], | ||
)" | ||
|
||
good_package_commas_inline <- "box::use(dplyr, stringr[select, mutate], )" | ||
|
||
good_module_commas <- "box::use( | ||
path/to/file1, | ||
path/to/file2[ | ||
first_function, | ||
second_function | ||
], | ||
)" | ||
|
||
good_module_commas_inline <- "box::use(path/to/file1, path/to/file2, )" | ||
|
||
lintr::expect_lint(good_package_commas, NULL, linter) | ||
lintr::expect_lint(good_package_commas_inline, NULL, linter) | ||
lintr::expect_lint(good_module_commas, NULL, linter) | ||
lintr::expect_lint(good_module_commas_inline, NULL, linter) | ||
}) | ||
|
||
test_that("box_trailing_commas_linter blocks no trailing commas in package imports", { | ||
linter <- box_trailing_commas_linter() | ||
|
||
bad_package_commas <- "box::use( | ||
dplyr, | ||
stringr | ||
)" | ||
|
||
bad_package_commas_inline <- "box::use(dplyr, stringr)" | ||
|
||
paren_lint_msg <- rex::rex("Always have a trailing comma at the end of imports, before a `)`.") | ||
|
||
lintr::expect_lint(bad_package_commas, list(message = paren_lint_msg), linter) | ||
lintr::expect_lint(bad_package_commas_inline, list(message = paren_lint_msg), linter) | ||
}) | ||
|
||
test_that("box_trailing_commas_linter check_functions = TRUE blocks no trailing commas", { | ||
linter <- box_trailing_commas_linter(check_functions = TRUE) | ||
|
||
bracket_lint_msg <- rex::rex("Always have a trailing comma at the end of imports, before a `]`.") | ||
|
||
bad_package_function_commas <- "box::use( | ||
dplyr, | ||
stringr[ | ||
select, | ||
mutate | ||
], | ||
)" | ||
|
||
bad_pkg_function_commas_inline <- "box::use(stringr[select, mutate],)" | ||
|
||
lintr::expect_lint(bad_package_function_commas, list(message = bracket_lint_msg), linter) | ||
lintr::expect_lint(bad_pkg_function_commas_inline, list(message = bracket_lint_msg), linter) | ||
}) | ||
|
||
test_that("box_trailing_comma_linter blocks no trailing commas in module imports", { | ||
linter <- box_trailing_commas_linter() | ||
|
||
bad_module_commas <- "box::use( | ||
path/to/file1, | ||
path/to/file2 | ||
)" | ||
|
||
bad_module_commas_inline <- "box::use(path/to/file1, path/to/file2)" | ||
|
||
paren_lint_msg <- rex::rex("Always have a trailing comma at the end of imports, before a `)`.") | ||
|
||
lintr::expect_lint(bad_module_commas, list(message = paren_lint_msg), linter) | ||
lintr::expect_lint(bad_module_commas_inline, list(message = paren_lint_msg), linter) | ||
}) | ||
|
||
test_that("box_trailing_commas_linter check_functions = TRUE blocks no trailing commas", { | ||
linter <- box_trailing_commas_linter(check_functions = TRUE) | ||
|
||
bad_module_function_commas <- "box::use( | ||
path/to/file2[ | ||
first_function, | ||
second_function | ||
], | ||
)" | ||
|
||
bad_mod_function_commas_inline <- "box::use(path/to/file2[first_function, second_function], )" | ||
|
||
bracket_lint_msg <- rex::rex("Always have a trailing comma at the end of imports, before a `]`.") | ||
|
||
lintr::expect_lint(bad_module_function_commas, list(message = bracket_lint_msg), linter) | ||
lintr::expect_lint(bad_mod_function_commas_inline, list(message = bracket_lint_msg), linter) | ||
}) | ||
|
||
test_that("box_trailing_commas_linter should not lint outside of `box::use()`", { | ||
linter <- box_trailing_commas_linter() | ||
|
||
should_not_lint <- "x <- c(1, 2, 3)" | ||
|
||
lintr::expect_lint(should_not_lint, NULL, linter) | ||
}) |