From e2e7400d04cff71719396ff5887f3e251f410978 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 12 Jan 2024 17:20:06 +0800 Subject: [PATCH 01/14] add box calls separate packages and modules --- R/linter_box_separate_packages_modules.R | 52 +++++++++++++++++++ ...est-linter_box_separate_packages_modules.R | 34 ++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 R/linter_box_separate_packages_modules.R create mode 100644 tests/testthat/test-linter_box_separate_packages_modules.R diff --git a/R/linter_box_separate_packages_modules.R b/R/linter_box_separate_packages_modules.R new file mode 100644 index 00000000..94f818bb --- /dev/null +++ b/R/linter_box_separate_packages_modules.R @@ -0,0 +1,52 @@ +#' Box library separate packages and module imports linter +#' +#' Checks that packages and modules are imported in separate `box::use()` statements. +#' +#' @examples +#' # will produce lints +#' lintr::lint( +#' text = "box::use(package, path/to/file)", +#' linters = box_separate_calls_linter() +#' ) +#' +#' lintr::lint( +#' text = "box::use(path/to/file, package)", +#' linters = box_separate_calls_linter() +#' ) +#' +#' # okay +#' lintr::lint( +#' text = "box::use(package1, package2) +#' box::use(path/to/file1, path/to/file2)", +#' linters = box_separate_calls_linter() +#' ) +#' +#' @export +box_separate_calls_linter <- function() { + xpath <- " +//SYMBOL_PACKAGE[(text() = 'box' and following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])] +/parent::expr +/parent::expr[ + ./child::expr[child::SYMBOL] and + ./child::expr[child::expr[child::OP-SLASH]] +] +" + lint_message <- "Separate packages and modules in their respective box::use() calls." + + lintr::Linter(function(source_expression) { + if (!lintr::is_lint_level(source_expression, "file")) { + return(list()) + } + + xml <- source_expression$full_xml_parsed_content + + bad_expr <- xml2::xml_find_all(xml, xpath) + + lintr::xml_nodes_to_lints( + bad_expr, + source_expression = source_expression, + lint_message = lint_message, + type = "style" + ) + }) +} diff --git a/tests/testthat/test-linter_box_separate_packages_modules.R b/tests/testthat/test-linter_box_separate_packages_modules.R new file mode 100644 index 00000000..77494d6b --- /dev/null +++ b/tests/testthat/test-linter_box_separate_packages_modules.R @@ -0,0 +1,34 @@ +good_box_calls <- "box::use( + dplyr, + shiny, +) + +box::use( + path/to/file1, + path/to/file2, +)" + +bad_box_call_1 <- "box::use( + dplyr, + path/to/file, +)" + +bad_box_call_2 <- "box::use( + path/to/file, + dplyr, +)" + +lint_message <- rex::rex("Separate packages and modules in their respective box::use() calls.") + +test_that("box_separate_calls_linter skips allowed box::use() calls", { + linter <- box_separate_calls_linter() + + lintr::expect_lint(good_box_calls, NULL, linter) +}) + +test_that("box_separate_calls_linter blocks packages and modules in same box::use() call", { + linter <- box_separate_calls_linter() + + lintr::expect_lint(bad_box_call_1, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_2, list(message = lint_message), linter) +}) From a23412e33243a7abe2d3eda055bea911245be038 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 12 Jan 2024 17:20:36 +0800 Subject: [PATCH 02/14] documentation --- NAMESPACE | 1 + man/box_separate_calls_linter.Rd | 31 +++++++++++++++++++++++++++++++ pkgdown/_pkgdown.yml | 4 ++++ 3 files changed, 36 insertions(+) create mode 100644 man/box_separate_calls_linter.Rd diff --git a/NAMESPACE b/NAMESPACE index 2b25b2d5..112dbf02 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,7 @@ # Generated by roxygen2: do not edit by hand export(app) +export(box_separate_calls_linter) export(build_js) export(build_sass) export(diagnostics) diff --git a/man/box_separate_calls_linter.Rd b/man/box_separate_calls_linter.Rd new file mode 100644 index 00000000..f451d27a --- /dev/null +++ b/man/box_separate_calls_linter.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/linter_box_separate_packages_modules.R +\name{box_separate_calls_linter} +\alias{box_separate_calls_linter} +\title{Box library separate packages and module imports linter} +\usage{ +box_separate_calls_linter() +} +\description{ +Checks that packages and modules are imported in separate \code{box::use()} statements. +} +\examples{ +# will produce lints +lintr::lint( + text = "box::use(package, path/to/file)", + linters = box_separate_calls_linter() +) + +lintr::lint( + text = "box::use(path/to/file, package)", + linters = box_separate_calls_linter() +) + +# okay +lintr::lint( + text = "box::use(package1, package2) + box::use(path/to/file1, path/to/file2)", + linters = box_separate_calls_linter() +) + +} diff --git a/pkgdown/_pkgdown.yml b/pkgdown/_pkgdown.yml index 759c93d4..c4a5a782 100644 --- a/pkgdown/_pkgdown.yml +++ b/pkgdown/_pkgdown.yml @@ -143,6 +143,10 @@ reference: - diagnostics - test_e2e +- title: Linters + contents: + - box_separate_calls_linter + - title: Data contents: - rhinos From 442d96f4774a2540a516b0cf2ced8362aa0d1d9d Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 12 Jan 2024 17:21:05 +0800 Subject: [PATCH 03/14] packge update --- DESCRIPTION | 6 ++++-- inst/templates/app_structure/dot.lintr | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f399da4f..633e73b3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rhino Title: A Framework for Enterprise Shiny Applications -Version: 1.7.0.9000 +Version: 1.7.0.9004 Authors@R: c( person("Kamil", "Żyła", role = c("aut", "cre"), email = "opensource+kamil@appsilon.com"), @@ -44,9 +44,11 @@ Suggests: knitr, mockery, rcmdcheck, + rex, rmarkdown, shiny.react, - spelling + spelling, + xml2 LazyData: true Config/testthat/edition: 3 Config/testthat/parallel: true diff --git a/inst/templates/app_structure/dot.lintr b/inst/templates/app_structure/dot.lintr index 63fade9a..3111a35a 100644 --- a/inst/templates/app_structure/dot.lintr +++ b/inst/templates/app_structure/dot.lintr @@ -1,5 +1,6 @@ linters: linters_with_defaults( line_length_linter = line_length_linter(100), + box_separate_calls_linter = rhino::box_separate_calls_linter(), object_usage_linter = NULL # Does not work with `box::use()`. ) From df3e02d12034302dacfadd1c73975568bfaadd94 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 12 Jan 2024 17:22:08 +0800 Subject: [PATCH 04/14] remove lint --- R/linter_box_separate_packages_modules.R | 8 ++++---- .../testthat/test-linter_box_separate_packages_modules.R | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/linter_box_separate_packages_modules.R b/R/linter_box_separate_packages_modules.R index 94f818bb..b25ee875 100644 --- a/R/linter_box_separate_packages_modules.R +++ b/R/linter_box_separate_packages_modules.R @@ -1,7 +1,7 @@ #' Box library separate packages and module imports linter -#' +#' #' Checks that packages and modules are imported in separate `box::use()` statements. -#' +#' #' @examples #' # will produce lints #' lintr::lint( @@ -13,7 +13,7 @@ #' text = "box::use(path/to/file, package)", #' linters = box_separate_calls_linter() #' ) -#' +#' #' # okay #' lintr::lint( #' text = "box::use(package1, package2) @@ -32,7 +32,7 @@ box_separate_calls_linter <- function() { ] " lint_message <- "Separate packages and modules in their respective box::use() calls." - + lintr::Linter(function(source_expression) { if (!lintr::is_lint_level(source_expression, "file")) { return(list()) diff --git a/tests/testthat/test-linter_box_separate_packages_modules.R b/tests/testthat/test-linter_box_separate_packages_modules.R index 77494d6b..d9302ca4 100644 --- a/tests/testthat/test-linter_box_separate_packages_modules.R +++ b/tests/testthat/test-linter_box_separate_packages_modules.R @@ -22,13 +22,13 @@ lint_message <- rex::rex("Separate packages and modules in their respective box: test_that("box_separate_calls_linter skips allowed box::use() calls", { linter <- box_separate_calls_linter() - + lintr::expect_lint(good_box_calls, NULL, linter) }) test_that("box_separate_calls_linter blocks packages and modules in same box::use() call", { linter <- box_separate_calls_linter() - + lintr::expect_lint(bad_box_call_1, list(message = lint_message), linter) lintr::expect_lint(bad_box_call_2, list(message = lint_message), linter) }) From 86c413b1959a64433891d775454a291b7668c6e5 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 26 Jan 2024 13:58:27 +0800 Subject: [PATCH 05/14] duplicate xml2 in suggests --- DESCRIPTION | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index deb3e7c7..d8efdb29 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,8 +48,7 @@ Suggests: rex, rmarkdown, shiny.react, - spelling, - xml2 + spelling LazyData: true Config/testthat/edition: 3 Config/testthat/parallel: true From 367103f81322fa4826357c9068ea27a801bdc53c Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 26 Jan 2024 14:06:31 +0800 Subject: [PATCH 06/14] integrate new linter --- R/box_linters.R | 53 +++++++++++++++++++ R/linter_box_separate_packages_modules.R | 52 ------------------ man/box_separate_calls_linter.Rd | 2 +- ...> test-linter_box_separate_calls_linter.R} | 44 +++++++-------- 4 files changed, 76 insertions(+), 75 deletions(-) rename tests/testthat/{test-linter_box_separate_packages_modules.R => test-linter_box_separate_calls_linter.R} (57%) diff --git a/R/box_linters.R b/R/box_linters.R index f0ba769c..fb92fcb6 100644 --- a/R/box_linters.R +++ b/R/box_linters.R @@ -1,3 +1,56 @@ +#' Box library separate packages and module imports linter +#' +#' Checks that packages and modules are imported in separate `box::use()` statements. +#' +#' @examples +#' # will produce lints +#' lintr::lint( +#' text = "box::use(package, path/to/file)", +#' linters = box_separate_calls_linter() +#' ) +#' +#' lintr::lint( +#' text = "box::use(path/to/file, package)", +#' linters = box_separate_calls_linter() +#' ) +#' +#' # okay +#' lintr::lint( +#' text = "box::use(package1, package2) +#' box::use(path/to/file1, path/to/file2)", +#' linters = box_separate_calls_linter() +#' ) +#' +#' @export +box_separate_calls_linter <- function() { + xpath <- " + //SYMBOL_PACKAGE[(text() = 'box' and following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])] + /parent::expr + /parent::expr[ + ./child::expr[child::SYMBOL] and + ./child::expr[child::expr[child::OP-SLASH]] + ] + " + lint_message <- "Separate packages and modules in their respective box::use() calls." + + lintr::Linter(function(source_expression) { + if (!lintr::is_lint_level(source_expression, "file")) { + return(list()) + } + + xml <- source_expression$full_xml_parsed_content + + bad_expr <- xml2::xml_find_all(xml, xpath) + + lintr::xml_nodes_to_lints( + bad_expr, + source_expression = source_expression, + lint_message = lint_message, + type = "style" + ) + }) +} + #' Box library universal import linter #' #' Checks that all function imports are explicit. `package[...]` is not used. diff --git a/R/linter_box_separate_packages_modules.R b/R/linter_box_separate_packages_modules.R index b25ee875..e69de29b 100644 --- a/R/linter_box_separate_packages_modules.R +++ b/R/linter_box_separate_packages_modules.R @@ -1,52 +0,0 @@ -#' Box library separate packages and module imports linter -#' -#' Checks that packages and modules are imported in separate `box::use()` statements. -#' -#' @examples -#' # will produce lints -#' lintr::lint( -#' text = "box::use(package, path/to/file)", -#' linters = box_separate_calls_linter() -#' ) -#' -#' lintr::lint( -#' text = "box::use(path/to/file, package)", -#' linters = box_separate_calls_linter() -#' ) -#' -#' # okay -#' lintr::lint( -#' text = "box::use(package1, package2) -#' box::use(path/to/file1, path/to/file2)", -#' linters = box_separate_calls_linter() -#' ) -#' -#' @export -box_separate_calls_linter <- function() { - xpath <- " -//SYMBOL_PACKAGE[(text() = 'box' and following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])] -/parent::expr -/parent::expr[ - ./child::expr[child::SYMBOL] and - ./child::expr[child::expr[child::OP-SLASH]] -] -" - lint_message <- "Separate packages and modules in their respective box::use() calls." - - lintr::Linter(function(source_expression) { - if (!lintr::is_lint_level(source_expression, "file")) { - return(list()) - } - - xml <- source_expression$full_xml_parsed_content - - bad_expr <- xml2::xml_find_all(xml, xpath) - - lintr::xml_nodes_to_lints( - bad_expr, - source_expression = source_expression, - lint_message = lint_message, - type = "style" - ) - }) -} diff --git a/man/box_separate_calls_linter.Rd b/man/box_separate_calls_linter.Rd index f451d27a..a1ec3f89 100644 --- a/man/box_separate_calls_linter.Rd +++ b/man/box_separate_calls_linter.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/linter_box_separate_packages_modules.R +% Please edit documentation in R/box_linters.R \name{box_separate_calls_linter} \alias{box_separate_calls_linter} \title{Box library separate packages and module imports linter} diff --git a/tests/testthat/test-linter_box_separate_packages_modules.R b/tests/testthat/test-linter_box_separate_calls_linter.R similarity index 57% rename from tests/testthat/test-linter_box_separate_packages_modules.R rename to tests/testthat/test-linter_box_separate_calls_linter.R index d9302ca4..68467df9 100644 --- a/tests/testthat/test-linter_box_separate_packages_modules.R +++ b/tests/testthat/test-linter_box_separate_calls_linter.R @@ -1,34 +1,34 @@ -good_box_calls <- "box::use( - dplyr, - shiny, -) - -box::use( - path/to/file1, - path/to/file2, -)" - -bad_box_call_1 <- "box::use( - dplyr, - path/to/file, -)" - -bad_box_call_2 <- "box::use( - path/to/file, - dplyr, -)" - -lint_message <- rex::rex("Separate packages and modules in their respective box::use() calls.") - test_that("box_separate_calls_linter skips allowed box::use() calls", { linter <- box_separate_calls_linter() + good_box_calls <- "box::use( + dplyr, + shiny, + ) + + box::use( + path/to/file1, + path/to/file2, + )" + lintr::expect_lint(good_box_calls, NULL, linter) }) test_that("box_separate_calls_linter blocks packages and modules in same box::use() call", { linter <- box_separate_calls_linter() + bad_box_call_1 <- "box::use( + dplyr, + path/to/file, + )" + + bad_box_call_2 <- "box::use( + path/to/file, + dplyr, + )" + + lint_message <- rex::rex("Separate packages and modules in their respective box::use() calls.") + lintr::expect_lint(bad_box_call_1, list(message = lint_message), linter) lintr::expect_lint(bad_box_call_2, list(message = lint_message), linter) }) From 0c0e6f6e2dc02c167741406dc0451244bdf171bf Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 26 Jan 2024 14:08:50 +0800 Subject: [PATCH 07/14] forgot the roxygen return --- R/box_linters.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/box_linters.R b/R/box_linters.R index fb92fcb6..5781cd98 100644 --- a/R/box_linters.R +++ b/R/box_linters.R @@ -2,6 +2,8 @@ #' #' Checks that packages and modules are imported in separate `box::use()` statements. #' +#' @return A custom linter function for use with `r-lib/lintr` +#' #' @examples #' # will produce lints #' lintr::lint( From 7d6fe721a659ece9d3fbfc1e09cebd6e3e7a51fd Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Fri, 26 Jan 2024 14:24:55 +0800 Subject: [PATCH 08/14] forgot to clean up a merge conflict marker --- inst/templates/app_structure/dot.lintr | 1 - 1 file changed, 1 deletion(-) diff --git a/inst/templates/app_structure/dot.lintr b/inst/templates/app_structure/dot.lintr index e00831bc..38b2a30b 100644 --- a/inst/templates/app_structure/dot.lintr +++ b/inst/templates/app_structure/dot.lintr @@ -3,6 +3,5 @@ linters: line_length_linter = line_length_linter(100), box_separate_calls_linter = rhino::box_separate_calls_linter(), box_universal_import_linter = rhino::box_universal_import_linter(), ->>>>>>> dev_next object_usage_linter = NULL # Does not work with `box::use()`. ) From 076ad64906a8f5a8d7f8ad743a3598b7742d2bc4 Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Tue, 20 Feb 2024 15:07:13 +0100 Subject: [PATCH 09/14] chore: Minor documentation changes. --- R/box_linters.R | 2 +- man/box_separate_calls_linter.Rd | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/box_linters.R b/R/box_linters.R index fb44d537..b690edb6 100644 --- a/R/box_linters.R +++ b/R/box_linters.R @@ -67,7 +67,7 @@ box_func_import_count_linter <- function(max = 8L) { }) } -#' Box library separate packages and module imports linter +#' `box` library separate packages and module imports linter #' #' Checks that packages and modules are imported in separate `box::use()` statements. #' diff --git a/man/box_separate_calls_linter.Rd b/man/box_separate_calls_linter.Rd index a1ec3f89..50a53549 100644 --- a/man/box_separate_calls_linter.Rd +++ b/man/box_separate_calls_linter.Rd @@ -2,10 +2,13 @@ % Please edit documentation in R/box_linters.R \name{box_separate_calls_linter} \alias{box_separate_calls_linter} -\title{Box library separate packages and module imports linter} +\title{\code{box} library separate packages and module imports linter} \usage{ box_separate_calls_linter() } +\value{ +A custom linter function for use with \code{r-lib/lintr} +} \description{ Checks that packages and modules are imported in separate \code{box::use()} statements. } From 6eacf05830b5d0db010e7d340342a173ed0958ee Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Tue, 20 Feb 2024 15:12:37 +0100 Subject: [PATCH 10/14] test: Additional tests for problematic cases. --- .../test-linter_box_separate_calls_linter.R | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-linter_box_separate_calls_linter.R b/tests/testthat/test-linter_box_separate_calls_linter.R index 68467df9..d1163ca8 100644 --- a/tests/testthat/test-linter_box_separate_calls_linter.R +++ b/tests/testthat/test-linter_box_separate_calls_linter.R @@ -1,7 +1,7 @@ test_that("box_separate_calls_linter skips allowed box::use() calls", { linter <- box_separate_calls_linter() - good_box_calls <- "box::use( + good_box_calls_1 <- "box::use( dplyr, shiny, ) @@ -11,7 +11,18 @@ test_that("box_separate_calls_linter skips allowed box::use() calls", { path/to/file2, )" - lintr::expect_lint(good_box_calls, NULL, linter) + good_box_calls_2 <- "box::use( + dplyr[filter, select], + shiny, + ) + + box::use( + path/to/file1[function1, function2], + path/to/file2, + )" + + lintr::expect_lint(good_box_calls_1, NULL, linter) + lintr::expect_lint(good_box_calls_2, NULL, linter) }) test_that("box_separate_calls_linter blocks packages and modules in same box::use() call", { @@ -27,8 +38,26 @@ test_that("box_separate_calls_linter blocks packages and modules in same box::us dplyr, )" + bad_box_call_3 <- "box::use( + path/to/file, + dplyr[filter, select], + )" + + bad_box_call_4 <- "box::use( + path/to/file[function1, function2], + dplyr, + )" + + bad_box_call_5 <- "box::use( + path/to/file[function1, function2], + dplyr[filter, select], + )" + lint_message <- rex::rex("Separate packages and modules in their respective box::use() calls.") lintr::expect_lint(bad_box_call_1, list(message = lint_message), linter) lintr::expect_lint(bad_box_call_2, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_3, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_4, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_5, list(message = lint_message), linter) }) From f814e2e208bd218450cb77954dbe768c71aa1a7c Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 21 Feb 2024 12:51:39 +0800 Subject: [PATCH 11/14] box function import has a slightly different pattern from full package import --- R/box_linters.R | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/R/box_linters.R b/R/box_linters.R index b690edb6..e452a39c 100644 --- a/R/box_linters.R +++ b/R/box_linters.R @@ -98,7 +98,12 @@ box_separate_calls_linter <- function() { //SYMBOL_PACKAGE[(text() = 'box' and following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])] /parent::expr /parent::expr[ - ./child::expr[child::SYMBOL] and + ( + ./child::expr[child::SYMBOL] or + ./child::expr[ + child::expr[child::SYMBOL] and child::OP-LEFT-BRACKET + ] + ) and ./child::expr[child::expr[child::OP-SLASH]] ] " From cdc3f40a4c0f91c489b3be4677286ac0d1d720dd Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 21 Feb 2024 12:52:23 +0800 Subject: [PATCH 12/14] added tests for package/module and function aliases for separate calls linter --- .../test-linter_box_separate_calls_linter.R | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/testthat/test-linter_box_separate_calls_linter.R b/tests/testthat/test-linter_box_separate_calls_linter.R index d1163ca8..a8219062 100644 --- a/tests/testthat/test-linter_box_separate_calls_linter.R +++ b/tests/testthat/test-linter_box_separate_calls_linter.R @@ -53,6 +53,26 @@ test_that("box_separate_calls_linter blocks packages and modules in same box::us dplyr[filter, select], )" + bad_box_call_6 <- "box::use( + a = path/to/file, + dplyr, + )" + + bad_box_call_7 <- "box::use( + path/to/file, + a = dplyr, + )" + + bad_box_call_8 <- "box::use( + path/to/file, + dplyr[a = filter, select], + )" + + bad_box_call_9 <- "box::use( + path/to/file[a = function1, function2], + dplyr, + )" + lint_message <- rex::rex("Separate packages and modules in their respective box::use() calls.") lintr::expect_lint(bad_box_call_1, list(message = lint_message), linter) @@ -60,4 +80,8 @@ test_that("box_separate_calls_linter blocks packages and modules in same box::us lintr::expect_lint(bad_box_call_3, list(message = lint_message), linter) lintr::expect_lint(bad_box_call_4, list(message = lint_message), linter) lintr::expect_lint(bad_box_call_5, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_6, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_7, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_8, list(message = lint_message), linter) + lintr::expect_lint(bad_box_call_9, list(message = lint_message), linter) }) From d9fb6338098851c5170658b79fe4a6fde4d55e07 Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Wed, 21 Feb 2024 12:53:18 +0800 Subject: [PATCH 13/14] removed empty file --- R/linter_box_separate_packages_modules.R | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 R/linter_box_separate_packages_modules.R diff --git a/R/linter_box_separate_packages_modules.R b/R/linter_box_separate_packages_modules.R deleted file mode 100644 index e69de29b..00000000 From 3a30d827fdc8f8237ba81ea8a512da7e80fb4974 Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Wed, 21 Feb 2024 08:47:34 +0100 Subject: [PATCH 14/14] chore: Update NEWS and add links to the styel guide in the documentation. --- NEWS.md | 1 + R/box_linters.R | 16 ++++++++++++++++ man/box_func_import_count_linter.Rd | 2 ++ man/box_separate_calls_linter.Rd | 2 ++ man/box_trailing_commas_linter.Rd | 2 ++ man/box_universal_import_linter.Rd | 2 ++ 6 files changed, 25 insertions(+) diff --git a/NEWS.md b/NEWS.md index 777196d9..37395212 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ * `box_universal_import_linter` checks if all imports are explicit. * `box_trailing_commas_linter` checks if statements include trailing commas. * `box_func_import_count_linter` checks if the number of function imports does not exceed the limit. + * `box_separate_calls_linter` checks if packages and modules are imported in separate statements. 2. Major refactor of `rhino::app()`: * The `request` parameter is now correctly forwarded to the UI function when using a `legacy_entrypoint` ([#395](https://github.com/Appsilon/rhino/issues/395)). diff --git a/R/box_linters.R b/R/box_linters.R index e452a39c..f2e70134 100644 --- a/R/box_linters.R +++ b/R/box_linters.R @@ -1,6 +1,9 @@ +# nolint start: line_length_linter #' `box` library function import count linter #' #' Checks that function imports do not exceed the defined `max`. +#' See the [Explanation: Rhino style guide](https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html) +#' to learn about the details. #' #' @param max Maximum function imports allowed between `[` and `]`. Defaults to 8. #' @@ -30,6 +33,7 @@ #' ) #' #' @export +# nolint end box_func_import_count_linter <- function(max = 8L) { xpath <- glue::glue("//SYMBOL_PACKAGE[ (text() = 'box' and @@ -67,9 +71,12 @@ box_func_import_count_linter <- function(max = 8L) { }) } +# nolint start: line_length_linter #' `box` library separate packages and module imports linter #' #' Checks that packages and modules are imported in separate `box::use()` statements. +#' See the [Explanation: Rhino style guide](https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html) +#' to learn about the details. #' #' @return A custom linter function for use with `r-lib/lintr` #' @@ -93,6 +100,7 @@ box_func_import_count_linter <- function(max = 8L) { #' ) #' #' @export +# nolint end box_separate_calls_linter <- function() { xpath <- " //SYMBOL_PACKAGE[(text() = 'box' and following-sibling::SYMBOL_FUNCTION_CALL[text() = 'use'])] @@ -127,11 +135,14 @@ box_separate_calls_linter <- function() { }) } +# nolint start: line_length_linter #' `box` library trailing commas linter #' #' Checks that all `box:use` imports have a trailing comma. This applies to #' package or module imports between `(` and `)`, and, optionally, function imports between #' `[` and `]`. Take note that `lintr::commas_linter()` may come into play. +#' See the [Explanation: Rhino style guide](https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html) +#' to learn about the details. #' #' @param check_functions Boolean flag to include function imports between `[` and `]`. #' Defaults to FALSE. @@ -166,6 +177,7 @@ box_separate_calls_linter <- function() { #' ) #' #' @export +# nolint end box_trailing_commas_linter <- function(check_functions = FALSE) { base_xpath <- "//SYMBOL_PACKAGE[ ( @@ -230,9 +242,12 @@ box_trailing_commas_linter <- function(check_functions = FALSE) { }) } +# nolint start: line_length_linter #' `box` library universal import linter #' #' Checks that all function imports are explicit. `package[...]` is not used. +#' See the [Explanation: Rhino style guide](https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html) +#' to learn about the details. #' #' @return A custom linter function for use with `r-lib/lintr` #' @@ -260,6 +275,7 @@ box_trailing_commas_linter <- function(check_functions = FALSE) { #' ) #' #' @export +# nolint end box_universal_import_linter <- function() { lint_message <- "Explicitly declare imports rather than universally import with `...`." diff --git a/man/box_func_import_count_linter.Rd b/man/box_func_import_count_linter.Rd index 1960ce5a..50d04d1e 100644 --- a/man/box_func_import_count_linter.Rd +++ b/man/box_func_import_count_linter.Rd @@ -14,6 +14,8 @@ A custom linter function for use with \code{r-lib/lintr}. } \description{ Checks that function imports do not exceed the defined \code{max}. +See the \href{https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html}{Explanation: Rhino style guide} +to learn about the details. } \examples{ # will produce lints diff --git a/man/box_separate_calls_linter.Rd b/man/box_separate_calls_linter.Rd index 50a53549..725ec8f5 100644 --- a/man/box_separate_calls_linter.Rd +++ b/man/box_separate_calls_linter.Rd @@ -11,6 +11,8 @@ A custom linter function for use with \code{r-lib/lintr} } \description{ Checks that packages and modules are imported in separate \code{box::use()} statements. +See the \href{https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html}{Explanation: Rhino style guide} +to learn about the details. } \examples{ # will produce lints diff --git a/man/box_trailing_commas_linter.Rd b/man/box_trailing_commas_linter.Rd index b2d75892..a804bff8 100644 --- a/man/box_trailing_commas_linter.Rd +++ b/man/box_trailing_commas_linter.Rd @@ -17,6 +17,8 @@ A custom linter function for use with \code{r-lib/lintr} Checks that all \code{box:use} imports have a trailing comma. This applies to package or module imports between \code{(} and \verb{)}, and, optionally, function imports between \code{[} and \verb{]}. Take note that \code{lintr::commas_linter()} may come into play. +See the \href{https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html}{Explanation: Rhino style guide} +to learn about the details. } \examples{ # will produce lints diff --git a/man/box_universal_import_linter.Rd b/man/box_universal_import_linter.Rd index ce83b851..f57d0aed 100644 --- a/man/box_universal_import_linter.Rd +++ b/man/box_universal_import_linter.Rd @@ -11,6 +11,8 @@ A custom linter function for use with \code{r-lib/lintr} } \description{ Checks that all function imports are explicit. \code{package[...]} is not used. +See the \href{https://appsilon.github.io/rhino/articles/explanation/rhino-style-guide.html}{Explanation: Rhino style guide} +to learn about the details. } \examples{ # will produce lints