You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Lint/FormatParameterMismatch cop generates false positives for format strings with "wildcard" width and precision. From the printf(3) man page:
A field width or precision, or both, may be indicated by an asterisk '*' or an asterisk followed
by one or more decimal digits and a '$' instead of a digit string. In this case, an int
argument supplies the field width or precision. A negative field width is treated as a left
adjustment flag followed by a positive field width; a negative precision is treated as though
it were missing. If a single format directive mixes positional (nn$) and non-positional argu-
ments, the results are undefined.
Example
classRuboCop::Sprintfdeftestsprintf("%*.*s\n",10,10,'this is a test')endend
Expected behavior
No error should be generated
Actual behavior
It will complain that argument count is wrong (3 instead of 2)
Steps to reproduce the problem
Save the above example as rubocop_sprintf.rb
⇨ rubocop ./rubocop_sprintf.rb
Inspecting 1 file
W
Offenses:
rubocop_sprintf.rb:3:5: W: Number of arguments (3) to sprintf doesn't match the number of fields (2). sprintf("%*.*s\n", 10, 10, 'this is a test') ^^^^^^^
The text was updated successfully, but these errors were encountered:
cybercode
changed the title
False positive on sprintf with width or precision = *
False positive on sprintf with width and precision = *Jul 6, 2017
cybercode
changed the title
False positive on sprintf with width and precision = *
False positive on sprintf with "asterisk" ('*') width and precision
Jul 6, 2017
The
Lint/FormatParameterMismatch
cop generates false positives for format strings with "wildcard" width and precision. From theprintf(3)
man page:Example
Expected behavior
No error should be generated
Actual behavior
It will complain that argument count is wrong (3 instead of 2)
Steps to reproduce the problem
Save the above example as
rubocop_sprintf.rb
RuboCop version
The text was updated successfully, but these errors were encountered: