Skip to content

Commit 42822b7

Browse files
committed
Finalize changes
* fix `.lintr` (used a deprecated function) * fix a few lints * Call styler on test-codecov.R and test-coveralls.R * avoid `with_mock()` in test-utils.R
1 parent 88a72ee commit 42822b7

File tree

11 files changed

+138
-123
lines changed

11 files changed

+138
-123
lines changed

.lintr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
linters: with_defaults(line_length_linter(120))
1+
linters: linters_with_defaults(line_length_linter(120))
22
exclusions: list("inst/doc/how_it_works.R")

R/cobertura.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#' @param cov the coverage object returned from [package_coverage()]
1515
#' @param filename the name of the Cobertura XML file
1616
#' @export
17-
to_cobertura <- function(cov, filename = "cobertura.xml"){
17+
to_cobertura <- function(cov, filename = "cobertura.xml") {
1818

1919
loadNamespace("xml2")
2020

@@ -24,7 +24,7 @@ to_cobertura <- function(cov, filename = "cobertura.xml"){
2424
percent_per_function <- tapply(df$value, df$functions, FUN = function(x) (sum(x > 0) / length(x)))
2525
lines_valid <- nrow(df)
2626
lines_covered <- sum(df$value > 0)
27-
27+
2828
d <- xml2::xml_new_document()
2929

3030
xml2::xml_add_child(d, xml2::xml_dtd(
@@ -34,7 +34,7 @@ to_cobertura <- function(cov, filename = "cobertura.xml"){
3434
top <- xml2::xml_add_child(d,
3535
"coverage",
3636
"line-rate" = as.character(percent_overall),
37-
"branch-rate" = "0",
37+
"branch-rate" = "0",
3838
`lines-covered` = as.character(lines_covered),
3939
`lines-valid` = as.character(lines_valid),
4040
`branches-covered` = "0",

R/compiled.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ run_gcov <- function(path, quiet = TRUE, clean = TRUE,
102102
res <- withr::with_dir(src_path, {
103103
compact(unlist(lapply(gcov_inputs, run_gcov_one), recursive = FALSE))
104104
})
105-
if (!length(res) & length(gcov_inputs))
105+
if (!length(res) && length(gcov_inputs))
106106
warning('parsed gcov output was empty')
107107
res
108108
}

R/covr.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ package_coverage <- function(path = ".",
369369
code = character(),
370370
install_path = temp_file("R_LIBS"),
371371
...,
372-
exclusions, pre_clean=TRUE) {
372+
exclusions, pre_clean = TRUE) {
373373

374374
if (!missing(exclusions)) {
375375
warning(
@@ -423,8 +423,7 @@ package_coverage <- function(path = ".",
423423
# check for compiler
424424
if (!uses_icc()) {
425425
flags <- getOption("covr.flags")
426-
}
427-
else {
426+
} else {
428427
if (length(getOption("covr.icov")) > 0L) {
429428
flags <- getOption("covr.icov_flags")
430429
# clean up old icov files
@@ -672,7 +671,7 @@ clean_coverage_tests <- function(obj) {
672671
for (i in seq_along(obj)) {
673672
if (is.null(val <- obj[[i]]$value)) next
674673
if (is.null(n <- nrow(obj[[i]]$tests$tally)) || n < val) next
675-
obj[[i]]$tests$tally <- obj[[i]]$tests$tally[seq_len(val),,drop = FALSE]
674+
obj[[i]]$tests$tally <- obj[[i]]$tests$tally[seq_len(val), , drop = FALSE]
676675
}
677676
}
678677

@@ -709,7 +708,7 @@ merge_coverage_tests <- function(from, into = NULL) {
709708
# modify trace test tallies
710709
for (name in intersect(names(into), names(from))) {
711710
if (name == "tests") next
712-
from[[name]]$tests$tally[,1L] <- test_idx[from[[name]]$tests$tally[,1L]]
711+
from[[name]]$tests$tally[, 1L] <- test_idx[from[[name]]$tests$tally[, 1L]]
713712
into[[name]]$tests$tally <- rbind(into[[name]]$tests$tally, from[[name]]$tests$tally)
714713
}
715714

R/icc.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ parse_icov <- function(lines, package_path = "") {
5454
by = list(line=m1$line, functions=m1$functions), sum)
5555
names(m2) <- c("line", "functions", "coverage")
5656
}
57-
matches <- m2[order(m2$line),]
57+
matches <- m2[order(m2$line), ]
5858

5959
values <- as.numeric(matches$coverage > 0L)
6060
functions <- matches$functions

R/summary_functions.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ print.coverage <- function(x, group = c("filename", "functions"), by = "line", .
162162

163163
overall_percentage <- percent_coverage(df, by = by)
164164

165-
cli::cli_inform(paste(
165+
cli::cli_inform(paste0(
166166
cli::style_bold(
167167
"{attr(x, 'package')$package} {to_title(type)} Coverage: "
168168
),
@@ -173,7 +173,7 @@ print.coverage <- function(x, group = c("filename", "functions"), by = "line", .
173173

174174
for (i in seq_along(by_coverage)) {
175175
cli::cli_inform(
176-
paste(
176+
paste0(
177177
cli::style_bold(names(by_coverage)[i], ": "),
178178
format_percentage(by_coverage[i])
179179
)

R/trace_calls.R

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,15 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) {
3131
if (is.atomic(x) || is.name(x) || is.null(x)) {
3232
if (is.null(parent_ref)) {
3333
x
34-
}
35-
else {
34+
} else {
3635
if (is_na(x) || is_brace(x)) {
3736
x
3837
} else {
3938
key <- new_counter(parent_ref, parent_functions) # nolint
4039
count(key, x)
4140
}
4241
}
43-
}
44-
else if (is.call(x)) {
42+
} else if (is.call(x)) {
4543
src_ref <- attr(x, "srcref") %||% impute_srcref(x, parent_ref)
4644
if ((identical(x[[1]], as.name("<-")) || identical(x[[1]], as.name("="))) && # nolint
4745
(is.call(x[[3]]) && identical(x[[3]][[1]], as.name("function")))) {
@@ -59,8 +57,7 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) {
5957
} else {
6058
as.call(recurse(x))
6159
}
62-
}
63-
else if (is.function(x)) {
60+
} else if (is.function(x)) {
6461

6562
# We cannot trace primitive functions
6663
if (is.primitive(x)) {
@@ -83,17 +80,13 @@ trace_calls <- function (x, parent_functions = NULL, parent_ref = NULL) {
8380
formals(x) <- new_formals
8481
body(x) <- fun_body
8582
x
86-
}
87-
else if (is.pairlist(x)) {
83+
} else if (is.pairlist(x)) {
8884
as.pairlist(recurse(x))
89-
}
90-
else if (is.expression(x)) {
85+
} else if (is.expression(x)) {
9186
as.expression(recurse(x))
92-
}
93-
else if (is.list(x)) {
87+
} else if (is.list(x)) {
9488
recurse(x)
95-
}
96-
else {
89+
} else {
9790
message("Unknown language class: ", paste(class(x), collapse = "/"))
9891
x
9992
}

R/trace_tests.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ count_test <- function(key) {
127127
tests$.data[[4L]] <- .current_test$i
128128

129129
tests$.value <- .counters[[key]]$value
130-
with(tests, tally[.value,] <- .data)
130+
with(tests, tally[.value, ] <- .data)
131131
}
132132

133133
#' Initialize a new test counter for a coverage trace
@@ -339,9 +339,9 @@ truncate_call <- function(call_obj, limit = 1e4) {
339339
#'
340340
is_current_test_finished <- function() {
341341
is.null(.current_test$src) ||
342-
.current_test$last_frame > sys.nframe() ||
343-
!identical(.current_test$src_call, sys.call(which = .current_test$last_frame)) ||
344-
!identical(.current_test$src_env, sys.frame(which = .current_test$last_frame - 1L))
342+
.current_test$last_frame > sys.nframe() ||
343+
!identical(.current_test$src_call, sys.call(which = .current_test$last_frame)) ||
344+
!identical(.current_test$src_env, sys.frame(which = .current_test$last_frame - 1L))
345345
}
346346

347347
#' Is the source bound to the expression

0 commit comments

Comments
 (0)