r-lib / lintr

Static Code Analysis for R
https://lintr.r-lib.org
Other
1.19k stars 184 forks source link

Introduce `deprecated_function_linter()` #1386

Open IndrajeetPatil opened 2 years ago

IndrajeetPatil commented 2 years ago

As discussed in https://github.com/r-lib/lintr/pull/1377.

This linter will mostly centre around packages that assign lifecycle stages for functions (testthat, tidyverse, etc.).

AshesITR commented 2 years ago

Is there maybe a way to programmatically extract this lifecycle information from packages?

IndrajeetPatil commented 2 years ago

Yeah, I was thinking the same.

Probably via .Rd files because a function is marked as deprecated using the following code in the docs:

#' `r lifecycle::badge("deprecated")`
AshesITR commented 2 years ago

It seems the first call in the function should also be to lifecycle.

AshesITR commented 2 years ago

Seems like if we loadNamespace() the required packages, we can inspect the functions to see if their call graph unconditionally hits a (known) deprecation function:

body(testthat::expect_that)[[2]][[1]]
#> edition_deprecate
body(survival::survConcordance)[[3]][[1]]
#> .Deprecated
body(tibble::data_frame)[[2]][[1]]
#> deprecate_warn
AshesITR commented 2 years ago

I just discovered lifecycle::lint_lifecycle() Maybe we can convince lifecycle to export lifecycle_linter()? That means the deprecated_function_linter() could focus on other lifecycle management styles, e.g. .Deprecated() or the style used in testthat.

IndrajeetPatil commented 4 months ago

A few resources to consider here, which would help us with implementation:

https://github.com/r-lib/pkgdown/blob/0ba8cb6c68c098a0d1d780052758da5ac9f83e3a/R/package.R#L188

https://github.com/moodymudskipper/now