mirror of
https://github.com/astral-sh/ruff.git
synced 2025-07-23 13:05:06 +00:00
![]() ## Summary Relates to #970. Add new `bad-format-character` Pylint rule. I had to make a change in `crates/ruff_python_literal/src/format.rs` to get a more detailed error in case the format character is not correct. I chose to do this since most of the format spec parsing functions are private. It would have required me reimplementing most of the parsing logic just to know if the format char was correct. This PR also doesn't reflect current Pylint functionality in two ways. It supports new format strings correctly, Pylint as of now doesn't. See pylint-dev/pylint#6085. In case there are multiple adjacent string literals delimited by whitespace the index of the wrong format char will relative to the single string. Pylint will instead reported it relative to the concatenated string. Given this: ``` "%s" "%z" % ("hello", "world") ``` Ruff will report this: ```Unsupported format character 'z' (0x7a) at index 1``` Pylint instead: ```Unsupported format character 'z' (0x7a) at index 3``` I believe it's more sensible to report the index relative to the individual string. ## Test Plan Added new snapshot and a small test in `crates/ruff_python_literal/src/format.rs`. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml |