diff --git a/crates/ruff/src/message/mod.rs b/crates/ruff/src/message/mod.rs index 5b28212741..2765347e16 100644 --- a/crates/ruff/src/message/mod.rs +++ b/crates/ruff/src/message/mod.rs @@ -6,6 +6,7 @@ use std::ops::Deref; use ruff_text_size::{TextRange, TextSize}; use rustc_hash::FxHashMap; +use crate::jupyter::JupyterIndex; pub use azure::AzureEmitter; pub use github::GithubEmitter; pub use gitlab::GitlabEmitter; @@ -17,9 +18,6 @@ use ruff_diagnostics::{Diagnostic, DiagnosticKind, Fix}; use ruff_python_ast::source_code::{SourceFile, SourceLocation}; pub use text::TextEmitter; -use crate::jupyter::JupyterIndex; -use crate::registry::AsRule; - mod azure; mod diff; mod github; @@ -77,11 +75,7 @@ impl Message { impl Ord for Message { fn cmp(&self, other: &Self) -> Ordering { - (self.filename(), self.start(), self.kind.rule()).cmp(&( - other.filename(), - other.start(), - other.kind.rule(), - )) + (&self.file, self.start()).cmp(&(&other.file, other.start())) } } diff --git a/crates/ruff_cli/src/commands/run.rs b/crates/ruff_cli/src/commands/run.rs index f8047b01d7..d33a55ed2f 100644 --- a/crates/ruff_cli/src/commands/run.rs +++ b/crates/ruff_cli/src/commands/run.rs @@ -143,7 +143,8 @@ pub(crate) fn run( acc }); - diagnostics.messages.sort_unstable(); + diagnostics.messages.sort(); + let duration = start.elapsed(); debug!("Checked {:?} files in: {:?}", paths.len(), duration); diff --git a/crates/ruff_cli/src/lib.rs b/crates/ruff_cli/src/lib.rs index 077f7d87fe..3a88139e54 100644 --- a/crates/ruff_cli/src/lib.rs +++ b/crates/ruff_cli/src/lib.rs @@ -107,7 +107,7 @@ quoting the executed command, along with the relevant file contents and `pyproje #[cfg(windows)] assert!(colored::control::set_virtual_terminal(true).is_ok()); - let log_level: LogLevel = (&log_level_args).into(); + let log_level = LogLevel::from(&log_level_args); set_up_logging(&log_level)?; match command { diff --git a/crates/ruff_python_ast/src/source_code/mod.rs b/crates/ruff_python_ast/src/source_code/mod.rs index c1f8222d4d..c4fdcc718f 100644 --- a/crates/ruff_python_ast/src/source_code/mod.rs +++ b/crates/ruff_python_ast/src/source_code/mod.rs @@ -1,3 +1,4 @@ +use std::cmp::Ordering; use std::fmt::{Debug, Formatter}; use std::sync::Arc; @@ -207,6 +208,23 @@ impl SourceFile { } } +impl PartialOrd for SourceFile { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for SourceFile { + fn cmp(&self, other: &Self) -> Ordering { + // Short circuit if these are the same source files + if Arc::ptr_eq(&self.inner, &other.inner) { + Ordering::Equal + } else { + self.inner.name.cmp(&other.inner.name) + } + } +} + struct SourceFileInner { name: Box, code: Box,