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

Allow passing multiple styles to object_name_linter #342

Merged
merged 2 commits into from
Aug 13, 2018
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
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 vector 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
)
})