Skip to content

Commit

Permalink
Fix missing row names in available_linters() (#1813)
Browse files Browse the repository at this point in the history
* Fix missing row names in `available_linters()`

Closes #1781

* Update linter_tags.R

* add another test

* address review comments

* reword NEWS bullet

Co-authored-by: AshesITR <alexander.rosenstock@web.de>
  • Loading branch information
IndrajeetPatil and AshesITR authored Dec 8, 2022
1 parent a936cf6 commit a41b065
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

* `linters_with_defaults()` no longer erroneously marks linter factories as linters (#1725, @AshesITR).

* Row names for `available_linters()` data frame are now contiguous (#1781, @IndrajeetPatil).

## Changes to defaults

* Set the default for the `except` argument in `duplicate_argument_linter()` to `c("mutate", "transmute")`.
Expand Down
4 changes: 4 additions & 0 deletions R/linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) <- NULL
available_df
}

Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-linter_tags.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ 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))
)

lintr_db2 <- available_linters(exclude_tags = NULL)
expect_identical(
tail(rownames(lintr_db2), 1L),
as.character(nrow(lintr_db2))
)
})

# 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", {
Expand Down

0 comments on commit a41b065

Please sign in to comment.