Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing row names in available_linters() #1813

Merged
merged 5 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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