Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnCoene committed Jan 28, 2024
1 parent 828f720 commit f77f8d4
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 127 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ test.R
^\.github$
^CODE_OF_CONDUCT\.md$
^CRAN-SUBMISSION$
^\.lintr$
15 changes: 15 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
linters: linters_with_defaults(
line_length_linter(120),
trailing_whitespace_linter = NULL,
commented_code_linter = NULL,
function_left_parentheses_linter = NULL,
spaces_left_parentheses_linter = NULL,
paren_body_linter = NULL,
brace_linter = NULL,
indentation_linter(
indent = 2L,
hanging_indent_style = "never"
),
object_usage_linter = NULL # this uses eval()
)
encoding: "UTF-8"
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ License: AGPL-3
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
RoxygenNote: 7.3.0
Imports:
R6,
rlang
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

S3method(chk,default)
S3method(chk,err)
S3method(get_call,character)
S3method(get_call,condition)
S3method(get_msg,character)
S3method(get_msg,condition)
S3method(is.e,default)
S3method(is.e,err)
S3method(is.w,default)
Expand All @@ -14,6 +18,8 @@ export(bash)
export(chk)
export(defer_resolve)
export(e)
export(get_call)
export(get_msg)
export(is.e)
export(is.problem)
export(is.w)
Expand Down
24 changes: 12 additions & 12 deletions R/error.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Error
#'
#' @export
Error <- R6::R6Class(
Error <- R6::R6Class( # nolint
"Error",
inherit = Issue,
#' @details Initialise
#'
#' @param obj A character string or an object of
#' class `error`, or `warning`.
#' @param raiser Template to raise the issue.
#' @details Initialise
#'
#' @param obj A character string or an object of
#' class `error`, or `warning`.
#' @param raiser Template to raise the issue.
public = list(
initialize = function(
obj,
Expand All @@ -17,15 +17,15 @@ Error <- R6::R6Class(
super$initialize(obj, type = "error")
super$raiser <- raiser
},
#' @details Stop
#'
#' Analogous to [stop()]
#' @details Stop
#'
#' Analogous to [stop()]
stop = function(){
super$raise()
},
#' @details Fatal
#'
#' Analogous to [stop()]
#' @details Fatal
#'
#' Analogous to [stop()]
fatal = function(){
super$raise()
}
Expand Down
8 changes: 4 additions & 4 deletions R/is.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#'
#' @name checks
#' @export
is.e <- function(obj) UseMethod("is.e")
is.e <- function(obj) UseMethod("is.e") # nolint

#' @rdname checks
#' @export
Expand All @@ -37,7 +37,7 @@ is.e.err <- function(obj){

#' @rdname checks
#' @export
is.w <- function(obj) UseMethod("is.w")
is.w <- function(obj) UseMethod("is.w") # nolint

#' @rdname checks
#' @export
Expand All @@ -54,6 +54,6 @@ is.w.err <- function(obj){

#' @rdname checks
#' @export
is.problem <- function(obj){
is.problem <- function(obj){ # nolint
is.e(obj) || is.w(obj)
}
}
42 changes: 21 additions & 21 deletions R/issue.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,46 @@
#' @importFrom rlang expr eval_bare
#'
#' @export
Issue <- R6::R6Class(
Issue <- R6::R6Class( # nolint
"Issue",
public = list(
#' @details Initialise
#'
#' @param obj A character string or an object of
#' class `error`, or `warning`.
#' @param type Type of message.
#' @details Initialise
#'
#' @param obj A character string or an object of
#' class `error`, or `warning`.
#' @param type Type of message.
initialize = function(obj, type = c("error", "warning")){
private$msg <- get_msg(obj)
private$.call <- get_call(obj)
private$type <- match.arg(type)
},
#' @details Print
#'
#' Print message of error or warning.
#' @details Print
#'
#' Print message of error or warning.
print = function(){
pattern <- tmpl(private$type)
msg <- sprintf(pattern, private$msg)
cat(msg, "\n")
},
#' @details Return
#' Returns self from parent function.
#'
#' @param n the number of generations to go back, passed to
#' [parent.frame()].
#' @details Return
#' Returns self from parent function.
#'
#' @param n the number of generations to go back, passed to
#' [parent.frame()].
return = function(n = 1){
assign("return.issue", self, envir = parent.frame(n))
call <- expr(return(return.issue))
eval_bare(call, env = parent.frame(n))
},
#' @details Add a rule
#' @param fn Function defining rule, must accept a single argument
#' and return a boolean.
#' @details Add a rule
#' @param fn Function defining rule, must accept a single argument
#' and return a boolean.
addRule = function(fn){
self$rule <- fn
invisible(self)
},
#' @details Add a predicate
#' @param obj Object to check by rules
#' @details Add a predicate
#' @param obj Object to check by rules
check = function(obj){

if(length(private$.rules) == 0)
Expand All @@ -77,8 +77,8 @@ Issue <- R6::R6Class(

self$raise()
},
#' @details Raise error or warning
#' @param fn A function to use to raise the issue.
#' @details Raise error or warning
#' @param fn A function to use to raise the issue.
raise = function(fn = NULL){
if(!is.null(fn))
fn(self$message)
Expand Down
6 changes: 3 additions & 3 deletions R/latch.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#'
#' @name latch
#' @export
latch.e <- function(obj, error){
latch.e <- function(obj, error){ # nolint
missing_obj <- e("Missing `obj`")
missing_error <- e("Missing `error`")

Expand All @@ -53,7 +53,7 @@ latch.e <- function(obj, error){

#' @rdname latch
#' @export
latch.w <- function(obj, warning){
latch.w <- function(obj, warning){ # nolint
missing_obj <- e("Missing `obj`")
missing_warning <- e("Missing `warning`")

Expand Down Expand Up @@ -127,4 +127,4 @@ get_attr_e <- function(obj){
#' @keywords internal
get_attr_w <- function(obj){
attr(obj, "w")
}
}
10 changes: 6 additions & 4 deletions R/parse.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
#' @param obj Message string, object of class `error`,
#' or `warning`.
#'
#' @noRd
#' @keywords internal
#' @export
get_msg <- function(obj) UseMethod("get_msg")

#' @export
get_msg.character <- function(obj){
return(obj)
}

#' @export
get_msg.condition <- function(obj){
return(obj$message)
}
Expand All @@ -25,17 +26,18 @@ get_msg.condition <- function(obj){
#' @param obj Message string, object of class `error`,
#' or `warning`.
#'
#' @noRd
#' @keywords internal
#' @export
get_call <- function(obj) UseMethod("get_call")

#' @export
get_call.condition <- function(obj){
if(is.null(obj$call))
return(NA_character_)

obj$call
}

#' @export
get_call.character <- function(obj){
NA_character_
}
10 changes: 5 additions & 5 deletions R/template.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
#'
#' @name template
#' @export
template.e <- function(pat = "%s"){
template.e <- function(pat = "%s"){ # nolint
check_tmpl(pat)
options("ERR_TEMPLATE_ERROR" = pat)
invisible()
}

#' @rdname template
#' @export
template.w <- function(pat = "%s"){
template.w <- function(pat = "%s"){ # nolint
check_tmpl(pat)
options("ERR_TEMPLATE_WARNING" = pat)
invisible()
Expand Down Expand Up @@ -77,20 +77,20 @@ check_tmpl <- function(pat){
#'
#' @name raise
#' @export
raise.e <- function(fn = NULL){
raise.e <- function(fn = NULL){ # nolint
options("ERR_RAISER_ERROR" = fn)
invisible()
}

#' @rdname raise
#' @export
raise.w <- function(fn = NULL){
raise.w <- function(fn = NULL){ # nolint
options("ERR_RAISER_WARNING" = fn)
invisible()
}

# Default raise method for Error
stopper <- function(message){
stopper <- function(message){ # nolint
stop(message, call. = FALSE)
}

Expand Down
18 changes: 9 additions & 9 deletions R/warning.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#' Error
#'
#' @export
Warning <- R6::R6Class(
Warning <- R6::R6Class( # nolint
"Warning",
inherit = Issue,
#' @details Initialise
#'
#' @param obj A character string or an object of
#' class `error`, or `warning`.
#' @param raiser Template to raise the issue.
#' @details Initialise
#'
#' @param obj A character string or an object of
#' class `error`, or `warning`.
#' @param raiser Template to raise the issue.
public = list(
initialize = function(
obj,
Expand All @@ -17,9 +17,9 @@ Warning <- R6::R6Class(
super$initialize(obj, type = "warning")
super$raiser <- raiser
},
#' @details Warn
#'
#' Analogous to [warning()]
#' @details Warn
#'
#' Analogous to [warning()]
warn = function(){
super$raise()
}
Expand Down
Loading

0 comments on commit f77f8d4

Please sign in to comment.