ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Rule duplication `F509` and `PLE1300`

Open dhruvmanila opened this issue 1 year ago • 3 comments

Both rules check for invalid format character in % format style string.

The implementation is almost the same:

F509

https://github.com/astral-sh/ruff/blob/1f748b89ca73361146508b6f0af9afc756dc9cb2/crates/ruff_linter/src/checkers/ast/analyze/expression.rs#L1087-L1100

PLE1300

https://github.com/astral-sh/ruff/blob/1f748b89ca73361146508b6f0af9afc756dc9cb2/crates/ruff_linter/src/rules/pylint/rules/bad_string_format_character.rs#L117-L125

There's one difference which can be noticed when an implicitly concatenated string is used. F509 looks at the concatenated string while PLE1300 looks at each part of an implicitly concatenated string. Refer to https://play.ruff.rs/6efd9945-2a3b-43e4-b9b7-a8d041b98318.

Reference:

  • F509 https://docs.astral.sh/ruff/rules/percent-format-unsupported-format-character/
  • PLE1300 https://docs.astral.sh/ruff/rules/bad-string-format-character/

dhruvmanila avatar May 13 '24 11:05 dhruvmanila

@dhruvmanila - Let's remove PLE1300 as part of v0.5.0?

charliermarsh avatar May 13 '24 14:05 charliermarsh

See https://github.com/astral-sh/ruff/pull/9756 for prior art.

zanieb avatar May 13 '24 14:05 zanieb

Let's remove PLE1300 as part of v0.5.0?

Yeah, that makes sense but there's one difference where PLE1300 would check each part of an implicitly concatenated string while F509 checks it as a whole. This means that the number of diagnostics would be reduced. That said, I think F509 can be improved to either

  1. Include all the invalid characters in the message or
  2. Raise violation for each invalid character and highlighting the part of the string instead of the entire string

dhruvmanila avatar May 13 '24 14:05 dhruvmanila

I'm looking into this and it seems that there's one behavior which is different - PLE1300 looks at both % style strings and .format strings while F509 only looks at % style strings. Basically, F509 is a subset of PLE1300 which means we should remove F509 instead.

dhruvmanila avatar Jun 25 '24 03:06 dhruvmanila

Shouldn't they be aliased to match what's expected from each tool and not break rétro compatibility ? (There's another issue for human readable names where old_names from pylint and aliases came up).

Pierre-Sassoulas avatar Jun 25 '24 04:06 Pierre-Sassoulas

Yeah, sorry, I meant that F509 will redirect to PLE1300 similar to https://github.com/astral-sh/ruff/pull/9756

dhruvmanila avatar Jun 25 '24 04:06 dhruvmanila

We've decided to not do this via rule redirection but wait until rule re-categorization (#1774) is complete and merge these rules instead. Refer to #12020 for context.

dhruvmanila avatar Jun 25 '24 16:06 dhruvmanila