diff --git a/DESCRIPTION b/DESCRIPTION index 198c6c95e..e800ae9d4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: lintr Title: Static R Code Analysis -Version: 1.0.0 +Version: 1.0.0.9000 Authors@R: person("Jim", "Hester", email = "james.f.hester@gmail.com", role = c("aut", "cre")) URL: https://github.com/jimhester/lintr BugReports: https://github.com/jimhester/lintr/issues diff --git a/NEWS.md b/NEWS.md index acacf05e3..8b78839dc 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# lintr 1.0.0.9000 # + +* Commas linter handles missing arguments calls properly (#145) + # lintr 1.0.0 # * bugfix to work with testthat 1.0.0 diff --git a/R/commas_linter.R b/R/commas_linter.R index 657bab383..fba60174e 100644 --- a/R/commas_linter.R +++ b/R/commas_linter.R @@ -32,7 +32,8 @@ commas_linter <- function(source_file) { start_of_line <- re_matches(line, rex(start, spaces, ",")) - if (has_token && !start_of_line) { + empty_comma <- substr(line, comma_loc - 2L, comma_loc - 1L) %==% ", " + if (has_token && !start_of_line && !empty_comma) { lints[[length(lints) + 1L]] <- Lint( diff --git a/tests/testthat/test-commas_linter.R b/tests/testthat/test-commas_linter.R index e917d0756..3dcad6a0e 100644 --- a/tests/testthat/test-commas_linter.R +++ b/tests/testthat/test-commas_linter.R @@ -35,4 +35,12 @@ test_that("returns the correct linting", { expect_lint("\"fun(1 ,1)\"", NULL, commas_linter) + + expect_lint("a[1, , 2]", + NULL, + commas_linter) + + expect_lint("a[1, , 2, , 3]", + NULL, + commas_linter) })