Skip to content
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# lintr (development version)

## Bug fixes

* `object_name_linter()` no longer errors when user-supplied `regexes=` have capture groups (#2188, @MichaelChirico).

## New and improved features

* More helpful errors for invalid configs (#2253, @MichaelChirico).
Expand Down
9 changes: 7 additions & 2 deletions R/object_name_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,13 @@ object_name_linter <- function(styles = c("snake_case", "symbols"), regexes = ch
check_style <- function(nms, style, generics = character()) {
conforming <- re_matches(nms, style)

# mark empty names and NA names as conforming
conforming[!nzchar(nms) | is.na(conforming)] <- TRUE
# style has capture group(s)
if (is.data.frame(conforming)) {
# if any group is missing, all groups are missing, so just check the first column
conforming <- !is.na(conforming[[1L]])
}
# mark empty or NA names as conforming
conforming <- is.na(nms) | !nzchar(nms) | conforming

if (!all(conforming)) {
possible_s3 <- re_matches(
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-object_name_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,8 @@ test_that("function shorthand also lints", {

expect_lint("aBc <- \\() NULL", "function name style", object_name_linter())
})

test_that("capture groups in style are fine", {
expect_lint("a <- 1\nab <- 2", NULL, object_name_linter(regexes = c(capture = "^(a)")))
expect_lint("ab <- 1\nabc <- 2", NULL, object_name_linter(regexes = c(capture = "^(a)(b)")))
})