Skip to content

Commit cbd0619

Browse files
Make cyclocomp_linter() optional (#2555)
* Make `cyclocomp_linter()` optional closes #2554 * update NAMESPACE * error if cyclocomp is not installed * Update cyclocomp_linter.R * more conditional skips * Update error message * Update NEWS.md * Update NEWS.md Co-authored-by: Michael Chirico <[email protected]> * remove unnecessary skip * ignore rd xref note * fix file ext * Revert "fix file ext" This reverts commit c625249. * Revert "ignore rd xref note" This reverts commit baf9512. * fix Rd issue * fix rd issue again * Update lint.yaml * does clearing cache first help? * Revert "does clearing cache first help?" This reverts commit 1a07a08. * fix broken test * remove cyclocomp from default linter tests --------- Co-authored-by: Michael Chirico <[email protected]>
1 parent 8d310a7 commit cbd0619

File tree

16 files changed

+36
-24
lines changed

16 files changed

+36
-24
lines changed

.github/workflows/lint.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
- uses: r-lib/actions/setup-r-dependencies@v2
2222
with:
2323
extra-packages: |
24+
any::cyclocomp
2425
r-lib/lintr
2526
local::.
2627
needs: lint

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Depends:
2525
Imports:
2626
backports (>= 1.1.7),
2727
codetools,
28-
cyclocomp,
2928
digest,
3029
glue,
3130
knitr,
@@ -37,6 +36,7 @@ Imports:
3736
Suggests:
3837
bookdown,
3938
cli,
39+
cyclocomp,
4040
jsonlite,
4141
patrick (>= 0.2.0),
4242
rlang,

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ export(with_id)
171171
export(xml_nodes_to_lints)
172172
export(xp_call_name)
173173
export(yoda_test_linter)
174-
importFrom(cyclocomp,cyclocomp)
175174
importFrom(glue,glue)
176175
importFrom(glue,glue_collapse)
177176
importFrom(rex,character_class)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* `extraction_operator_linter()` is deprecated. Although switching from `$` to `[[` has some robustness benefits for package code, it can lead to non-idiomatic code in many contexts (e.g. R6 classes, Shiny applications, etc.) (#2409, @IndrajeetPatil). To enable the detection of the `$` operator for extraction through partial matching, use `options(warnPartialMatchDollar = TRUE)`.
1616
* `unnecessary_nested_if_linter()` is deprecated and subsumed into the new/more general `unnecessary_nesting_linter()`.
1717
* Drop support for posting GitHub comments from inside GitHub comment bot, Travis, Wercker, and Jenkins CI tools (spurred by #2148, @MichaelChirico). We rely on GitHub Actions for linting in CI, and don't see any active users relying on these alternatives. We welcome and encourage community contributions to get support for different CI system going again.
18+
* `cyclocomp_linter()` is no longer part of the default linters (#2555, @IndrajeetPatil) because the tidyverse style guide doesn't contain any guidelines on meeting certain complexity requirements. Note that users with `cyclocomp_linter()` in their configs may now need to install {cyclocomp} intentionally, in particular in CI/CD pipelines.
1819

1920
## Bug fixes
2021

R/cyclocomp_linter.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#' Cyclomatic complexity linter
22
#'
3-
#' Check for overly complicated expressions. See [cyclocomp::cyclocomp()].
3+
#' Check for overly complicated expressions. See `cyclocomp()` function from `{cyclocomp}`.
44
#'
5-
#' @param complexity_limit Maximum cyclomatic complexity, default 15. Expressions more complex
6-
#' than this are linted. See [cyclocomp::cyclocomp()].
5+
#' @param complexity_limit Maximum cyclomatic complexity, default `15`. Expressions more complex
6+
#' than this are linted.
77
#'
8-
#' @examples
8+
#' @examplesIf requireNamespace("cyclocomp", quietly = TRUE)
99
#' # will produce lints
1010
#' lint(
1111
#' text = "if (TRUE) 1 else 2",
@@ -23,6 +23,15 @@
2323
#' @export
2424
cyclocomp_linter <- function(complexity_limit = 15L) {
2525
Linter(linter_level = "expression", function(source_expression) {
26+
# nocov start
27+
if (!requireNamespace("cyclocomp", quietly = TRUE)) {
28+
cli::cli_abort(c(
29+
"Cyclocomp complexity is computed using {.fn cyclocomp::cyclocomp}.",
30+
i = "Please install the needed {.pkg cyclocomp} package."
31+
))
32+
}
33+
# nocov end
34+
2635
complexity <- try_silently(
2736
cyclocomp::cyclocomp(parse(text = source_expression$content))
2837
)

R/lintr-package.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"_PACKAGE"
99

1010
## lintr namespace: start
11-
#' @importFrom cyclocomp cyclocomp
1211
#' @importFrom glue glue glue_collapse
1312
#' @importFrom rex rex regex re_matches re_substitutes character_class
1413
#' @importFrom stats na.omit

R/zzz.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ default_linters <- modify_defaults(
1717
brace_linter(),
1818
commas_linter(),
1919
commented_code_linter(),
20-
cyclocomp_linter(),
2120
equals_na_linter(),
2221
function_left_parentheses_linter(),
2322
indentation_linter(),

inst/lintr/linters.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ conjunct_test_linter,package_development best_practices readability configurable
1717
consecutive_assertion_linter,style readability consistency
1818
consecutive_mutate_linter,consistency readability configurable efficiency
1919
consecutive_stopifnot_linter,style readability consistency deprecated
20-
cyclocomp_linter,style readability best_practices default configurable
20+
cyclocomp_linter,style readability best_practices configurable
2121
duplicate_argument_linter,correctness common_mistakes configurable
2222
empty_assignment_linter,readability best_practices
2323
equals_na_linter,robustness correctness common_mistakes default

man/cyclocomp_linter.Rd

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/default_linters.Rd

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)