Skip to content

Commit

Permalink
fix(clippy): misc clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 4, 2022
1 parent a0b972f commit b98b098
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 155 deletions.
7 changes: 2 additions & 5 deletions src/handlers/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,10 @@ impl GraphicalReportHandler {
"".to_string()
};
let link = format!(
"\u{1b}]8;;{}\u{1b}\\{}\u{1b}]8;;\u{1b}\\",
"\u{1b}]8;;{}\u{1b}\\{}{}\u{1b}]8;;\u{1b}\\",
url,
format!(
"{}{}",
code.style(severity_style),
"(link)".style(self.theme.styles.link)
)
);
write!(header, "{}", link)?;
writeln!(f, "{}", header)?;
Expand Down Expand Up @@ -417,7 +414,7 @@ impl GraphicalReportHandler {

// And _now_ we can print out the line text itself!
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)?;
} else {
writeln!(f, "{}", line.text)?;
Expand Down
2 changes: 1 addition & 1 deletion tests/graphical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@ fn related_source_code_propagation() -> Result<(), MietteError> {

let src = "source\n text\n here".to_string();
let err = MyBad {
src: NamedSource::new("bad_file.rs", src.clone()),
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
related: vec![InnerError {
highlight: (0, 6).into(),
Expand Down
2 changes: 1 addition & 1 deletion tests/narrated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ fn related_source_code_propagation() -> Result<(), MietteError> {

let src = "source\n text\n here".to_string();
let err = MyBad {
src: NamedSource::new("bad_file.rs", src.clone()),
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
related: vec![InnerError {
highlight: (0, 6).into(),
Expand Down
294 changes: 147 additions & 147 deletions tests/test_derive_attr.rs
Original file line number Diff line number Diff line change
@@ -1,147 +1,147 @@
// Testing of the `diagnostic` attr used by derive(Diagnostic)
use miette::{Diagnostic, LabeledSpan, NamedSource, SourceSpan};
use thiserror::Error;

#[test]
fn enum_uses_base_attr() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
#[diagnostic(code(error::on::base))]
enum MyBad {
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
}

#[test]
fn enum_uses_variant_attr() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
enum MyBad {
#[diagnostic(code(error::on::variant))]
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
}

#[test]
fn multiple_attrs_allowed_on_item() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
#[diagnostic(code(error::on::base))]
#[diagnostic(help("try doing it correctly"))]
enum MyBad {
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
}

#[test]
fn multiple_attrs_allowed_on_variant() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
enum MyBad {
#[diagnostic(code(error::on::variant))]
#[diagnostic(help("try doing it correctly"))]
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
}

#[test]
fn attrs_can_be_split_between_item_and_variants() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
#[diagnostic(code(error::on::base))]
enum MyBad {
#[diagnostic(help("try doing it correctly"))]
#[diagnostic(url("https://example.com/foo/bar"))]
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
assert_eq!(
err.url().unwrap().to_string(),
"https://example.com/foo/bar".to_string()
);
}

#[test]
fn attr_not_required() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
enum MyBad {
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
let err_span = err.labels().unwrap().next().unwrap();
let expectation = LabeledSpan::new(Some("this bit here".into()), 9usize.into(), 4usize.into());
assert_eq!(err_span, expectation);
}
// Testing of the `diagnostic` attr used by derive(Diagnostic)
use miette::{Diagnostic, LabeledSpan, NamedSource, SourceSpan};
use thiserror::Error;

#[test]
fn enum_uses_base_attr() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
#[diagnostic(code(error::on::base))]
enum MyBad {
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
}

#[test]
fn enum_uses_variant_attr() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
enum MyBad {
#[diagnostic(code(error::on::variant))]
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
}

#[test]
fn multiple_attrs_allowed_on_item() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
#[diagnostic(code(error::on::base))]
#[diagnostic(help("try doing it correctly"))]
enum MyBad {
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
}

#[test]
fn multiple_attrs_allowed_on_variant() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
enum MyBad {
#[diagnostic(code(error::on::variant))]
#[diagnostic(help("try doing it correctly"))]
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::variant");
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
}

#[test]
fn attrs_can_be_split_between_item_and_variants() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
#[diagnostic(code(error::on::base))]
enum MyBad {
#[diagnostic(help("try doing it correctly"))]
#[diagnostic(url("https://example.com/foo/bar"))]
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
assert_eq!(err.code().unwrap().to_string(), "error::on::base");
assert_eq!(err.help().unwrap().to_string(), "try doing it correctly");
assert_eq!(
err.url().unwrap().to_string(),
"https://example.com/foo/bar".to_string()
);
}

#[test]
fn attr_not_required() {
#[derive(Debug, Diagnostic, Error)]
#[error("oops!")]
enum MyBad {
Only {
#[source_code]
src: NamedSource,
#[label("this bit here")]
highlight: SourceSpan,
},
}

let src = "source\n text\n here".to_string();
let err = MyBad::Only {
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
};
let err_span = err.labels().unwrap().next().unwrap();
let expectation = LabeledSpan::new(Some("this bit here".into()), 9usize, 4usize);
assert_eq!(err_span, expectation);
}
2 changes: 1 addition & 1 deletion tests/test_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ mod json_report_handler {

let src = "source\n text\n here".to_string();
let err = MyBad {
src: NamedSource::new("bad_file.rs", src.clone()),
src: NamedSource::new("bad_file.rs", src),
highlight: (9, 4).into(),
related: vec![
InnerError {
Expand Down

0 comments on commit b98b098

Please sign in to comment.