diff --git a/.ci/lint_r_code.R b/.ci/lint_r_code.R index 12116104e..a49e70f94 100755 --- a/.ci/lint_r_code.R +++ b/.ci/lint_r_code.R @@ -1,5 +1,5 @@ -library(lintr) +loadNamespace("lintr") args <- commandArgs( trailingOnly = TRUE @@ -33,30 +33,34 @@ LINTERS_TO_USE <- list( , "any_duplicated" = lintr::any_duplicated_linter() , "any_is_na" = lintr::any_is_na_linter() , "assignment" = lintr::assignment_linter() + , "backport" = lintr::backport_linter() , "boolean_arithmetic" = lintr::boolean_arithmetic_linter() , "braces" = lintr::brace_linter() , "class_equals" = lintr::class_equals_linter() , "commas" = lintr::commas_linter() + , "conjunct_test" = lintr::conjunct_test_linter() , "duplicate_argument" = lintr::duplicate_argument_linter() , "empty_assignment" = lintr::empty_assignment_linter() , "equals_na" = lintr::equals_na_linter() + , "fixed_regex" = lintr::fixed_regex_linter() , "for_loop_index" = lintr::for_loop_index_linter() , "function_left" = lintr::function_left_parentheses_linter() + , "function_return" = lintr::function_return_linter() + , "implicit_assignment" = lintr::implicit_assignment_linter() , "implicit_integers" = lintr::implicit_integer_linter() , "infix_spaces" = lintr::infix_spaces_linter() , "inner_combine" = lintr::inner_combine_linter() , "is_numeric" = lintr::is_numeric_linter() - , "fixed_regex" = lintr::fixed_regex_linter() - , "function_return" = lintr::function_return_linter() , "lengths" = lintr::lengths_linter() + , "line_length" = lintr::line_length_linter(length = 120L) , "literal_coercion" = lintr::literal_coercion_linter() - , "long_lines" = lintr::line_length_linter(length = 120L) , "matrix" = lintr::matrix_apply_linter() , "missing_argument" = lintr::missing_argument_linter() , "non_portable_path" = lintr::nonportable_path_linter() , "numeric_leading_zero" = lintr::numeric_leading_zero_linter() , "outer_negation" = lintr::outer_negation_linter() , "package_hooks" = lintr::package_hooks_linter() + , "paren_body" = lintr::paren_body_linter() , "paste" = lintr::paste_linter() , "quotes" = lintr::quotes_linter() , "redundant_equals" = lintr::redundant_equals_linter() @@ -100,6 +104,7 @@ LINTERS_TO_USE <- list( "%>%" = pipe_text , "%.%" = pipe_text , "%..%" = pipe_text + , "|>" = pipe_text , "?" = interactive_text , "??" = interactive_text ) @@ -107,6 +112,7 @@ LINTERS_TO_USE <- list( , "unnecessary_concatenation" = lintr::unnecessary_concatenation_linter() , "unnecessary_lambda" = lintr::unnecessary_lambda_linter() , "unreachable_code" = lintr::unreachable_code_linter() + , "unused_import" = lintr::unused_import_linter() , "vector_logic" = lintr::vector_logic_linter() , "whitespace" = lintr::whitespace_linter() ) diff --git a/R-package/demo/basic_walkthrough.R b/R-package/demo/basic_walkthrough.R index b5bfed26d..c9ac484e6 100644 --- a/R-package/demo/basic_walkthrough.R +++ b/R-package/demo/basic_walkthrough.R @@ -1,5 +1,4 @@ library(lightgbm) -library(methods) # We load in the agaricus dataset # In this example, we are aiming to predict whether a mushroom is edible diff --git a/R-package/demo/boost_from_prediction.R b/R-package/demo/boost_from_prediction.R index 5ee04f2d7..68d33a73c 100644 --- a/R-package/demo/boost_from_prediction.R +++ b/R-package/demo/boost_from_prediction.R @@ -1,5 +1,4 @@ library(lightgbm) -library(methods) # Load in the agaricus dataset data(agaricus.train, package = "lightgbm") diff --git a/R-package/demo/early_stopping.R b/R-package/demo/early_stopping.R index 5179195f0..6ca214c5a 100644 --- a/R-package/demo/early_stopping.R +++ b/R-package/demo/early_stopping.R @@ -1,5 +1,4 @@ library(lightgbm) -library(methods) # Load in the agaricus dataset data(agaricus.train, package = "lightgbm") diff --git a/R-package/tests/testthat.R b/R-package/tests/testthat.R index 475295274..72a440c27 100644 --- a/R-package/tests/testthat.R +++ b/R-package/tests/testthat.R @@ -1,5 +1,5 @@ library(testthat) -library(lightgbm) +library(lightgbm) # nolint: [unused_import] test_check( package = "lightgbm" diff --git a/R-package/tests/testthat/test_dataset.R b/R-package/tests/testthat/test_dataset.R index cf68ce926..401d1babf 100644 --- a/R-package/tests/testthat/test_dataset.R +++ b/R-package/tests/testthat/test_dataset.R @@ -183,7 +183,9 @@ test_that("lgb.Dataset: colnames", { colnames(dtest) <- "asdf" }) new_names <- make.names(seq_len(ncol(test_data))) - expect_silent(colnames(dtest) <- new_names) + expect_silent({ + colnames(dtest) <- new_names + }) expect_equal(colnames(dtest), new_names) }) diff --git a/R-package/tests/testthat/test_learning_to_rank.R b/R-package/tests/testthat/test_learning_to_rank.R index 6868794cf..b4ebe7bd6 100644 --- a/R-package/tests/testthat/test_learning_to_rank.R +++ b/R-package/tests/testthat/test_learning_to_rank.R @@ -37,7 +37,8 @@ test_that("learning-to-rank with lgb.train() works as expected", { eval_results <- model$eval_train() expect_equal(length(eval_results), length(eval_names)) for (result in eval_results) { - expect_true(result[["value"]] > 0.0 && result[["value"]] < 1.0) + expect_true(result[["value"]] > 0.0) + expect_true(result[["value"]] < 1.0) expect_true(result[["higher_better"]]) expect_identical(result[["data_name"]], "training") } @@ -104,8 +105,10 @@ test_that("learning-to-rank with lgb.cv() works as expected", { # check that best score and iter make sense (0.0 < nDCG < 1.0) best_iter <- cv_bst$best_iter best_score <- cv_bst$best_score - expect_true(best_iter > 0L && best_iter <= nrounds) - expect_true(best_score > 0.0 && best_score < 1.0) + expect_true(best_iter > 0L) + expect_true(best_iter <= nrounds) + expect_true(best_score > 0.0) + expect_true(best_score < 1.0) expect_true(abs(best_score - 0.75) < .LGB_NUMERIC_TOLERANCE) # best_score should be set for the first metric diff --git a/R-package/tests/testthat/test_lgb.Booster.R b/R-package/tests/testthat/test_lgb.Booster.R index 5f398f1c0..7ebb236cd 100644 --- a/R-package/tests/testthat/test_lgb.Booster.R +++ b/R-package/tests/testthat/test_lgb.Booster.R @@ -1275,7 +1275,9 @@ test_that("params (including dataset params) should be stored in .rds file for B bst_file <- tempfile(fileext = ".rds") expect_warning(saveRDS.lgb.Booster(bst, file = bst_file)) - expect_warning(bst_from_file <- readRDS.lgb.Booster(file = bst_file)) + expect_warning({ + bst_from_file <- readRDS.lgb.Booster(file = bst_file) + }) expect_identical( bst_from_file$params , list(