Unverified Commit 1b43214f authored by CuriousCorrelation's avatar CuriousCorrelation Committed by GitHub
Browse files

[ci] [R-package] Add string_boundary_linter (#5324)

parent eb13f39a
...@@ -58,6 +58,7 @@ LINTERS_TO_USE <- list( ...@@ -58,6 +58,7 @@ LINTERS_TO_USE <- list(
, "spaces_inside" = lintr::spaces_inside_linter() , "spaces_inside" = lintr::spaces_inside_linter()
, "spaces_left_parens" = lintr::spaces_left_parentheses_linter() , "spaces_left_parens" = lintr::spaces_left_parentheses_linter()
, "sprintf" = lintr::sprintf_linter() , "sprintf" = lintr::sprintf_linter()
, "string_boundary" = lintr::string_boundary_linter()
, "todo_comments" = lintr::todo_comment_linter(c("todo", "fixme", "to-do")) , "todo_comments" = lintr::todo_comment_linter(c("todo", "fixme", "to-do"))
, "trailing_blank" = lintr::trailing_blank_lines_linter() , "trailing_blank" = lintr::trailing_blank_lines_linter()
, "trailing_white" = lintr::trailing_whitespace_linter() , "trailing_white" = lintr::trailing_whitespace_linter()
......
...@@ -4,9 +4,9 @@ VERBOSITY <- as.integer( ...@@ -4,9 +4,9 @@ VERBOSITY <- as.integer(
ON_WINDOWS <- .Platform$OS.type == "windows" ON_WINDOWS <- .Platform$OS.type == "windows"
UTF8_LOCALE <- all(grepl( UTF8_LOCALE <- all(endsWith(
pattern = "UTF-8$" Sys.getlocale(category = "LC_CTYPE")
, x = Sys.getlocale(category = "LC_CTYPE") , "UTF-8"
)) ))
data(agaricus.train, package = "lightgbm") data(agaricus.train, package = "lightgbm")
......
...@@ -787,20 +787,20 @@ test_that("all parameters are stored correctly with save_model_to_string()", { ...@@ -787,20 +787,20 @@ test_that("all parameters are stored correctly with save_model_to_string()", {
params_in_file <- .params_from_model_string(model_str = model_str) params_in_file <- .params_from_model_string(model_str = model_str)
# parameters should match what was passed from the R package # parameters should match what was passed from the R package
expect_equal(sum(grepl(pattern = "^\\[metric\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[metric:")), 1L)
expect_equal(sum(params_in_file == "[metric: l2]"), 1L) expect_equal(sum(params_in_file == "[metric: l2]"), 1L)
expect_equal(sum(grepl(pattern = "^\\[num_iterations\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[num_iterations:")), 1L)
expect_equal(sum(params_in_file == "[num_iterations: 4]"), 1L) expect_equal(sum(params_in_file == "[num_iterations: 4]"), 1L)
expect_equal(sum(grepl(pattern = "^\\[objective\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[objective:")), 1L)
expect_equal(sum(params_in_file == "[objective: regression]"), 1L) expect_equal(sum(params_in_file == "[objective: regression]"), 1L)
expect_equal(sum(grepl(pattern = "^\\[verbosity\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[verbosity:")), 1L)
expect_equal(sum(params_in_file == sprintf("[verbosity: %i]", VERBOSITY)), 1L) expect_equal(sum(params_in_file == sprintf("[verbosity: %i]", VERBOSITY)), 1L)
# early stopping should be off by default # early stopping should be off by default
expect_equal(sum(grepl(pattern = "^\\[early_stopping_round\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[early_stopping_round:")), 1L)
expect_equal(sum(params_in_file == "[early_stopping_round: 0]"), 1L) expect_equal(sum(params_in_file == "[early_stopping_round: 0]"), 1L)
}) })
...@@ -851,15 +851,15 @@ test_that("early_stopping, num_iterations are stored correctly in model string e ...@@ -851,15 +851,15 @@ test_that("early_stopping, num_iterations are stored correctly in model string e
# parameters should match what was passed from the R package, and the "main" (non-alias) # parameters should match what was passed from the R package, and the "main" (non-alias)
# params values in `params` should be preferred to keyword argumentts or aliases # params values in `params` should be preferred to keyword argumentts or aliases
expect_equal(sum(grepl(pattern = "^\\[num_iterations\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[num_iterations:")), 1L)
expect_equal(sum(params_in_file == sprintf("[num_iterations: %s]", num_iterations)), 1L) expect_equal(sum(params_in_file == sprintf("[num_iterations: %s]", num_iterations)), 1L)
expect_equal(sum(grepl(pattern = "^\\[early_stopping_round\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[early_stopping_round:")), 1L)
expect_equal(sum(params_in_file == sprintf("[early_stopping_round: %s]", early_stopping_round)), 1L) expect_equal(sum(params_in_file == sprintf("[early_stopping_round: %s]", early_stopping_round)), 1L)
# none of the aliases shouold have been written to the model file # none of the aliases shouold have been written to the model file
expect_equal(sum(grepl(pattern = "^\\[num_boost_round\\:", x = params_in_file)), 0L) expect_equal(sum(startsWith(params_in_file, "[num_boost_round:")), 0L)
expect_equal(sum(grepl(pattern = "^\\[n_iter\\:", x = params_in_file)), 0L) expect_equal(sum(startsWith(params_in_file, "[n_iter:")), 0L)
expect_equal(sum(grepl(pattern = "^\\[n_iter_no_change\\:", x = params_in_file)), 0L) expect_equal(sum(startsWith(params_in_file, "[n_iter_no_change:")), 0L)
}) })
...@@ -1079,15 +1079,15 @@ test_that("lgb.cv() correctly handles passing through params to the model file", ...@@ -1079,15 +1079,15 @@ test_that("lgb.cv() correctly handles passing through params to the model file",
# parameters should match what was passed from the R package, and the "main" (non-alias) # parameters should match what was passed from the R package, and the "main" (non-alias)
# params values in `params` should be preferred to keyword argumentts or aliases # params values in `params` should be preferred to keyword argumentts or aliases
expect_equal(sum(grepl(pattern = "^\\[num_iterations\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[num_iterations:")), 1L)
expect_equal(sum(params_in_file == sprintf("[num_iterations: %s]", num_iterations)), 1L) expect_equal(sum(params_in_file == sprintf("[num_iterations: %s]", num_iterations)), 1L)
expect_equal(sum(grepl(pattern = "^\\[early_stopping_round\\:", x = params_in_file)), 1L) expect_equal(sum(startsWith(params_in_file, "[early_stopping_round:")), 1L)
expect_equal(sum(params_in_file == sprintf("[early_stopping_round: %s]", early_stopping_round)), 1L) expect_equal(sum(params_in_file == sprintf("[early_stopping_round: %s]", early_stopping_round)), 1L)
# none of the aliases shouold have been written to the model file # none of the aliases shouold have been written to the model file
expect_equal(sum(grepl(pattern = "^\\[num_boost_round\\:", x = params_in_file)), 0L) expect_equal(sum(startsWith(params_in_file, "[num_boost_round:")), 0L)
expect_equal(sum(grepl(pattern = "^\\[n_iter\\:", x = params_in_file)), 0L) expect_equal(sum(startsWith(params_in_file, "[n_iter:")), 0L)
expect_equal(sum(grepl(pattern = "^\\[n_iter_no_change\\:", x = params_in_file)), 0L) expect_equal(sum(startsWith(params_in_file, "[n_iter_no_change:")), 0L)
} }
}) })
...@@ -1268,8 +1268,8 @@ test_that("Booster's print, show, and summary work correctly", { ...@@ -1268,8 +1268,8 @@ test_that("Booster's print, show, and summary work correctly", {
} }
.has_expected_content_for_fitted_model <- function(printed_txt) { .has_expected_content_for_fitted_model <- function(printed_txt) {
expect_true(any(grepl("^LightGBM Model", printed_txt))) expect_true(any(startsWith(printed_txt, "LightGBM Model")))
expect_true(any(grepl("^Fitted to dataset", printed_txt))) expect_true(any(startsWith(printed_txt, "Fitted to dataset")))
} }
.has_expected_content_for_finalized_model <- function(printed_txt) { .has_expected_content_for_finalized_model <- function(printed_txt) {
......
...@@ -404,7 +404,7 @@ dynlib_line <- grep( ...@@ -404,7 +404,7 @@ dynlib_line <- grep(
) )
c_api_contents <- readLines(file.path(TEMP_SOURCE_DIR, "src", "lightgbm_R.h")) c_api_contents <- readLines(file.path(TEMP_SOURCE_DIR, "src", "lightgbm_R.h"))
c_api_contents <- c_api_contents[grepl("^LIGHTGBM_C_EXPORT", c_api_contents)] c_api_contents <- c_api_contents[startsWith(c_api_contents, "LIGHTGBM_C_EXPORT")]
c_api_contents <- gsub( c_api_contents <- gsub(
pattern = "LIGHTGBM_C_EXPORT SEXP " pattern = "LIGHTGBM_C_EXPORT SEXP "
, replacement = "" , replacement = ""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment