diff --git a/crates/ruff_dev/src/format_dev.rs b/crates/ruff_dev/src/format_dev.rs index d4bf4157be..566efb8290 100644 --- a/crates/ruff_dev/src/format_dev.rs +++ b/crates/ruff_dev/src/format_dev.rs @@ -48,16 +48,27 @@ fn ruff_check_paths(dirs: &[PathBuf]) -> anyhow::Result f32 { self.intersection as f32 / (self.black_input + self.ruff_output + self.intersection) as f32 } + + #[allow(clippy::cast_precision_loss)] + pub(crate) fn similarity_index(&self) -> f32 { + self.intersection as f32 / (self.black_input + self.intersection) as f32 + } } impl Add for Statistics { @@ -171,10 +188,10 @@ pub(crate) fn main(args: &Args) -> anyhow::Result { { print!("{}", result.display(args.format)); println!( - "Found {} stability errors in {} files (jaccard index {:.3}) in {:.2}s", + "Found {} stability errors in {} files (similarity index {:.3}) in {:.2}s", error_count, result.file_count, - result.statistics.jaccard_index(), + result.statistics.similarity_index(), result.duration.as_secs_f32(), ); } @@ -253,10 +270,10 @@ fn format_dev_multi_project(args: &Args) -> bool { total_files += result.file_count; bar.println(format!( - "Finished {} with {} files (jaccard index {:.3}) in {:.2}s", + "Finished {} with {} files (similarity index {:.3}) in {:.2}s", path.display(), result.file_count, - result.statistics.jaccard_index(), + result.statistics.similarity_index(), result.duration.as_secs_f32(), )); bar.println(result.display(args.format).to_string().trim_end()); diff --git a/crates/ruff_python_formatter/README.md b/crates/ruff_python_formatter/README.md index ab7c451e2c..9c2d918e19 100644 --- a/crates/ruff_python_formatter/README.md +++ b/crates/ruff_python_formatter/README.md @@ -249,11 +249,11 @@ It's possible to format an entire project: cargo run --bin ruff_dev -- format-dev --write my_project ``` -This will format all files that `ruff check` would lint and computes the -[Jaccard index](https://en.wikipedia.org/wiki/Jaccard_index), a measure for how close the original -and formatted versions are. The Jaccard index is 1 if there were no changes at all, while 0 means -every line was changed. If you run this on a black formatted projects, this tells you how similar -the ruff formatter is to black for the given project, with our goal being as close to 1 as possible. +This will format all files that `ruff check` would lint and computes the similarity index, the +fraction of changed lines. The similarity index is 1 if there were no changes at all, while 0 means +we changed every single line. If you run this on a black formatted projects, this tells you how +similar the ruff formatter is to black for the given project, with our goal being as close to 1 as +possible. There are three common problems with the formatter: The second formatting pass looks different than the first (formatter instability or lack of idempotency), we print invalid syntax (e.g. missing