Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint/fixes #35

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion R/api_key.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
return(testing_key())
} else {
cli::cli_abort(
"No API key found, please supply with {.arg api_key} argument or with {.help [{.fun set_api_key}](octopusR::set_api_key)}",
"No API key found, please supply with {.arg api_key} argument or with
{.help [{.fun set_api_key}](octopusR::set_api_key)}",

Check warning on line 32 in R/api_key.R

View check run for this annotation

Codecov / codecov/patch

R/api_key.R#L31-L32

Added lines #L31 - L32 were not covered by tests
call = rlang::caller_env()
)
}
Expand Down
15 changes: 8 additions & 7 deletions R/check_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@
#'
#' @return NULL
check_datetime_format <- function(arg_date) {
arg <- rlang::caller_arg(arg_date)
call <- rlang::caller_env()
if (!inherits(arg_date, "character") &&
!inherits(arg_date, "Date")) {
if (!inherits(arg_date, "character") && !inherits(arg_date, "Date")) {
cli::cli_abort(
"{.arg {arg}} must be {.cls character} or {.cls Date}, not {.cls {class(arg_date)}}.",
"{.arg {rlang::caller_arg(arg_date)}} must be {.cls character} or
{.cls Date}, not {.cls {class(arg_date)}}.",

Check warning on line 16 in R/check_params.R

View check run for this annotation

Codecov / codecov/patch

R/check_params.R#L15-L16

Added lines #L15 - L16 were not covered by tests
call = call
)
}
iso_8601_pattern <-
"^([\\+-]?\\d{4}(?!\\d{2}\\b))((-?)((0[1-9]|1[0-2])(\\3([12]\\d|0[1-9]|3[01]))?|W([0-4]\\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\\d|[12]\\d{2}|3([0-5]\\d|6[1-6])))([T\\s]((([01]\\d|2[0-3])((:?)[0-5]\\d)?|24\\:?00)([\\.,]\\d+(?!:))?)?(\\17[0-5]\\d([\\.,]\\d+)?)?([zZ]|([\\+-])([01]\\d|2[0-3]):?([0-5]\\d)?)?)?)?$"

Check warning on line 21 in R/check_params.R

View workflow job for this annotation

GitHub Actions / lint

file=R/check_params.R,line=21,col=81,[line_length_linter] Lines should not be more than 80 characters. This line is 312 characters.

if (!grepl(iso_8601_pattern, arg_date, perl = TRUE)) {
cli::cli_abort(
c(
"{.arg {arg}} must be in [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) format.",
"{.arg {rlang::caller_arg(arg_date)}} must be in
[ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) format.",
">" = "For example {.val {Sys.Date()}} or {.val {Sys.time()}}."
),
call = call
Expand All @@ -43,10 +43,11 @@
#'
#' @return NULL
check_logical <- function(arg_lgl) {
arg <- rlang::caller_arg(arg_lgl)
call <- rlang::caller_env()
if (!inherits(arg_lgl, "logical")) {
cli::cli_abort("{.arg {arg}} must be {.cls logical}, not {.cls {class(arg_lgl)}}.",
cli::cli_abort(
"{.arg {rlang::caller_arg(arg_lgl)}} must be {.cls logical},
not {.cls {class(arg_lgl)}}.",
call = call
)
}
Expand Down
6 changes: 4 additions & 2 deletions R/get_consumption.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#'
#' @return a [tibble][tibble::tibble-package] of the requested consumption data.
#' @export
get_consumption <- function(

Check warning on line 40 in R/get_consumption.R

View workflow job for this annotation

GitHub Actions / lint

file=R/get_consumption.R,line=40,col=1,[cyclocomp_linter] Functions should have cyclomatic complexity of less than 15, this has 17.
meter_type = c("electricity", "gas"),
mpan_mprn = get_meter_details(meter_type)[["mpan_mprn"]],
serial_number = get_meter_details(meter_type)[["serial_number"]],
Expand All @@ -59,7 +59,8 @@
force(api_key)
if (!missing(period_to) && missing(period_from)) {
cli::cli_abort(
"To use {.arg period_to} you must also provide the {.arg period_from} parameter to create a range."
"To use {.arg period_to} you must also provide the {.arg period_from}
parameter to create a range."
)
}
if (missing(order_by)) {
Expand All @@ -78,7 +79,8 @@

if (missing(period_from)) {
cli::cli_abort(
"You must also specify {.arg period_to} when specifying {.arg period_from}."
"You must also specify {.arg period_to} when specifying
{.arg period_from}."

Check warning on line 83 in R/get_consumption.R

View check run for this annotation

Codecov / codecov/patch

R/get_consumption.R#L82-L83

Added lines #L82 - L83 were not covered by tests
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions R/get_meter_gsp.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
#'
#' @return a character of the meter-points GSP.
#' @export
get_meter_gsp <- function(mpan = get_meter_details("electricity")[["mpan_mprn"]]) {
get_meter_gsp <- function(
mpan = get_meter_details("electricity")[["mpan_mprn"]]) {
if (is.na(mpan) || mpan == "") {
cli::cli_abort(
"Meter details were missing or incomplete, please supply with {.arg mpan_mprn} and {.arg serial_number} arguments or with {.help [{.fun set_meter_details}](octopusR::set_meter_details)}",
"Meter details were missing or incomplete, please supply with
{.arg mpan_mprn} and {.arg serial_number} arguments or with
{.help [{.fun set_meter_details}](octopusR::set_meter_details)}",
call = rlang::caller_env()
)
}
Expand Down
7 changes: 5 additions & 2 deletions R/meter_details.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
if (missing(mpan_mprn)) {
mpan_mprn <- askpass::askpass(
glue::glue(
"Please enter your {meter_type} meter-point's {ifelse(meter_type == 'electricity', 'MPAN', 'MPRN')}."
"Please enter your {meter_type} meter-point's
{ifelse(meter_type == 'electricity', 'MPAN', 'MPRN')}."

Check warning on line 30 in R/meter_details.R

View check run for this annotation

Codecov / codecov/patch

R/meter_details.R#L29-L30

Added lines #L29 - L30 were not covered by tests
)
)
}
Expand Down Expand Up @@ -80,7 +81,9 @@
}

cli::cli_abort(
"Meter details were missing or incomplete, please supply with {.arg mpan_mprn} and {.arg serial_number} arguments or with {.help [{.fun set_meter_details}](octopusR::set_meter_details)}.",
"Meter details were missing or incomplete, please supply with
{.arg mpan_mprn} and {.arg serial_number} arguments or with
{.help [{.fun set_meter_details}](octopusR::set_meter_details)}.",

Check warning on line 86 in R/meter_details.R

View check run for this annotation

Codecov / codecov/patch

R/meter_details.R#L84-L86

Added lines #L84 - L86 were not covered by tests
call = rlang::caller_env()
)
}
Expand Down
2 changes: 1 addition & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Codecov
GSP
MPAN
MPRN
OctopusR
SMETS
datetime
timezone
4 changes: 2 additions & 2 deletions tests/testthat/test-get_consumption.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ test_that("errors properly with incorrect params", {

expect_error(
get_consumption("electricity", period_to = Sys.Date()),
"To use `period_to` you must also provide the `period_from` parameter to create a range"
"To use `period_to` you must also provide the `period_from` parameter .+?$"
)
expect_error(
get_consumption("gas", period_to = Sys.Date()),
"To use `period_to` you must also provide the `period_from` parameter to create a range"
"To use `period_to` you must also provide the `period_from` parameter .+?$"
)
})

Expand Down
Loading