Skip to content

Commit

Permalink
allow multiple naming styles if user really wants them (r-lib#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
infotroph committed Aug 13, 2018
1 parent baddc5b commit c8d398b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# lintr 1.0.2.9000 #
* Fixed error when object_name_linter is passed multiple styles (#341, @infotroph)
* Config files are now also searched for in the users' home directory (#266, @randy3k)
* Fixed crash caused by ambiguous cache file paths (#212, @fangly).
* RStudio addins to lint current source and project (fixes #264, @JhossePaul)
Expand Down
4 changes: 2 additions & 2 deletions R/object_name_linters.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ object_name_linter <- function(style = "snake_case") {
make_object_linter(
function(source_file, token) {
name <- unquote(token[["text"]])
if (!matches_styles(name, style)) {
if (!any(matches_styles(name, style))) {
object_lint(
source_file,
token,
sprintf("Variable or function name should be %s.", style),
sprintf("Variable or function name should be %s.", paste(style, collapse = " or ")),
"object_name_linter"
)
}
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-object_name_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,14 @@ test_that("linter returns correct linting", {
expect_lint("pack:::camelCase", NULL, linter)
expect_lint("a(camelCase = 1)", NULL, linter)
})

test_that("linter accepts vectors of styles", {
msg <- "Variable or function name should be lowerCamelCase or dotted.case."
linter <- object_name_linter(style=c("lowerCamelCase", "dotted.case"))

expect_lint(
c("var.one <- 1", "varTwo <- 2", "var_three <- 3"),
list(message=msg, line_number=3L, column_number=1L),
linter
)
})

0 comments on commit c8d398b

Please sign in to comment.