Sort messages prior to display (#56)

This commit is contained in:
Charlie Marsh 2022-08-31 10:53:35 -04:00 committed by GitHub
parent 3afedcd48b
commit 0ebed13e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -56,7 +56,7 @@ fn run_once(files: &[PathBuf], settings: &Settings, cache: bool) -> Result<Vec<M
debug!("Identified files to lint in: {:?}", duration);
let start = Instant::now();
let messages: Vec<Message> = files
let mut messages: Vec<Message> = files
.par_iter()
.filter(|entry| {
!settings
@ -72,6 +72,7 @@ fn run_once(files: &[PathBuf], settings: &Settings, cache: bool) -> Result<Vec<M
})
.flatten()
.collect();
messages.sort_unstable();
let duration = start.elapsed();
debug!("Checked files in: {:?}", duration);

View file

@ -1,3 +1,4 @@
use std::cmp::Ordering;
use std::fmt;
use colored::Colorize;
@ -29,6 +30,22 @@ pub struct Message {
pub filename: String,
}
impl Ord for Message {
fn cmp(&self, other: &Self) -> Ordering {
(&self.filename, self.location.row(), self.location.column()).cmp(&(
&other.filename,
other.location.row(),
self.location.column(),
))
}
}
impl PartialOrd for Message {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl fmt::Display for Message {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(