Skip to contents

Checks that all defined/declared functions and data objects are used within the source file. Functions and data objects that are marked with @export are ignored.

Usage

unused_declared_object_linter()

Value

A custom linter function for use with r-lib/lintr.

Details

For use in rhino, see the Explanation: Rhino style guide to learn about the details.

Examples

# will produce lint
code <- "
#' @export
public_function <- function() {

}

private_function <- function() {

}

local_data <- \"A\"
"

lintr::lint(text = code, linters = unused_declared_object_linter())
#> ::warning file=<text>,line=7,col=1::file=<text>,line=7,col=1,[unused_declared_object_linter] Declared function/object unused.
#> ::warning file=<text>,line=11,col=1::file=<text>,line=11,col=1,[unused_declared_object_linter] Declared function/object unused.

# okay
code <- "
#' @export
public_function <- function() {
  some_variable <- local_data
  private_function()
}

private_function <- function() {

}

local_data <- \"A\"
"

lintr::lint(text = code, linters = unused_declared_object_linter())
#> ::warning file=<text>,line=4,col=3::file=<text>,line=4,col=3,[unused_declared_object_linter] Declared function/object unused.