Skip to contents

Check for an inconsistent number of arguments or arguments with incompatible types (for literal arguments) in sprintf() calls.

Usage

sprintf_linter()

Details

gettextf() calls are also included, since gettextf() is a thin wrapper around sprintf().

See also

linters for a complete list of linters available in lintr.

Examples

# will produce lints
lint(
  text = 'sprintf("hello %s %s %d", x, y)',
  linters = sprintf_linter()
)
#> <text>:1:1: warning: [sprintf_linter] too few arguments
#> sprintf("hello %s %s %d", x, y)
#> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

# okay
lint(
  text = 'sprintf("hello %s %s %d", x, y, z)',
  linters = sprintf_linter()
)
#>  No lints found.

lint(
  text = 'sprintf("hello %s %s %d", x, y, ...)',
  linters = sprintf_linter()
)
#>  No lints found.