Skip to content

Commit

Permalink
jsonlite is a Suggests dependency (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico authored Oct 11, 2022
1 parent 461d9a9 commit 444a2fb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Imports:
cyclocomp,
digest,
glue,
jsonlite,
knitr,
rex,
stats,
Expand All @@ -39,6 +38,7 @@ Imports:
Suggests:
bookdown,
httr (>= 1.2.1),
jsonlite,
mockery,
patrick,
pkgdown,
Expand Down
3 changes: 3 additions & 0 deletions R/comments.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ github_comment <- function(text, info = NULL, token = settings$comment_token) {
if (!requireNamespace("httr", quietly = TRUE)) {
stop("Package 'httr' is required to post comments with github_comment().")
}
if (!requireNamespace("jsonlite", quietly = TRUE)) {
stop("Package 'jsonlite' is required to post comments with github_comment().")
}

if (is.null(info)) {
info <- ci_build_info()
Expand Down
6 changes: 4 additions & 2 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ checkstyle_output <- function(lints, filename = "lintr_results.xml") {
#' @param filename the name of the output report
#' @export
sarif_output <- function(lints, filename = "lintr_results.sarif") {
if (!requireNamespace("jsonlite", quietly = TRUE)) {
stop("'jsonlite' is required to produce SARIF reports, please install to continue.")
}

# package path will be `NULL` unless it is a relative path
package_path <- attr(lints, "path")
Expand Down Expand Up @@ -716,8 +719,7 @@ sarif_output <- function(lints, filename = "lintr_results.sarif") {
append(sarif$runs[[1L]]$results, list(one_result))
}

write(jsonlite::toJSON(sarif, pretty = TRUE, auto_unbox = TRUE),
filename)
write(jsonlite::toJSON(sarif, pretty = TRUE, auto_unbox = TRUE), filename)
}

highlight_string <- function(message, column_number = NULL, ranges = NULL) {
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-sarif_output.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
skip_if_not_installed("jsonlite")

test_that("`sarif_output` produces expected error", {
l <- lint(text = "x = 1", linters = assignment_linter())
expect_error(sarif_output(l), "Package path needs to be a relative path", fixed = TRUE)
Expand Down

0 comments on commit 444a2fb

Please sign in to comment.