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

Escaped % being flagged as invalid when matched with other format with latest 0.85.1 #8124

Closed
rbuenviaje opened this issue Jun 8, 2020 · 1 comment · Fixed by #8126
Closed
Labels

Comments

@rbuenviaje
Copy link

PR #8042 Introduced a change that flagged mismatched format as an offense, but I believe it doesn't take into account the escaped %. Something like %% %{foo}s should be valid as it has a named component, but the first part is just escaping a % sign.

Expected behavior

No offense when pairing a named format with an escaped %. Other combinations with an escaped % may need to be checked.

Actual behavior

Offense flagged with Lint/FormatParameterMismatch: Format string is invalid because formatting sequence types (numbered, named or unnumbered) are mixed

Steps to reproduce the problem

Something like format('%%%<hex>02X', hex: 10) -> %0A should be valid. This format string does not throw errors when run.

RuboCop version

$ rubocop -V
0.85.1 (using Parser 2.7.1.3, rubocop-ast 0.0.3, running on ruby 2.6.4 x86_64-darwin18)
@koic koic added the bug label Jun 9, 2020
koic added a commit to koic/rubocop that referenced this issue Jun 9, 2020
…atch`

Fixes rubocop#8124.

This PR fixes a false positive for `Lint/FormatParameterMismatch`
using named parameters with escaped `%`.
@s-mage
Copy link

s-mage commented Jun 9, 2020

Got another false positive for this cop: "%{code} - %{message}" % { code: 42, message: "wut" }. If I understood correctly, this string has only named sequences.

bbatsov pushed a commit that referenced this issue Jun 9, 2020
Fixes #8124.

This PR fixes a false positive for `Lint/FormatParameterMismatch`
using named parameters with escaped `%`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants