mirror of https://github.com/zkat/miette.git
fix(clippy): misc clippy fixes
This commit is contained in:
parent
a0b972f876
commit
b98b098282
|
|
@ -165,13 +165,10 @@ impl GraphicalReportHandler {
|
||||||
"".to_string()
|
"".to_string()
|
||||||
};
|
};
|
||||||
let link = format!(
|
let link = format!(
|
||||||
"\u{1b}]8;;{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\",
|
"\u{1b}]8;;{}\u{1b}\\{}{}\u{1b}]8;;\u{1b}\\",
|
||||||
url,
|
url,
|
||||||
format!(
|
|
||||||
"{}{}",
|
|
||||||
code.style(severity_style),
|
code.style(severity_style),
|
||||||
"(link)".style(self.theme.styles.link)
|
"(link)".style(self.theme.styles.link)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
write!(header, "{}", link)?;
|
write!(header, "{}", link)?;
|
||||||
writeln!(f, "{}", header)?;
|
writeln!(f, "{}", header)?;
|
||||||
|
|
@ -417,7 +414,7 @@ impl GraphicalReportHandler {
|
||||||
|
|
||||||
// And _now_ we can print out the line text itself!
|
// And _now_ we can print out the line text itself!
|
||||||
if let Some(w) = self.tab_width {
|
if let Some(w) = self.tab_width {
|
||||||
let text = line.text.replace("\t", " ".repeat(w).as_str());
|
let text = line.text.replace('\t', " ".repeat(w).as_str());
|
||||||
writeln!(f, "{}", text)?;
|
writeln!(f, "{}", text)?;
|
||||||
} else {
|
} else {
|
||||||
writeln!(f, "{}", line.text)?;
|
writeln!(f, "{}", line.text)?;
|
||||||
|
|
|
||||||
|
|
@ -846,7 +846,7 @@ fn related_source_code_propagation() -> Result<(), MietteError> {
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad {
|
let err = MyBad {
|
||||||
src: NamedSource::new("bad_file.rs", src.clone()),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
related: vec![InnerError {
|
related: vec![InnerError {
|
||||||
highlight: (0, 6).into(),
|
highlight: (0, 6).into(),
|
||||||
|
|
|
||||||
|
|
@ -631,7 +631,7 @@ fn related_source_code_propagation() -> Result<(), MietteError> {
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad {
|
let err = MyBad {
|
||||||
src: NamedSource::new("bad_file.rs", src.clone()),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
related: vec![InnerError {
|
related: vec![InnerError {
|
||||||
highlight: (0, 6).into(),
|
highlight: (0, 6).into(),
|
||||||
|
|
|
||||||
|
|
@ -1,147 +1,147 @@
|
||||||
// Testing of the `diagnostic` attr used by derive(Diagnostic)
|
// Testing of the `diagnostic` attr used by derive(Diagnostic)
|
||||||
use miette::{Diagnostic, LabeledSpan, NamedSource, SourceSpan};
|
use miette::{Diagnostic, LabeledSpan, NamedSource, SourceSpan};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enum_uses_base_attr() {
|
fn enum_uses_base_attr() {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
#[diagnostic(code(error::on::base))]
|
#[diagnostic(code(error::on::base))]
|
||||||
enum MyBad {
|
enum MyBad {
|
||||||
Only {
|
Only {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
src: NamedSource,
|
src: NamedSource,
|
||||||
#[label("this bit here")]
|
#[label("this bit here")]
|
||||||
highlight: SourceSpan,
|
highlight: SourceSpan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad::Only {
|
let err = MyBad::Only {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
};
|
};
|
||||||
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
|
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn enum_uses_variant_attr() {
|
fn enum_uses_variant_attr() {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
enum MyBad {
|
enum MyBad {
|
||||||
#[diagnostic(code(error::on::variant))]
|
#[diagnostic(code(error::on::variant))]
|
||||||
Only {
|
Only {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
src: NamedSource,
|
src: NamedSource,
|
||||||
#[label("this bit here")]
|
#[label("this bit here")]
|
||||||
highlight: SourceSpan,
|
highlight: SourceSpan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad::Only {
|
let err = MyBad::Only {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
};
|
};
|
||||||
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
|
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_attrs_allowed_on_item() {
|
fn multiple_attrs_allowed_on_item() {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
#[diagnostic(code(error::on::base))]
|
#[diagnostic(code(error::on::base))]
|
||||||
#[diagnostic(help("try doing it correctly"))]
|
#[diagnostic(help("try doing it correctly"))]
|
||||||
enum MyBad {
|
enum MyBad {
|
||||||
Only {
|
Only {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
src: NamedSource,
|
src: NamedSource,
|
||||||
#[label("this bit here")]
|
#[label("this bit here")]
|
||||||
highlight: SourceSpan,
|
highlight: SourceSpan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad::Only {
|
let err = MyBad::Only {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
};
|
};
|
||||||
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
|
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
|
||||||
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
|
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn multiple_attrs_allowed_on_variant() {
|
fn multiple_attrs_allowed_on_variant() {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
enum MyBad {
|
enum MyBad {
|
||||||
#[diagnostic(code(error::on::variant))]
|
#[diagnostic(code(error::on::variant))]
|
||||||
#[diagnostic(help("try doing it correctly"))]
|
#[diagnostic(help("try doing it correctly"))]
|
||||||
Only {
|
Only {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
src: NamedSource,
|
src: NamedSource,
|
||||||
#[label("this bit here")]
|
#[label("this bit here")]
|
||||||
highlight: SourceSpan,
|
highlight: SourceSpan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad::Only {
|
let err = MyBad::Only {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
};
|
};
|
||||||
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
|
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
|
||||||
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
|
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn attrs_can_be_split_between_item_and_variants() {
|
fn attrs_can_be_split_between_item_and_variants() {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
#[diagnostic(code(error::on::base))]
|
#[diagnostic(code(error::on::base))]
|
||||||
enum MyBad {
|
enum MyBad {
|
||||||
#[diagnostic(help("try doing it correctly"))]
|
#[diagnostic(help("try doing it correctly"))]
|
||||||
#[diagnostic(url("https://example.com/foo/bar"))]
|
#[diagnostic(url("https://example.com/foo/bar"))]
|
||||||
Only {
|
Only {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
src: NamedSource,
|
src: NamedSource,
|
||||||
#[label("this bit here")]
|
#[label("this bit here")]
|
||||||
highlight: SourceSpan,
|
highlight: SourceSpan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad::Only {
|
let err = MyBad::Only {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
};
|
};
|
||||||
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
|
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
|
||||||
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
|
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
err.url().unwrap().to_string(),
|
err.url().unwrap().to_string(),
|
||||||
"https://example.com/foo/bar".to_string()
|
"https://example.com/foo/bar".to_string()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn attr_not_required() {
|
fn attr_not_required() {
|
||||||
#[derive(Debug, Diagnostic, Error)]
|
#[derive(Debug, Diagnostic, Error)]
|
||||||
#[error("oops!")]
|
#[error("oops!")]
|
||||||
enum MyBad {
|
enum MyBad {
|
||||||
Only {
|
Only {
|
||||||
#[source_code]
|
#[source_code]
|
||||||
src: NamedSource,
|
src: NamedSource,
|
||||||
#[label("this bit here")]
|
#[label("this bit here")]
|
||||||
highlight: SourceSpan,
|
highlight: SourceSpan,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad::Only {
|
let err = MyBad::Only {
|
||||||
src: NamedSource::new("bad_file.rs", src),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
};
|
};
|
||||||
let err_span = err.labels().unwrap().next().unwrap();
|
let err_span = err.labels().unwrap().next().unwrap();
|
||||||
let expectation = LabeledSpan::new(Some("this bit here".into()), 9usize.into(), 4usize.into());
|
let expectation = LabeledSpan::new(Some("this bit here".into()), 9usize, 4usize);
|
||||||
assert_eq!(err_span, expectation);
|
assert_eq!(err_span, expectation);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -834,7 +834,7 @@ mod json_report_handler {
|
||||||
|
|
||||||
let src = "source\n text\n here".to_string();
|
let src = "source\n text\n here".to_string();
|
||||||
let err = MyBad {
|
let err = MyBad {
|
||||||
src: NamedSource::new("bad_file.rs", src.clone()),
|
src: NamedSource::new("bad_file.rs", src),
|
||||||
highlight: (9, 4).into(),
|
highlight: (9, 4).into(),
|
||||||
related: vec![
|
related: vec![
|
||||||
InnerError {
|
InnerError {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue