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

Use {cli} for formatting condition messages #2418

Merged
merged 84 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
a680b56
start with backport linter
IndrajeetPatil Dec 11, 2023
9f578d2
cover addin and settings
IndrajeetPatil Dec 12, 2023
d437154
Update DESCRIPTION
IndrajeetPatil Dec 12, 2023
d69c1af
import cli functions
IndrajeetPatil Dec 13, 2023
b39be67
undo snapshot tests
IndrajeetPatil Dec 14, 2023
d6c3cec
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Dec 14, 2023
2a797f8
address initial review comments
IndrajeetPatil Dec 14, 2023
f885355
fix test
IndrajeetPatil Dec 14, 2023
474b866
improve error message
IndrajeetPatil Dec 14, 2023
c406b7a
delint
IndrajeetPatil Dec 14, 2023
6fe595f
use cli in comments
IndrajeetPatil Dec 14, 2023
20d2253
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Dec 15, 2023
793277f
Update linter_tags.R
IndrajeetPatil Dec 15, 2023
36f55d2
fix test and delint
IndrajeetPatil Dec 15, 2023
cd8baac
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Dec 25, 2023
72bb926
more conversions
IndrajeetPatil Dec 28, 2023
176fd17
conversions in undesirables
IndrajeetPatil Dec 28, 2023
15bf9a1
Update xml_nodes_to_lints.R
IndrajeetPatil Dec 28, 2023
dc11fcd
start with settings
IndrajeetPatil Dec 30, 2023
d3c53f5
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Feb 22, 2024
807f41e
merge with main
IndrajeetPatil Mar 23, 2024
24248f0
fix bad merge
IndrajeetPatil Mar 23, 2024
b65b498
convert two more warnings to use cli
IndrajeetPatil Mar 23, 2024
316e9ca
resolve merge conflicts
IndrajeetPatil Mar 23, 2024
0fda18e
fix lints and cover more warnings with cli
IndrajeetPatil Mar 23, 2024
77846ca
remove lints
IndrajeetPatil Mar 23, 2024
6c69858
don't test full message with snapshot
IndrajeetPatil Mar 23, 2024
6ffc60e
Update settings.R
IndrajeetPatil Mar 29, 2024
8e3c480
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Mar 29, 2024
7231b53
fix tests
IndrajeetPatil Mar 29, 2024
2c7baa9
convert two more settings messages
IndrajeetPatil Mar 30, 2024
1e54de1
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Mar 30, 2024
e5a4d85
convert exclude messages
IndrajeetPatil Mar 31, 2024
eed9b50
fix new lints
IndrajeetPatil Mar 31, 2024
851030c
two more error messages
IndrajeetPatil Mar 31, 2024
9889933
two more error messages
IndrajeetPatil Apr 1, 2024
04c45d4
more messages in lint
IndrajeetPatil Apr 1, 2024
55e078c
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Apr 2, 2024
eb765be
pick a few low-hanging fruits
IndrajeetPatil Apr 3, 2024
e2b8570
more settings
IndrajeetPatil Apr 5, 2024
56dd7e0
converting more errors to cli from settings
IndrajeetPatil Apr 6, 2024
eaf754e
rest of it
IndrajeetPatil Apr 7, 2024
eed787f
fix lint
IndrajeetPatil Apr 7, 2024
d9a8356
Update NEWS.md
IndrajeetPatil Apr 7, 2024
0a4d970
update checks dots error message
IndrajeetPatil Apr 7, 2024
561bb19
fix lint
IndrajeetPatil Apr 7, 2024
94a35d0
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Apr 7, 2024
766f1bb
Update backport_linter.R
IndrajeetPatil Apr 7, 2024
1474bd0
another round of refinement
IndrajeetPatil Apr 7, 2024
7e1ac5a
use more classes
IndrajeetPatil Apr 7, 2024
4472987
address review comments
IndrajeetPatil Apr 7, 2024
38dffd9
address a few of the review comments
IndrajeetPatil Apr 13, 2024
31511e5
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Apr 13, 2024
34e92af
not needed anymore; testthat 3.2.1 needs waldo >= 0.5
IndrajeetPatil Apr 13, 2024
7e5865b
use internal argument for bug reports URL
IndrajeetPatil Apr 14, 2024
d2c359d
narrower line
MichaelChirico Apr 14, 2024
a6abaaa
fix merge conflict
IndrajeetPatil Apr 20, 2024
12f17cb
favour str markup over sQuote
IndrajeetPatil Apr 20, 2024
a564a1e
don't nest cli exceptions; formatting is off then
IndrajeetPatil Apr 20, 2024
4edc5c9
Update R/xp_utils.R
IndrajeetPatil Apr 20, 2024
d1f1fe0
fix test
IndrajeetPatil Apr 20, 2024
ed55121
use obj_type_friendly marker
IndrajeetPatil Apr 20, 2024
b17a4ed
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil May 7, 2024
497e2d2
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil May 11, 2024
4d3362a
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil May 22, 2024
500df0a
Update `default_undesirable_functions()` list
IndrajeetPatil May 25, 2024
8284a58
remove unneeded nolint directives
IndrajeetPatil May 25, 2024
dd38ec8
Revert "remove unneeded nolint directives"
IndrajeetPatil May 27, 2024
17cd8d7
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil May 27, 2024
1dd21fc
remove unnecessary assignments
IndrajeetPatil May 27, 2024
df4bd84
nolint line length lint
IndrajeetPatil May 27, 2024
1eb3c85
Update expect_lint.R
IndrajeetPatil May 27, 2024
166b472
Apply suggestions from code review
IndrajeetPatil May 28, 2024
300b636
cli 3.4 is needed
IndrajeetPatil May 28, 2024
5811919
get rid of unnecessary `toString()`
IndrajeetPatil May 29, 2024
c778935
add TODOs to nolint directives
IndrajeetPatil May 29, 2024
febdf0a
Use cli_abort_internal
IndrajeetPatil May 29, 2024
11f5ab5
fix tests
IndrajeetPatil May 29, 2024
dd20746
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil May 29, 2024
0a8881e
Update xp_utils.R
IndrajeetPatil May 29, 2024
776408d
use pluralization
IndrajeetPatil May 29, 2024
767ab96
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Jun 8, 2024
7ce0482
Merge branch 'main' into f-2386-use-cli
IndrajeetPatil Jun 9, 2024
9dcbbc6
use more specific error message stem
IndrajeetPatil Jun 11, 2024
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Depends:
R (>= 3.6)
Imports:
backports (>= 1.1.7),
cli,
codetools,
cyclocomp,
digest,
Expand All @@ -36,7 +37,6 @@ Imports:
xmlparsedata (>= 1.0.5)
Suggests:
bookdown,
cli,
httr (>= 1.2.1),
jsonlite,
patrick (>= 0.2.0),
Expand Down
12 changes: 7 additions & 5 deletions R/addins.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# nocov start
addin_lint <- function() {
if (!requireNamespace("rstudioapi", quietly = TRUE)) {
stop("'rstudioapi' is required for add-ins.", call. = FALSE)
cli::cli_abort("{.pkg rstudioapi} is required for add-ins.")
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
}
filename <- rstudioapi::getSourceEditorContext()
if (filename$path == "") {
return("Current source has no path. Please save before continue")
return("Current source has no path. Please save before continue.")
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
}

config_file <- (get("find_config", asNamespace("lintr")))(filename$path)
Expand All @@ -16,7 +16,7 @@ addin_lint <- function() {
config_linters <- config[["linters"]]
}
linters <- if (length(config_linters) == 0L) {
message("No configuration found. Using default linters.")
cli::cli_inform("No configuration found. Using default linters.")
default_linters
} else {
eval(parse(text = config_linters))
Expand All @@ -27,12 +27,14 @@ addin_lint <- function() {

addin_lint_package <- function() {
if (!requireNamespace("rstudioapi", quietly = TRUE)) {
stop("'rstudioapi' is required for add-ins.", call. = FALSE)
cli::cli_abort("{.pkg rstudioapi} is required for add-ins.")
}
project <- rstudioapi::getActiveProject()
project_path <- if (is.null(project)) getwd() else project

if (is.null(project)) message("No project found, passing current directory")
if (is.null(project)) {
cli::cli_inform("No project found, passing current directory")
}

lintr::lint_package(project_path)
}
Expand Down
9 changes: 3 additions & 6 deletions R/backport_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ normalize_r_version <- function(r_version) {
version_names <- c("devel", "release", paste0("oldrel-", seq_len(length(minor_versions) - 2L)))
if (!r_version %in% version_names) {
# This can only trip if e.g. oldrel-99 is requested
stop("`r_version` must be a version number or one of ", toString(sQuote(version_names)), call. = FALSE)
cli::cli_abort("{.var r_version} must be a version number or one of {toString(sQuote(version_names))}")
IndrajeetPatil marked this conversation as resolved.
Show resolved Hide resolved
}
requested_version <- minor_versions[match(r_version, table = version_names)]
available_patches <- all_versions[startsWith(all_versions, requested_version)]
Expand All @@ -102,13 +102,10 @@ normalize_r_version <- function(r_version) {
} else if (is.character(r_version)) {
r_version <- R_system_version(r_version, strict = TRUE)
} else if (!inherits(r_version, "R_system_version")) {
stop("`r_version` must be a R version number, returned by R_system_version(), or a string.", call. = FALSE)
cli::cli_abort("{.var r_version} must be an R version number, returned by {.fun R_system_version}, or a string.")
}
if (r_version < "3.0.0") {
warning(
"It is not recommended to depend on an R version older than 3.0.0. Resetting 'r_version' to 3.0.0.",
call. = FALSE
)
cli::cli_warn("Depending on an R version older than 3.0.0 is not recommended. Resetting {.var r_version} to 3.0.0.")
r_version <- R_system_version("3.0.0")
}
r_version
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/backport_linter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# backport_linter produces error when R version misspecified

Code
lint(text = "numToBits(2)", linters = backport_linter(420L))
Condition
Error in `normalize_r_version()`:
! `r_version` must be an R version number, returned by `R_system_version()`, or a string.

10 changes: 10 additions & 0 deletions tests/testthat/_snaps/settings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# read_config_file() bubbles up warnings helpfully, without erroring (#2253)

Code
lint_dir()
Condition
Warning:
Warning encountered while loading config:
Warning from config setting 'linters' in 'NULL':
Depending on an R version older than 3.0.0 is not recommended. Resetting `r_version` to 3.0.0.

5 changes: 2 additions & 3 deletions tests/testthat/test-backport_linter.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
test_that("backport_linter produces error when R version misspecified", {
expect_error(
expect_snapshot(
lint(text = "numToBits(2)", linters = backport_linter(420L)),
"`r_version` must be a R version number, returned by R_system_version(), or a string.",
fixed = TRUE
error = TRUE
)
})

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ test_that("read_config_file() bubbles up warnings helpfully, without erroring (#
withr::local_dir(withr::local_tempdir())

writeLines("a <- 1", "aaa.R")
expect_warning(lint_dir(), "Warning from config setting 'linters'.*Resetting 'r_version' to 3.0.0")
expect_snapshot(lint_dir())
})

test_that("perl-only regular expressions are accepted in config", {
Expand Down
Loading