From 976d3ac80e3ba3b9d3657747df8583cb92b7a93c Mon Sep 17 00:00:00 2001 From: Rodrigo Basa Date: Thu, 11 Jan 2024 14:56:56 +0800 Subject: [PATCH] remove lint --- R/linter_box_trailing_commas_linter.R | 30 +++++++++---------- .../test-linter_box_trailing_commas_linter.R | 20 ++++++------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/R/linter_box_trailing_commas_linter.R b/R/linter_box_trailing_commas_linter.R index 3c129187..793aba7e 100644 --- a/R/linter_box_trailing_commas_linter.R +++ b/R/linter_box_trailing_commas_linter.R @@ -3,34 +3,34 @@ #' Checks that all `box:use` imports have a trailing comma. This applies to #' package or module imports between `(` and `)`, and function imports between #' `[` and `]`. Take note that `lintr::commas_linter()` may come into play. -#' +#' #' @examples #' # will produce lints #' lintr::lint( #' text = "box::use(base, rlang)", #' linters = box_trailing_commas_linter() #' ) -#' +#' #' lintr::lint( #' text = "box::use( #' dplyr[select, mutate], #' ), #' linters = box_trailing_commas_linter() #' ) -#' +#' #' # okay #' linter::lint( #' text = "box::use(base, rlang,), #' linters = box_trailing_commas_linter() #' ) -#' +#' #' linter::lint( #' text = "box::use( #' dplyr[select, mutate,], #' ), #' linters = box_trailing_commas_linter() #' ) -#' +#' #' @export box_trailing_commas_linter <- function() { base_xpath <- "//SYMBOL_PACKAGE[ @@ -41,7 +41,7 @@ box_trailing_commas_linter <- function() { ] /parent::expr " - + right_paren_xpath <- paste( base_xpath, "/following-sibling::OP-RIGHT-PAREN[ @@ -49,8 +49,8 @@ box_trailing_commas_linter <- function() { ] " ) - - right_bracket_xpath <-paste( + + right_bracket_xpath <- paste( base_xpath, "/parent::expr /descendant::OP-RIGHT-BRACKET[ @@ -63,31 +63,31 @@ box_trailing_commas_linter <- function() { ] " ) - + lintr::Linter(function(source_expression) { if (!lintr::is_lint_level(source_expression, "file")) { return(list()) } - + xml <- source_expression$full_xml_parsed_content - + bad_right_paren_expr <- xml2::xml_find_all(xml, right_paren_xpath) bad_right_bracket_expr <- xml2::xml_find_all(xml, right_bracket_xpath) - + paren_lints <- lintr::xml_nodes_to_lints( bad_right_paren_expr, source_expression = source_expression, lint_message = "Always have a trailing comma at the end of imports, before a `)`.", type = "style" ) - + bracket_lints <- lintr::xml_nodes_to_lints( bad_right_bracket_expr, source_expression = source_expression, lint_message = "Always have a trailing comma at the end of imports, before a `]`.", type = "style" ) - + c(paren_lints, bracket_lints) }) -} \ No newline at end of file +} diff --git a/tests/testthat/test-linter_box_trailing_commas_linter.R b/tests/testthat/test-linter_box_trailing_commas_linter.R index 33ee9870..e8499523 100644 --- a/tests/testthat/test-linter_box_trailing_commas_linter.R +++ b/tests/testthat/test-linter_box_trailing_commas_linter.R @@ -33,7 +33,7 @@ bad_package_function_commas <- "box::use( ], )" -bad_package_function_commas_inline <- "box::use(stringr[select, mutate],)" +bad_pkg_function_commas_inline <- "box::use(stringr[select, mutate],)" bad_module_commas <- "box::use( path/to/file1, @@ -51,14 +51,14 @@ bad_module_function_commas <- "box::use( should_not_lint <- "x <- c(1, 2, 3)" -bad_module_function_commas_inline <- "box::use(path/to/file2[first_function, second_function], )" +bad_mod_function_commas_inline <- "box::use(path/to/file2[first_function, second_function], )" paren_lint_msg <- rex::rex("Always have a trailing comma at the end of imports, before a `)`.") bracket_lint_msg <- rex::rex("Always have a trailing comma at the end of imports, before a `]`.") test_that("box_trailing_commas_linter skips allowed package import usage", { linter <- box_trailing_commas_linter() - + 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) @@ -67,34 +67,34 @@ test_that("box_trailing_commas_linter skips allowed package import usage", { test_that("box_trailing_commas_linter blocks no trailing commas in package imports", { linter <- box_trailing_commas_linter() - + 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 blocks no trailing commas in package function imports", { linter <- box_trailing_commas_linter() - + lintr::expect_lint(bad_package_function_commas, list(message = bracket_lint_msg), linter) - lintr::expect_lint(bad_package_function_commas_inline, 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() - + 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 blocks no trailing commas in module function imports", { linter <- box_trailing_commas_linter() - + lintr::expect_lint(bad_module_function_commas, list(message = bracket_lint_msg), linter) - lintr::expect_lint(bad_module_function_commas_inline, 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() - + lintr::expect_lint(should_not_lint, NULL, linter) })