ruff
32f644c3 - Add RUF072: warn when using operator on an f-string (#24162)

Commit
156 days ago
Add RUF072: warn when using operator on an f-string (#24162) ## Summary Fixes #24159 Adds a new rule RUF072 (`fstring-percent-format`) that flags any use of the `%` operator on an f-string. Mixing f-string interpolation with `%`-formatting is almost certainly a mistake since both serve the same purpose. There's no valid use case for using `%` on an f-string. ```python # Flagged f"{name}" % name f"hello %s %s" % (1, 2) f"value: {x}" % {"key": "value"} # OK — plain string literals are handled by existing F50x rules "hello %s" % name "%s %s" % (1, 2) ``` ## Test Plan - Added test cases for f-strings with `%` on various RHS types (variables, tuples, dicts, literals) - Added test cases for plain string literals (not flagged — handled by F50x) - Verified existing ruff and pyflakes tests still pass ```shell cargo test -p ruff_linter -- fstring_percent_format ``` Test file: `crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__RUF072_RUF072.py.snap` Test cases cover: - F-string with `%` and variable RHS: `f"{banana}" % banana` - F-string with `%` and tuple RHS: `f"hello %s %s" % (1, 2)` - F-string with `%` and dict RHS: `f"value: {x}" % {"key": "value"}` - F-string with `%` and literal RHS: `f"{x}" % 42` - Plain string literals not flagged (handled by existing F50x rules)
Author
Parents
Loading