diff --git a/NEWS.md b/NEWS.md index c6be365c5..64a2b7779 100644 --- a/NEWS.md +++ b/NEWS.md @@ -22,6 +22,8 @@ * `linters_with_defaults()` no longer erroneously marks linter factories as linters (#1725, @AshesITR). +* Row names for `available_linters()` data frame no longer have missing entries (#1781, @IndrajeetPatil). + ## Changes to defaults * Set the default for the `except` argument in `duplicate_argument_linter()` to `c("mutate", "transmute")`. diff --git a/R/linter_tags.R b/R/linter_tags.R index 209d6cb71..22d7ae205 100644 --- a/R/linter_tags.R +++ b/R/linter_tags.R @@ -87,6 +87,10 @@ build_available_linters <- function(available, package, tags, exclude_tags) { matches_exclude <- vapply(available_df$tags, function(linter_tags) any(linter_tags %in% exclude_tags), logical(1L)) available_df <- available_df[!matches_exclude, ] } + + # Due to removal of deprecated linters in the returned data frame, there can be gaps in row numbers. + # To avoid this inconsistency, regenerate row names. + rownames(available_df) <- seq(1L:nrow(available_df)) available_df } diff --git a/tests/testthat/test-linter_tags.R b/tests/testthat/test-linter_tags.R index e58612878..ffdbecddc 100644 --- a/tests/testthat/test-linter_tags.R +++ b/tests/testthat/test-linter_tags.R @@ -86,6 +86,14 @@ test_that("available_linters matches the set of linters available from lintr", { expect_identical(sort(linters_in_namespace), sort(exported_linters)) }) +test_that("rownames for available_linters data frame doesn't have missing entries", { + lintr_db <- available_linters() + expect_identical( + tail(rownames(lintr_db), 1L), + as.character(nrow(lintr_db)) + ) +}) + # See the roxygen helpers in R/linter_tags.R for the code used to generate the docs. # This test helps ensure the documentation is up to date with the available_linters() database test_that("lintr help files are up to date", {