From 591d049b6fbffa90cceb9401110112ca6fdd9fd7 Mon Sep 17 00:00:00 2001 From: MEO265 <99362508+MEO265@users.noreply.github.com> Date: Thu, 30 May 2024 07:28:30 +0200 Subject: [PATCH] mnt: Add `implicit_integer_linter` and fixes --- .lintr | 4 ++-- tests/testthat/test-handlers.R | 18 +++++++++--------- tests/testthat/test-loggit.R | 4 ++-- vignettes/loggit2.Rmd | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.lintr b/.lintr index e154d6b..93aa917 100644 --- a/.lintr +++ b/.lintr @@ -31,7 +31,7 @@ linters: list( if_not_else_linter(), ifelse_censor_linter(), # implicit_assignment_linter(allow_scoped = TRUE), # Is bugged - # implicit_integer_linter(allow_colon = TRUE), + implicit_integer_linter(allow_colon = TRUE), indentation_linter(), infix_spaces_linter(), inner_combine_linter(), @@ -61,7 +61,7 @@ linters: list( repeat_linter(), routine_registration_linter(), scalar_in_linter(), - # semicolon_linter(), + # semicolon_linter(), # Wanted in tests seq_linter(), sort_linter(), spaces_inside_linter(), diff --git a/tests/testthat/test-handlers.R b/tests/testthat/test-handlers.R index 64d05c5..21791b3 100644 --- a/tests/testthat/test-handlers.R +++ b/tests/testthat/test-handlers.R @@ -3,7 +3,7 @@ test_that("message works as it does in base R", { expect_identical_message(message(), base::message()) expect_identical_message(message("this is a message test"), base::message("this is a message test")) expect_identical_message(message("this", "is a", "message test"), base::message("this", "is a", "message test")) - expect_identical_message(message("Some numbers", 3, 1:5, "!"), base::message("Some numbers", 3, 1:5, "!")) + expect_identical_message(message("Some numbers", 3L, 1:5, "!"), base::message("Some numbers", 3L, 1:5, "!")) # message works as in base R (with echo = FALSE) expect_identical_message(message(echo = FALSE), base::message(), ignore_call = TRUE) @@ -44,7 +44,7 @@ test_that("warning works as it does in base R", { expect_identical_warning(warning(), base::warning()) expect_identical_warning(warning("this is a warning test"), base::warning("this is a warning test")) expect_identical_warning(warning("this", "is a", "warning test"), base::warning("this", "is a", "warning test")) - expect_identical_warning(warning("Some numbers", 3, 1:5, "!"), base::warning("Some numbers", 3, 1:5, "!")) + expect_identical_warning(warning("Some numbers", 3L, 1:5, "!"), base::warning("Some numbers", 3L, 1:5, "!")) # warning works as in base R (with echo = FALSE) expect_identical_warning(warning(echo = FALSE), base::warning()) @@ -80,7 +80,7 @@ test_that("stop works as it does in base R", { expect_identical_error(stop(), base::stop()) expect_identical_error(stop("this is a stop test"), base::stop("this is a stop test")) expect_identical_error(stop("this", "is a", "stop test"), base::stop("this", "is a", "stop test")) - expect_identical_error(stop("Some numbers", 3, 1:5, "!"), base::stop("Some numbers", 3, 1:5, "!")) + expect_identical_error(stop("Some numbers", 3L, 1:5, "!"), base::stop("Some numbers", 3L, 1:5, "!")) # stop works as in base R (with echo = FALSE) expect_identical_error(stop(echo = FALSE), base::stop()) @@ -114,11 +114,11 @@ test_that("stopifnot", { f <- function(x, ...) x expect_identical_error(stopifnot(f(x = FALSE)), base::stopifnot(f(x = FALSE))) g <- function() f(FALSE) - expect_identical_error(stopifnot(4 == 4, g()), base::stopifnot(4 == 4, g())) - expect_identical_error(stopifnot(4 == 4, Test = g()), base::stopifnot(4 == 4, Test = g())) + expect_identical_error(stopifnot(4L == 4L, g()), base::stopifnot(4L == 4L, g())) + expect_identical_error(stopifnot(4L == 4L, Test = g()), base::stopifnot(4L == 4L, Test = g())) expect_identical_error(stopifnot(exprs = { TRUE; FALSE }), base::stopifnot(exprs = { TRUE; FALSE })) expect_identical_error(stopifnot(exprObject = { TRUE; FALSE }), base::stopifnot(exprObject = { TRUE; FALSE })) - expect_no_error(stopifnot(TRUE, 3 == 3)) + expect_no_error(stopifnot(TRUE, 3L == 3L)) # stopifnot works as in base R (with echo = FALSE) expect_no_error(stopifnot(echo = FALSE)) @@ -126,14 +126,14 @@ test_that("stopifnot", { f <- function(x, ...) x expect_identical_error(stopifnot(f(x = FALSE), echo = FALSE), base::stopifnot(f(x = FALSE))) g <- function() f(FALSE) - expect_identical_error(stopifnot(4 == 4, g(), echo = FALSE), base::stopifnot(4 == 4, g())) - expect_identical_error(stopifnot(4 == 4, "A Test" = g(), echo = FALSE), base::stopifnot(4 == 4, "A Test" = g())) + expect_identical_error(stopifnot(4L == 4L, g(), echo = FALSE), base::stopifnot(4L == 4L, g())) + expect_identical_error(stopifnot(4L == 4L, "A Test" = g(), echo = FALSE), base::stopifnot(4L == 4L, "A Test" = g())) expect_identical_error(stopifnot(exprs = { TRUE; FALSE }, echo = FALSE), base::stopifnot(exprs = { TRUE; FALSE })) expect_identical_error( stopifnot(exprObject = { TRUE; FALSE }, echo = FALSE), base::stopifnot(exprObject = { TRUE; FALSE }) ) - expect_no_error(stopifnot(TRUE, 3 == 3, echo = FALSE)) + expect_no_error(stopifnot(TRUE, 3L == 3L, echo = FALSE)) cleanup() diff --git a/tests/testthat/test-loggit.R b/tests/testthat/test-loggit.R index 1f44c5a..b37c76f 100644 --- a/tests/testthat/test-loggit.R +++ b/tests/testthat/test-loggit.R @@ -32,7 +32,7 @@ test_that("loggit multiplies values with warning", { ) expect_warning( - loggit(log_lvl = "INFO", log_msg = c("foo", "bar"), value = 1, echo = FALSE), + loggit(log_lvl = "INFO", log_msg = c("foo", "bar"), value = 1L, echo = FALSE), regexp = "^log_msg should be of length one, only the first element will be used.$" ) @@ -42,7 +42,7 @@ test_that("loggit multiplies values with warning", { ) expect_error( - loggit(log_lvl = "INFO", log_msg = "foo", value = 1, "4", echo = FALSE), + loggit(log_lvl = "INFO", log_msg = "foo", value = 1L, "4", echo = FALSE), regexp = "^All custom log fields should be named.$" ) diff --git a/vignettes/loggit2.Rmd b/vignettes/loggit2.Rmd index 66adb2c..7b0635d 100644 --- a/vignettes/loggit2.Rmd +++ b/vignettes/loggit2.Rmd @@ -12,7 +12,7 @@ knitr::opts_chunk$set( #nolint collapse = TRUE, comment = "#>" ) -old <- options(width = 200) +old <- options(width = 200L) ``` `loggit2` is an easy-to-use, yet powerful, [`ndjson`](https://github.com/ndjson) @@ -114,7 +114,7 @@ fun_a <- function(x) { fun_b <- function(x) { base::warning("This is a second warning") - 5 + 5 + 5L + 5L } ```