|
| 1 | + |
| 2 | + |
| 3 | +undesirable_functions <- |
| 4 | + lintr::default_undesirable_functions |> |
| 5 | + lintr::modify_defaults( |
| 6 | + |
| 7 | + # following https://github.com/r-lib/devtools/blob/2aa51ef/.lintr.R: |
| 8 | + # Base messaging |
| 9 | + "message" = "use cli::cli_inform()", |
| 10 | + "warning" = "use cli::cli_warn()", |
| 11 | + "stop" = "use cli::cli_abort()", |
| 12 | + # rlang messaging |
| 13 | + "inform" = "use cli::cli_inform()", |
| 14 | + "warn" = "use cli::cli_warn()", |
| 15 | + "abort" = "use cli::cli_abort()", |
| 16 | + # older cli |
| 17 | + "cli_alert_danger" = "use cli::cli_inform()", |
| 18 | + "cli_alert_info" = "use cli::cli_inform()", |
| 19 | + "cli_alert_success" = "use cli::cli_inform()", |
| 20 | + "cli_alert_warning" = "use cli::cli_inform()", |
| 21 | + |
| 22 | + library = paste( |
| 23 | + "\nuse `::`, `usethis::use_import_from()`, or `withr::local_package()`", |
| 24 | + "instead of modifying the global search path.", |
| 25 | + "\nSee:\n", |
| 26 | + "<https://r-pkgs.org/code.html#sec-code-r-landscape> and\n", |
| 27 | + "<https://r-pkgs.org/testing-design.html#sec-testing-design-self-contained>", |
| 28 | + "\nfor more details." |
| 29 | + ), |
| 30 | + |
| 31 | + structure = NULL, |
| 32 | + browser = NULL |
| 33 | + # see https://github.com/r-lib/lintr/pull/2227 and |
| 34 | + # rebuttal https://github.com/r-lib/lintr/pull/2227#issuecomment-1800302675 |
| 35 | + |
| 36 | + ) |
| 37 | + |
| 38 | +# define snake_case with uppercase acronyms allowed; |
| 39 | +# see https://github.com/r-lib/lintr/issues/2844 for details: |
| 40 | +withr::local_package("rex") |
| 41 | +snake_case_ACROs1 <- rex::rex( |
| 42 | + start, |
| 43 | + maybe("."), |
| 44 | + list(some_of(upper), maybe("s"), zero_or_more(digit)) %or% list(some_of(lower), zero_or_more(digit)), |
| 45 | + zero_or_more( |
| 46 | + "_", |
| 47 | + list(some_of(upper), maybe("s"), zero_or_more(digit)) %or% list(some_of(lower), zero_or_more(digit)) |
| 48 | + ), |
| 49 | + end |
| 50 | +) |
| 51 | + |
| 52 | +linters <- lintr::linters_with_defaults( |
| 53 | + return_linter = NULL, |
| 54 | + trailing_whitespace_linter = NULL, |
| 55 | + lintr::redundant_equals_linter(), |
| 56 | + lintr::pipe_consistency_linter(pipe = "|>"), |
| 57 | + lintr::object_name_linter( |
| 58 | + regexes = c(snake_case_ACROs1 = snake_case_ACROs1) |
| 59 | + ), |
| 60 | + lintr::undesirable_function_linter( |
| 61 | + fun = undesirable_functions, |
| 62 | + symbol_is_undesirable = TRUE |
| 63 | + ) |
| 64 | +) |
| 65 | + |
| 66 | +# prevent warnings from lintr::read_settings: |
| 67 | +rm(undesirable_functions) |
| 68 | +rm(snake_case_ACROs1) |
| 69 | +exclusions <- list( |
| 70 | + `data-raw` = list( |
| 71 | + pipe_consistency_linter = Inf, |
| 72 | + undesirable_function_linter = Inf |
| 73 | + ), |
| 74 | + vignettes = list( |
| 75 | + undesirable_function_linter = Inf, |
| 76 | + object_name_linter = Inf |
| 77 | + ), |
| 78 | + "inst/examples" = list( |
| 79 | + undesirable_function_linter = Inf |
| 80 | + ), |
| 81 | + "tests/testthat.R" = list( |
| 82 | + undesirable_function_linter = Inf |
| 83 | + ) |
| 84 | + |
| 85 | +) |
0 commit comments