Implement `flake8-use-fstring`
https://github.com/MichaelKim0407/flake8-use-fstring
-
FS001:%formatting is used. -
FS002:.formatformatting is used. -
FS003: f-string missing prefix (ignored by default).
Config options:
--percent-greedy, --format-greedy
-
Level 0 (default): only report error if the value before
%or.formatis a string literal. -
Level 1: report error if a string literal appears before
%or.formatanywhere in the statement. -
Level 2: report any usage of
%or.format.
I believe we support FS001 and FS002, at least partially, as UP031 and UP032, which also automatically upgrade % strings to .format strings, and .format strings to f-strings.
(I say "partially", because it doesn't flag every usage of % and .format strings -- it omits some cases depending on formatting.)
We could change UP031 and UP032 to always flag those string formatting methods, even if they can't fix them. That'd be one way to close out this issue. But it's a bit of a behavior change for those rules.
Let me test how it works right now, looking at the rules description, it might actually be enough.
@charliermarsh Sorry for necro'ing a closed issue - just want to mention that in my recent usage, UP032 did indeed left some .format()s, which are a bit more complex then just already assigned variable(s).
I'm thinking an opt-in option in settings for it to flag them, even though auto-fix is not available could be nice?
Might include comment, like "consider adding helper variable for complex formatting before using it in f-string"