Skip to content

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

Closed
@rbuenviaje

Description

@rbuenviaje

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)

Activity

s-mage

s-mage commented on Jun 9, 2020

@s-mage

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

added a commit that references this issue on Jun 9, 2020

[Fix #8124] Fix a false positive for `Lint/FormatParameterMismatch`

3b0552b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @koic@s-mage@rbuenviaje

      Issue actions

        Escaped % being flagged as invalid when matched with other format with latest 0.85.1 · Issue #8124 · rubocop/rubocop