From 05700fc2261162b823769ff92f5e7fd9f3545038 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 3 Aug 2024 16:24:36 +0200 Subject: [PATCH 1/3] Use cli progress bar: first draft --- NAMESPACE | 3 --- R/lint.R | 20 +++----------------- R/lintr-package.R | 3 +-- tests/testthat/test-lint_dir.R | 6 ------ 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 6b5c46937..c02307cf3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -180,13 +180,10 @@ importFrom(stats,na.omit) importFrom(tools,R_user_dir) importFrom(utils,capture.output) importFrom(utils,getParseData) -importFrom(utils,getTxtProgressBar) importFrom(utils,globalVariables) importFrom(utils,head) importFrom(utils,relist) -importFrom(utils,setTxtProgressBar) importFrom(utils,tail) -importFrom(utils,txtProgressBar) importFrom(xml2,as_list) importFrom(xml2,xml_attr) importFrom(xml2,xml_children) diff --git a/R/lint.R b/R/lint.R index 042fbeaca..038253d5c 100644 --- a/R/lint.R +++ b/R/lint.R @@ -182,20 +182,13 @@ lint_dir <- function(path = ".", ..., return(lints) } - pb <- if (isTRUE(show_progress)) { - txtProgressBar(max = length(files), style = 3L) - } - lints <- flatten_lints(lapply( - files, - function(file) { - maybe_report_progress(pb) - lint(file, ..., parse_settings = FALSE, exclusions = exclusions) + cli::cli_progress_along(files, name = "Running linters"), + function(idx) { + lint(files[idx], ..., parse_settings = FALSE, exclusions = exclusions) } )) - if (!is.null(pb)) close(pb) - lints <- reorder_lints(lints) if (relative_path) { @@ -688,13 +681,6 @@ has_positional_logical <- function(dots) { !nzchar(names2(dots)[1L]) } -maybe_report_progress <- function(pb) { - if (is.null(pb)) { - return(invisible()) - } - setTxtProgressBar(pb, getTxtProgressBar(pb) + 1L) -} - maybe_append_error_lint <- function(lints, error, lint_cache, filename) { if (inherits(error, "lint")) { error$linter <- "error" diff --git a/R/lintr-package.R b/R/lintr-package.R index 70f8d0d11..ff9fba37d 100644 --- a/R/lintr-package.R +++ b/R/lintr-package.R @@ -13,8 +13,7 @@ #' @importFrom rex rex regex re_matches re_substitutes character_class #' @importFrom stats na.omit #' @importFrom tools R_user_dir -#' @importFrom utils capture.output getParseData getTxtProgressBar globalVariables head relist -#' setTxtProgressBar tail txtProgressBar +#' @importFrom utils capture.output getParseData globalVariables head relist tail #' @importFrom xml2 as_list #' xml_attr xml_children xml_find_all xml_find_chr xml_find_lgl xml_find_num xml_find_first xml_name xml_text ## lintr namespace: end diff --git a/tests/testthat/test-lint_dir.R b/tests/testthat/test-lint_dir.R index 6da4b81bb..da6dd824c 100644 --- a/tests/testthat/test-lint_dir.R +++ b/tests/testthat/test-lint_dir.R @@ -10,12 +10,6 @@ test_that("lint all files in a directory", { expect_s3_class(lints, "lints") expect_identical(sort(linted_files), sort(files)) - - expect_output( - lint_dir(the_dir, parse_settings = FALSE, show_progress = TRUE), - "======", - fixed = TRUE - ) }) test_that("lint all relevant directories in a package", { From 12147b4dde427a36e59c03eed9c484d881ee2b93 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 3 Aug 2024 16:34:22 +0200 Subject: [PATCH 2/3] update NEWS --- NEWS.md | 2 +- R/lint.R | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 140ee54ea..042c87f8e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -86,7 +86,7 @@ ## Notes -* All user-facing messages are now prepared using the `{cli}` package (#2418, @IndrajeetPatil). All messages have been reviewed and updated to be more informative and consistent. +* All user-facing messages (including progress bar) are now prepared using the `{cli}` package (#2418, @IndrajeetPatil). All messages have been reviewed and updated to be more informative and consistent. * {lintr} now depends on R version 4.0.0. It already does so implicitly due to recursive upstream dependencies requiring this version; we've simply made that dependency explicit and up-front (#2569, @MichaelChirico). # lintr 3.1.2 diff --git a/R/lint.R b/R/lint.R index 038253d5c..d9e135692 100644 --- a/R/lint.R +++ b/R/lint.R @@ -184,9 +184,7 @@ lint_dir <- function(path = ".", ..., lints <- flatten_lints(lapply( cli::cli_progress_along(files, name = "Running linters"), - function(idx) { - lint(files[idx], ..., parse_settings = FALSE, exclusions = exclusions) - } + function(idx) lint(files[idx], ..., parse_settings = FALSE, exclusions = exclusions) )) lints <- reorder_lints(lints) From e4a180aa1ceae33612093734ccd1d9fe55d8693e Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sat, 3 Aug 2024 16:49:58 +0200 Subject: [PATCH 3/3] Update NEWS.md --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 042c87f8e..0bddf2bcf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -86,7 +86,7 @@ ## Notes -* All user-facing messages (including progress bar) are now prepared using the `{cli}` package (#2418, @IndrajeetPatil). All messages have been reviewed and updated to be more informative and consistent. +* All user-facing messages (including progress bar) are now prepared using the `{cli}` package (#2418 and #2641, @IndrajeetPatil). All messages have been reviewed and updated to be more informative and consistent. * {lintr} now depends on R version 4.0.0. It already does so implicitly due to recursive upstream dependencies requiring this version; we've simply made that dependency explicit and up-front (#2569, @MichaelChirico). # lintr 3.1.2