53 lines
1.3 KiB
Rust
53 lines
1.3 KiB
Rust
use std::cmp::Ordering;
|
|
use std::fmt;
|
|
use std::path::Path;
|
|
|
|
use colored::Colorize;
|
|
use rustpython_parser::ast::Location;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::checks::CheckKind;
|
|
use crate::fs::relativize_path;
|
|
|
|
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub struct Message {
|
|
pub kind: CheckKind,
|
|
pub fixed: bool,
|
|
pub location: Location,
|
|
pub end_location: Location,
|
|
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(),
|
|
other.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!(
|
|
f,
|
|
"{}{}{}{}{}{} {} {}",
|
|
relativize_path(Path::new(&self.filename)).white().bold(),
|
|
":".cyan(),
|
|
self.location.row(),
|
|
":".cyan(),
|
|
self.location.column(),
|
|
":".cyan(),
|
|
self.kind.code().as_ref().red().bold(),
|
|
self.kind.body()
|
|
)
|
|
}
|
|
}
|