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

Yet another Lint/FormatParameterMismatch false positive related to string interpolation #12672

Open
zor-el opened this issue Feb 4, 2024 · 1 comment
Labels

Comments

@zor-el
Copy link

zor-el commented Feb 4, 2024

A similar issue (#11521) appears to have been addressed, but it didn't seem to cover this type of case:

# frozen_string_literal: true

prefix = 'alert'
message = 'some message'
puts format('%10s: %s', prefix, message)
padding = 10
puts format("%#{padding}s: %s", prefix, message)

The format(...) invocations are equivalent, yet the latter causes an offense:

... W: Lint/FormatParameterMismatch: Format string is invalid because formatting sequence types (numbered, named or unnumbered) are mixed.
puts format("%#{padding}s: %s", prefix, message)
     ^^^^^^

Expected behavior

No Lint/FormatParameterMismatch offense reported.

Actual behavior

See above

Steps to reproduce the problem

See above

RuboCop version

Tested with:

1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.2.2) [x86_64-darwin21]
1.57.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.2.2) [x86_64-darwin21]
1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 2.7.8) [x86_64-darwin21]
@zor-el zor-el changed the title Yet another Lint/FormatParameterMismatch interpolation-related false positive Yet another Lint/FormatParameterMismatch false positive related to string interpolation Feb 4, 2024
@koic koic added the bug label Feb 5, 2024
@pboling
Copy link
Contributor

pboling commented Mar 11, 2024

I am also experiencing this issue:

key_offset = 20
val_offset = 20
sprintf("| %-#{key_offset}s | %-#{val_offset}s |", key, value)

RuboCop says:

    Lint/FormatParameterMismatch: Number of arguments (2) to `sprintf` doesn't match the number of fields (1).

Version: 1.57.2 - old I know, but since this is an open issue, I'm posting it to show another example of the failure, which is probably the same regardless of version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants