Summary
Today, I encountered a case where ruff format needs to be run twice in order to reach a stable result.
Here's the lines that reproduce the issue:
import os
import subprocess
def clean_unnecessary_objects(objects, dest_path, keep_dot_git):
objects_to_remove = set([".git"]) if objects == "all" else set(os.listdir(dest_path)) - set(objects)
subprocess.check_call(f"rm -rf {' '.join(map(lambda object_name: os.path.join(dest_path, object_name), objects_to_remove))}", shell=True)
After running ruff format test.py, the file looks like this:
import os
import subprocess
def clean_unnecessary_objects(objects, dest_path, keep_dot_git):
objects_to_remove = (
set([".git"]) if objects == "all" else set(os.listdir(dest_path)) - set(objects)
)
subprocess.check_call(
f"rm -rf {' '.join(map(lambda object_name: os.path.join(
dest_path, object_name
), objects_to_remove))}",
shell=True,
)
After running ruff format --no-cache test.py (to force the formatter to run again on the same file), the file looks like this:
import os
import subprocess
def clean_unnecessary_objects(objects, dest_path, keep_dot_git):
objects_to_remove = (
set([".git"]) if objects == "all" else set(os.listdir(dest_path)) - set(objects)
)
subprocess.check_call(
f"rm -rf {
' '.join(
map(
lambda object_name: os.path.join(dest_path, object_name),
objects_to_remove,
)
)
}",
shell=True,
)
Further runs of ruff format --no-cache test.py don't change the file.
My .ruff.toml config is very simple:
target-version = "py312"
[format]
line-ending = "lf"
Playground links:
Version
ruff 0.15.11
Summary
Today, I encountered a case where
ruff formatneeds to be run twice in order to reach a stable result.Here's the lines that reproduce the issue:
After running
ruff format test.py, the file looks like this:After running
ruff format --no-cache test.py(to force the formatter to run again on the same file), the file looks like this:Further runs of
ruff format --no-cache test.pydon't change the file.My .ruff.toml config is very simple:
Playground links:
Version
ruff 0.15.11