I'm trying ruff
but when I do ruff check .
on my example:
print("%s" % "hello")
it shows:
UP031 Use format specifiers instead of percent format
and if I do ruff check . --fix
or ruff format .
they don't change anything.
My pyproject.toml
snipped:
[tool.ruff]
target-version = "py39"
line-length = 120
extend-select = ["E501", "UP", "RUF"]
You should always post the versions of the tools you are using and when asking for help with errors/outputs you should always post the whole output.
Running your example with ruff 0.1.2 (
ruff check .
) outputs:The error message clearly states that there aren't fixes available unless you run the command with the option
--unsafe-fixes
. If you want ruff to fix it then you need to run the commandruff check . --fix --unsafe-fixes
and it will fix the line to
print("{}".format("hello"))
It is an unsafe fix as explained by the documentation, the value you are trying to print could change the way its printed if you change the formatting.
According to ruff rules (UP032) is sometimes able to fix
.format()
and turn it into an f-string, but in this case because you are directly using a string it doesn't fix it. If your code was:Ruff would fix it and turn it into (`ruff check . --fix):