Skip to content

Commit 308be5b

Browse files
add a test to ensure inst/lintr/linters.csv is up to date (#932)
* add a test to ensure inst/lintr/linters.csv is up to date * new test vs getNamespaceExports Co-authored-by: AshesITR <[email protected]>
1 parent dfe9b52 commit 308be5b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

R/object_name_linters.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ object_lint2 <- function(expr, source_file, message) {
144144
)
145145
}
146146

147-
make_object_linter <- function(fun, name = linter_auto_name()) {
147+
object_linter_factory <- function(fun, name = linter_auto_name()) {
148148
force(name)
149149
Linter(function(source_file) {
150150

@@ -330,7 +330,7 @@ regexes_rd <- toString(paste0("\\sQuote{", names(style_regexes), "}"))
330330
#' @seealso [linters] for a complete list of linters available in lintr.
331331
#' @export
332332
object_length_linter <- function(length = 30L) {
333-
make_object_linter(function(source_file, token) {
333+
object_linter_factory(function(source_file, token) {
334334
if (nchar(token$text) > length) {
335335
object_lint(
336336
source_file,

R/path_linters.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ split_path <- function(path, sep="/|\\\\") {
139139
}
140140

141141
#' @include utils.R
142-
make_path_linter <- function(path_function, message, linter, name = linter_auto_name()) {
142+
path_linter_factory <- function(path_function, message, linter, name = linter_auto_name()) {
143143
force(name)
144144
Linter(function(source_file) {
145145
lapply(
@@ -184,7 +184,7 @@ make_path_linter <- function(path_function, message, linter, name = linter_auto_
184184
#' @seealso [linters] for a complete list of linters available in lintr.
185185
#' @export
186186
absolute_path_linter <- function(lax = TRUE) {
187-
make_path_linter(
187+
path_linter_factory(
188188
path_function = function(path) {
189189
is_absolute_path(path) && is_valid_long_path(path, lax)
190190
},
@@ -201,7 +201,7 @@ absolute_path_linter <- function(lax = TRUE) {
201201
#' @seealso [linters] for a complete list of linters available in lintr.
202202
#' @export
203203
nonportable_path_linter <- function(lax = TRUE) {
204-
make_path_linter(
204+
path_linter_factory(
205205
path_function = function(path) {
206206
is_path(path) && is_valid_long_path(path, lax) && path != "/" &&
207207
re_matches(path, rex(one_of("/", "\\")))

tests/testthat/test-linter_tags.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ test_that("default_linters and default tag match up", {
1818
tagged_default <- avail[["linter"]][vapply(avail[["tags"]], function(tags) "default" %in% tags, logical(1L))]
1919
expect_setequal(tagged_default, names(default_linters))
2020
})
21+
22+
test_that("available_linters matches the set of linters available from lintr", {
23+
lintr_db <- available_linters()
24+
all_linters <- ls(asNamespace("lintr"), pattern = "_linter$")
25+
# ensure that the contents of inst/lintr/linters.csv covers all _linter objects in our namespace
26+
expect_setequal(lintr_db$linter, all_linters)
27+
# ensure that all _linter objects in our namespace are also exported
28+
expect_setequal(all_linters, grep("_linter$", getNamespaceExports("lintr"), value = TRUE))
29+
})

0 commit comments

Comments
 (0)