Skip to contents

Check that all commas are followed by spaces, but do not have spaces before them.

Usage

commas_linter(allow_trailing = FALSE)

Arguments

allow_trailing

If TRUE, the linter allows a comma to be followed directly by a closing bracket without a space.

See also

Examples

# will produce lints
lint(
  text = "switch(op , x = foo, y = bar)",
  linters = commas_linter()
)
#> ::warning file=<text>,line=1,col=10::file=<text>,line=1,col=10,[commas_linter] Commas should never have a space before.

lint(
  text = "mean(x,trim = 0.2,na.rm = TRUE)",
  linters = commas_linter()
)
#> ::warning file=<text>,line=1,col=8::file=<text>,line=1,col=8,[commas_linter] Commas should always have a space after.
#> ::warning file=<text>,line=1,col=19::file=<text>,line=1,col=19,[commas_linter] Commas should always have a space after.

lint(
  text = "x[ ,, drop=TRUE]",
  linters = commas_linter()
)
#> ::warning file=<text>,line=1,col=3::file=<text>,line=1,col=3,[commas_linter] Commas should never have a space before.
#> ::warning file=<text>,line=1,col=5::file=<text>,line=1,col=5,[commas_linter] Commas should always have a space after.

lint(
  text = "x[1,]",
  linters = commas_linter()
)
#> ::warning file=<text>,line=1,col=5::file=<text>,line=1,col=5,[commas_linter] Commas should always have a space after.

# okay
lint(
  text = "switch(op, x = foo, y = bar)",
  linters = commas_linter()
)

lint(
  text = "switch(op, x = , y = bar)",
  linters = commas_linter()
)

lint(
  text = "mean(x, trim = 0.2, na.rm = TRUE)",
  linters = commas_linter()
)

lint(
  text = "a[1, , 2, , 3]",
  linters = commas_linter()
)

lint(
  text = "x[1,]",
  linters = commas_linter(allow_trailing = TRUE)
)