From b8d4c069bc230de8bea5660ff97c133425b2229b Mon Sep 17 00:00:00 2001 From: Boshen Date: Sun, 27 Oct 2024 20:48:11 +0800 Subject: [PATCH] refactor: fmt --- miette-derive/src/code.rs | 5 ++++- miette-derive/src/diagnostic.rs | 24 +++++++++++++----------- miette-derive/src/diagnostic_arg.rs | 6 +----- miette-derive/src/diagnostic_source.rs | 2 +- miette-derive/src/fmt.rs | 13 ++++++++----- miette-derive/src/help.rs | 5 ++--- miette-derive/src/label.rs | 10 ++++++++-- miette-derive/src/lib.rs | 3 +-- miette-derive/src/url.rs | 9 +++++---- miette-derive/src/utils.rs | 3 ++- src/chain.rs | 3 +-- src/eyreish/context.rs | 7 ++++--- src/eyreish/error.rs | 23 ++++++++++++----------- src/eyreish/fmt.rs | 3 ++- src/eyreish/kind.rs | 2 +- src/eyreish/mod.rs | 18 ++++++------------ src/eyreish/wrapper.rs | 4 +--- src/handler.rs | 17 ++++++++--------- src/handlers/debug.rs | 5 ++++- src/handlers/graphical.rs | 6 ++++-- src/handlers/narratable.rs | 8 +++++--- src/handlers/theme.rs | 1 + src/highlighters/blank.rs | 3 +-- src/highlighters/mod.rs | 6 ++++-- src/highlighters/syntect.rs | 3 +-- src/lib.rs | 5 ++--- src/protocol.rs | 6 ++++++ tests/color_format.rs | 9 ++++++--- tests/common/mod.rs | 3 ++- tests/drop/mod.rs | 13 ++++++++----- tests/narrated.rs | 12 +++++++----- tests/test_boxed.rs | 12 ++++++------ tests/test_context.rs | 6 ++++-- tests/test_convert.rs | 3 ++- tests/test_downcast.rs | 16 +++++++++++----- tests/test_fmt.rs | 3 ++- tests/test_json.rs | 9 ++++----- tests/test_macros.rs | 3 ++- tests/test_repr.rs | 6 ++++-- tests/test_source.rs | 9 ++++++--- 40 files changed, 172 insertions(+), 132 deletions(-) diff --git a/miette-derive/src/code.rs b/miette-derive/src/code.rs index 22dc795..6911a6a 100644 --- a/miette-derive/src/code.rs +++ b/miette-derive/src/code.rs @@ -42,7 +42,10 @@ impl Parse for Code { Ok(Code(input.parse::()?.value())) } } else { - Err(syn::Error::new(ident.span(), "diagnostic code is required. Use #[diagnostic(code = ...)] or #[diagnostic(code(...))] to define one.")) + Err(syn::Error::new( + ident.span(), + "diagnostic code is required. Use #[diagnostic(code = ...)] or #[diagnostic(code(...))] to define one.", + )) } } } diff --git a/miette-derive/src/diagnostic.rs b/miette-derive/src/diagnostic.rs index 8f7c8ae..2264306 100644 --- a/miette-derive/src/diagnostic.rs +++ b/miette-derive/src/diagnostic.rs @@ -2,16 +2,18 @@ use proc_macro2::TokenStream; use quote::quote; use syn::{punctuated::Punctuated, DeriveInput, Token}; -use crate::code::Code; -use crate::diagnostic_arg::DiagnosticArg; -use crate::diagnostic_source::DiagnosticSource; -use crate::forward::{Forward, WhichFn}; -use crate::help::Help; -use crate::label::Labels; -use crate::related::Related; -use crate::severity::Severity; -use crate::source_code::SourceCode; -use crate::url::Url; +use crate::{ + code::Code, + diagnostic_arg::DiagnosticArg, + diagnostic_source::DiagnosticSource, + forward::{Forward, WhichFn}, + help::Help, + label::Labels, + related::Related, + severity::Severity, + source_code::SourceCode, + url::Url, +}; pub enum Diagnostic { Struct { @@ -248,7 +250,7 @@ impl Diagnostic { return Err(syn::Error::new( input.ident.span(), "Can't derive Diagnostic for Unions", - )) + )); } }) } diff --git a/miette-derive/src/diagnostic_arg.rs b/miette-derive/src/diagnostic_arg.rs index c279533..8954f3f 100644 --- a/miette-derive/src/diagnostic_arg.rs +++ b/miette-derive/src/diagnostic_arg.rs @@ -1,10 +1,6 @@ use syn::parse::{Parse, ParseStream}; -use crate::code::Code; -use crate::forward::Forward; -use crate::help::Help; -use crate::severity::Severity; -use crate::url::Url; +use crate::{code::Code, forward::Forward, help::Help, severity::Severity, url::Url}; pub enum DiagnosticArg { Transparent, diff --git a/miette-derive/src/diagnostic_source.rs b/miette-derive/src/diagnostic_source.rs index 30ac6e5..afb19ec 100644 --- a/miette-derive/src/diagnostic_source.rs +++ b/miette-derive/src/diagnostic_source.rs @@ -2,9 +2,9 @@ use proc_macro2::TokenStream; use quote::quote; use syn::spanned::Spanned; -use crate::forward::WhichFn; use crate::{ diagnostic::{DiagnosticConcreteArgs, DiagnosticDef}, + forward::WhichFn, utils::{display_pat_members, gen_all_variants_with}, }; diff --git a/miette-derive/src/fmt.rs b/miette-derive/src/fmt.rs index 692c5ad..47dd0f5 100644 --- a/miette-derive/src/fmt.rs +++ b/miette-derive/src/fmt.rs @@ -1,12 +1,15 @@ // NOTE: Most code in this file is taken straight from `thiserror`. -use std::collections::HashSet as Set; -use std::iter::FromIterator; +use std::{collections::HashSet as Set, iter::FromIterator}; use proc_macro2::{Delimiter, Group, TokenStream, TokenTree}; use quote::{format_ident, quote, quote_spanned, ToTokens}; -use syn::ext::IdentExt; -use syn::parse::{ParseStream, Parser}; -use syn::{braced, bracketed, parenthesized, Ident, Index, LitStr, Member, Result, Token}; +use syn::{ + braced, bracketed, + ext::IdentExt, + parenthesized, + parse::{ParseStream, Parser}, + Ident, Index, LitStr, Member, Result, Token, +}; #[derive(Clone)] pub struct Display { diff --git a/miette-derive/src/help.rs b/miette-derive/src/help.rs index d635add..6500ae5 100644 --- a/miette-derive/src/help.rs +++ b/miette-derive/src/help.rs @@ -9,11 +9,9 @@ use syn::{ use crate::{ diagnostic::{DiagnosticConcreteArgs, DiagnosticDef}, - utils::{display_pat_members, gen_all_variants_with}, -}; -use crate::{ fmt::{self, Display}, forward::WhichFn, + utils::{display_pat_members, gen_all_variants_with}, }; pub enum Help { @@ -77,6 +75,7 @@ impl Help { } Ok(None) } + pub(crate) fn gen_enum(variants: &[DiagnosticDef]) -> Option { gen_all_variants_with( variants, diff --git a/miette-derive/src/label.rs b/miette-derive/src/label.rs index c4c5dcd..dde51b0 100644 --- a/miette-derive/src/label.rs +++ b/miette-derive/src/label.rs @@ -64,7 +64,10 @@ impl Parse for LabelAttr { LabelType::Collection } Some(_) => { - return Err(syn::Error::new(input.span(), "Invalid argument to label() attribute. The argument must be a literal string or either the keyword `primary` or `collection`.")); + return Err(syn::Error::new( + input.span(), + "Invalid argument to label() attribute. The argument must be a literal string or either the keyword `primary` or `collection`.", + )); } _ => LabelType::Default, }; @@ -79,7 +82,10 @@ impl Parse for LabelAttr { let display = Display { fmt, args, has_bonus_display: false }; (attr, Some(display)) } else if !content.is_empty() { - return Err(syn::Error::new(input.span(), "Invalid argument to label() attribute. The argument must be a literal string or either the keyword `primary` or `collection`.")); + return Err(syn::Error::new( + input.span(), + "Invalid argument to label() attribute. The argument must be a literal string or either the keyword `primary` or `collection`.", + )); } else { (attr, None) } diff --git a/miette-derive/src/lib.rs b/miette-derive/src/lib.rs index 0f7e64e..473dc3a 100644 --- a/miette-derive/src/lib.rs +++ b/miette-derive/src/lib.rs @@ -1,8 +1,7 @@ +use diagnostic::Diagnostic; use quote::quote; use syn::{parse_macro_input, DeriveInput}; -use diagnostic::Diagnostic; - mod code; mod diagnostic; mod diagnostic_arg; diff --git a/miette-derive/src/url.rs b/miette-derive/src/url.rs index bf54410..cf0f769 100644 --- a/miette-derive/src/url.rs +++ b/miette-derive/src/url.rs @@ -8,11 +8,9 @@ use syn::{ use crate::{ diagnostic::{DiagnosticConcreteArgs, DiagnosticDef}, - utils::{display_pat_members, gen_all_variants_with, gen_unused_pat}, -}; -use crate::{ fmt::{self, Display}, forward::WhichFn, + utils::{display_pat_members, gen_all_variants_with, gen_unused_pat}, }; pub enum Url { @@ -42,7 +40,10 @@ impl Parse for Url { if option == "docsrs" { Ok(Url::DocsRs) } else { - Err(syn::Error::new(option.span(), "Invalid argument to url() sub-attribute. It must be either a string or a plain `docsrs` identifier")) + Err(syn::Error::new( + option.span(), + "Invalid argument to url() sub-attribute. It must be either a string or a plain `docsrs` identifier", + )) } } } else { diff --git a/miette-derive/src/utils.rs b/miette-derive/src/utils.rs index 8fbac75..196da39 100644 --- a/miette-derive/src/utils.rs +++ b/miette-derive/src/utils.rs @@ -67,9 +67,10 @@ pub(crate) fn gen_all_variants_with( }) } -use crate::fmt::Display; use std::collections::HashSet; +use crate::fmt::Display; + pub(crate) fn gen_unused_pat(fields: &syn::Fields) -> TokenStream { match fields { syn::Fields::Named(_) => quote! { { .. } }, diff --git a/src/chain.rs b/src/chain.rs index f59efbe..ae57477 100644 --- a/src/chain.rs +++ b/src/chain.rs @@ -3,8 +3,7 @@ Iterate over error `.source()` chains. NOTE: This module is taken wholesale from . */ -use std::error::Error as StdError; -use std::vec; +use std::{error::Error as StdError, vec}; use ChainState::*; diff --git a/src/eyreish/context.rs b/src/eyreish/context.rs index 4dff561..be2b69a 100644 --- a/src/eyreish/context.rs +++ b/src/eyreish/context.rs @@ -1,9 +1,10 @@ -use super::error::{ContextError, ErrorImpl}; -use super::{Report, WrapErr}; use core::fmt::{self, Debug, Display, Write}; - use std::error::Error as StdError; +use super::{ + error::{ContextError, ErrorImpl}, + Report, WrapErr, +}; use crate::{Diagnostic, LabeledSpan}; mod ext { diff --git a/src/eyreish/error.rs b/src/eyreish/error.rs index 51097d5..5555907 100644 --- a/src/eyreish/error.rs +++ b/src/eyreish/error.rs @@ -1,16 +1,17 @@ -use core::any::TypeId; -use core::fmt::{self, Debug, Display}; -use core::mem::ManuallyDrop; -use core::ptr::{self, NonNull}; +use core::{ + any::TypeId, + fmt::{self, Debug, Display}, + mem::ManuallyDrop, + ops::{Deref, DerefMut}, + ptr::{self, NonNull}, +}; use std::error::Error as StdError; -use super::ptr::{Mut, Own, Ref}; -use super::Report; -use super::ReportHandler; -use crate::chain::Chain; -use crate::eyreish::wrapper::WithSourceCode; -use crate::{Diagnostic, SourceCode}; -use core::ops::{Deref, DerefMut}; +use super::{ + ptr::{Mut, Own, Ref}, + Report, ReportHandler, +}; +use crate::{chain::Chain, eyreish::wrapper::WithSourceCode, Diagnostic, SourceCode}; impl Report { /// Create a new error object from any error type. diff --git a/src/eyreish/fmt.rs b/src/eyreish/fmt.rs index 9e385d1..f603e32 100644 --- a/src/eyreish/fmt.rs +++ b/src/eyreish/fmt.rs @@ -1,6 +1,7 @@ -use super::{error::ErrorImpl, ptr::Ref}; use core::fmt; +use super::{error::ErrorImpl, ptr::Ref}; + impl ErrorImpl<()> { pub(crate) unsafe fn display(this: Ref<'_, Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result { this.deref() diff --git a/src/eyreish/kind.rs b/src/eyreish/kind.rs index 339c60c..876d8c6 100644 --- a/src/eyreish/kind.rs +++ b/src/eyreish/kind.rs @@ -45,9 +45,9 @@ // let error = $msg; // (&error).miette_kind().new(error) -use super::Report; use core::fmt::{Debug, Display}; +use super::Report; use crate::Diagnostic; pub struct Adhoc; diff --git a/src/eyreish/mod.rs b/src/eyreish/mod.rs index db6b8d3..c15cbeb 100644 --- a/src/eyreish/mod.rs +++ b/src/eyreish/mod.rs @@ -1,9 +1,8 @@ #![allow(clippy::needless_doctest_main, clippy::new_ret_no_self, clippy::wrong_self_convention)] use core::fmt::Display; +use std::{error::Error as StdError, sync::OnceLock}; -use std::error::Error as StdError; -use std::sync::OnceLock; - +use error::ErrorImpl; #[allow(unreachable_pub)] pub use into_diagnostic::*; #[doc(hidden)] @@ -19,16 +18,13 @@ pub use ReportHandler as EyreContext; #[allow(unreachable_pub)] pub use WrapErr as Context; +use self::ptr::Own; #[cfg(not(feature = "fancy-base"))] use crate::DebugReportHandler; use crate::Diagnostic; #[cfg(feature = "fancy-base")] use crate::MietteHandler; -use error::ErrorImpl; - -use self::ptr::Own; - mod context; mod error; mod fmt; @@ -446,16 +442,14 @@ pub trait WrapErr: context::private::Sealed { // Private API. Referenced by macro-generated code. #[doc(hidden)] pub mod private { - use super::Report; use core::fmt::{Debug, Display}; - pub use core::result::Result::Err; + use super::Report; + #[doc(hidden)] pub mod kind { - pub use super::super::kind::{AdhocKind, TraitKind}; - - pub use super::super::kind::BoxedKind; + pub use super::super::kind::{AdhocKind, BoxedKind, TraitKind}; } #[track_caller] diff --git a/src/eyreish/wrapper.rs b/src/eyreish/wrapper.rs index bfe95a9..2be7f04 100644 --- a/src/eyreish/wrapper.rs +++ b/src/eyreish/wrapper.rs @@ -1,10 +1,8 @@ use core::fmt::{self, Debug, Display}; - use std::error::Error as StdError; -use crate::{Diagnostic, LabeledSpan, Report, SourceCode}; - use crate as miette; +use crate::{Diagnostic, LabeledSpan, Report, SourceCode}; #[repr(transparent)] pub(crate) struct MessageError(pub(crate) M); diff --git a/src/handler.rs b/src/handler.rs index e38c794..fa0cdbc 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -1,14 +1,11 @@ use std::fmt; -use crate::highlighters::Highlighter; -use crate::highlighters::MietteHighlighter; -use crate::protocol::Diagnostic; -use crate::GraphicalReportHandler; -use crate::GraphicalTheme; -use crate::NarratableReportHandler; -use crate::ReportHandler; -use crate::ThemeCharacters; -use crate::ThemeStyles; +use crate::{ + highlighters::{Highlighter, MietteHighlighter}, + protocol::Diagnostic, + GraphicalReportHandler, GraphicalTheme, NarratableReportHandler, ReportHandler, + ThemeCharacters, ThemeStyles, +}; /// Settings to control the color format used for graphical rendering. #[derive(Copy, Clone, Debug, Eq, PartialEq)] @@ -149,6 +146,7 @@ impl MietteHandlerOpts { self.break_words = Some(break_words); self } + /// Sets the `textwrap::WordSeparator` to use when determining wrap points. pub fn word_separator(mut self, word_separator: textwrap::WordSeparator) -> Self { self.word_separator = Some(word_separator); @@ -160,6 +158,7 @@ impl MietteHandlerOpts { self.word_splitter = Some(word_splitter); self } + /// Include the cause chain of the top-level error in the report. pub fn with_cause_chain(mut self) -> Self { self.with_cause_chain = Some(true); diff --git a/src/handlers/debug.rs b/src/handlers/debug.rs index 61c6a38..6187a84 100644 --- a/src/handlers/debug.rs +++ b/src/handlers/debug.rs @@ -56,7 +56,10 @@ impl DebugReportHandler { } diag.finish()?; writeln!(f)?; - writeln!(f, "NOTE: If you're looking for the fancy error reports, install miette with the `fancy` feature, or write your own and hook it up with miette::set_hook().") + writeln!( + f, + "NOTE: If you're looking for the fancy error reports, install miette with the `fancy` feature, or write your own and hook it up with miette::set_hook()." + ) } } diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index 8e7f073..28f7bf5 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -1,5 +1,7 @@ -use std::fmt::{self, Write}; -use std::io::IsTerminal; +use std::{ + fmt::{self, Write}, + io::IsTerminal, +}; use owo_colors::{OwoColorize, Style}; use unicode_width::UnicodeWidthChar; diff --git a/src/handlers/narratable.rs b/src/handlers/narratable.rs index a7fb904..8df09f5 100644 --- a/src/handlers/narratable.rs +++ b/src/handlers/narratable.rs @@ -2,9 +2,11 @@ use std::fmt; use unicode_width::{UnicodeWidthChar, UnicodeWidthStr}; -use crate::diagnostic_chain::DiagnosticChain; -use crate::protocol::{Diagnostic, Severity}; -use crate::{LabeledSpan, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents}; +use crate::{ + diagnostic_chain::DiagnosticChain, + protocol::{Diagnostic, Severity}, + LabeledSpan, MietteError, ReportHandler, SourceCode, SourceSpan, SpanContents, +}; /** [`ReportHandler`] that renders plain text and avoids extraneous graphics. diff --git a/src/handlers/theme.rs b/src/handlers/theme.rs index d2d5a1c..878d5a6 100644 --- a/src/handlers/theme.rs +++ b/src/handlers/theme.rs @@ -244,6 +244,7 @@ impl ThemeCharacters { advice: "💡".into(), } } + /// ASCII-art-based graphical elements. Works well on older terminals. pub fn ascii() -> Self { Self { diff --git a/src/highlighters/blank.rs b/src/highlighters/blank.rs index 50a9c65..a9b75b9 100644 --- a/src/highlighters/blank.rs +++ b/src/highlighters/blank.rs @@ -1,8 +1,7 @@ use owo_colors::Style; -use crate::SpanContents; - use super::{Highlighter, HighlighterState}; +use crate::SpanContents; /// The default syntax highlighter. It applies `Style::default()` to input text. /// This is used by default when no syntax highlighting features are enabled. diff --git a/src/highlighters/mod.rs b/src/highlighters/mod.rs index d605c1c..b0cd756 100644 --- a/src/highlighters/mod.rs +++ b/src/highlighters/mod.rs @@ -13,12 +13,12 @@ use std::{ops::Deref, sync::Arc}; -use crate::SpanContents; +pub use blank::*; use owo_colors::Styled; #[cfg(feature = "syntect-highlighter")] pub use self::syntect::*; -pub use blank::*; +use crate::SpanContents; mod blank; #[cfg(feature = "syntect-highlighter")] @@ -90,6 +90,7 @@ impl Default for MietteHighlighter { _ => Self(Arc::new(SyntectHighlighter::default())), } } + #[cfg(not(feature = "syntect-highlighter"))] fn default() -> Self { return MietteHighlighter::nocolor(); @@ -110,6 +111,7 @@ impl std::fmt::Debug for MietteHighlighter { impl Deref for MietteHighlighter { type Target = dyn Highlighter + Send + Sync; + fn deref(&self) -> &Self::Target { &*self.0 } diff --git a/src/highlighters/syntect.rs b/src/highlighters/syntect.rs index 1f9c8ff..b0f4bb3 100644 --- a/src/highlighters/syntect.rs +++ b/src/highlighters/syntect.rs @@ -12,13 +12,12 @@ mod syntect { use owo_colors::{Rgb, Style, Styled}; +use super::BlankHighlighterState; use crate::{ highlighters::{Highlighter, HighlighterState}, SpanContents, }; -use super::BlankHighlighterState; - /// Highlights miette [SourceCode] with the [syntect](https://docs.rs/syntect/latest/syntect/) highlighting crate. /// /// Currently only 24-bit truecolor output is supported due to syntect themes diff --git a/src/lib.rs b/src/lib.rs index 6448f77..5bddd66 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -783,9 +783,6 @@ //! [`Result`]: https://docs.rs/miette/latest/miette/type.Result.html //! [`SourceCode`]: https://docs.rs/miette/latest/miette/trait.SourceCode.html //! [`SourceSpan`]: https://docs.rs/miette/latest/miette/struct.SourceSpan.html -#[cfg(feature = "derive")] -pub use oxc_miette_derive::*; - pub use error::*; pub use eyreish::*; #[cfg(feature = "fancy-base")] @@ -793,6 +790,8 @@ pub use handler::*; pub use handlers::*; pub use miette_diagnostic::*; pub use named_source::*; +#[cfg(feature = "derive")] +pub use oxc_miette_derive::*; #[cfg(feature = "fancy")] pub use panic::*; pub use protocol::*; diff --git a/src/protocol.rs b/src/protocol.rs index 27711a7..911e315 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -520,21 +520,27 @@ impl<'a> SpanContents<'a> for MietteSpanContents<'a> { fn data(&self) -> &'a [u8] { self.data } + fn span(&self) -> &SourceSpan { &self.span } + fn line(&self) -> usize { self.line } + fn column(&self) -> usize { self.column } + fn line_count(&self) -> usize { self.line_count } + fn name(&self) -> Option<&str> { self.name.as_deref() } + fn language(&self) -> Option<&str> { self.language.as_deref() } diff --git a/tests/color_format.rs b/tests/color_format.rs index 3c07cbf..f44dc15 100644 --- a/tests/color_format.rs +++ b/tests/color_format.rs @@ -1,11 +1,14 @@ #![cfg(feature = "fancy-no-backtrace")] +use std::{ + ffi::OsString, + fmt::{self, Debug}, + sync::Mutex, +}; + use lazy_static::lazy_static; use miette::{Diagnostic, MietteHandler, MietteHandlerOpts, ReportHandler, RgbColors}; use regex::Regex; -use std::ffi::OsString; -use std::fmt::{self, Debug}; -use std::sync::Mutex; use thiserror::Error; #[derive(Eq, PartialEq, Debug)] diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 223810c..f46f7e3 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -1,6 +1,7 @@ -use miette::{bail, Result}; use std::io; +use miette::{bail, Result}; + pub fn bail_literal() -> Result<()> { bail!("oh no!"); } diff --git a/tests/drop/mod.rs b/tests/drop/mod.rs index 13800a9..e9b24fb 100644 --- a/tests/drop/mod.rs +++ b/tests/drop/mod.rs @@ -1,8 +1,11 @@ -use std::error::Error as StdError; -use std::fmt::{self, Display}; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering::SeqCst; -use std::sync::Arc; +use std::{ + error::Error as StdError, + fmt::{self, Display}, + sync::{ + atomic::{AtomicBool, Ordering::SeqCst}, + Arc, + }, +}; use miette::Diagnostic; diff --git a/tests/narrated.rs b/tests/narrated.rs index 02790b1..f2880d8 100644 --- a/tests/narrated.rs +++ b/tests/narrated.rs @@ -1,9 +1,9 @@ #![cfg(feature = "fancy-no-backtrace")] -use miette::{Diagnostic, MietteError, NamedSource, NarratableReportHandler, Report, SourceSpan}; - -use miette::{GraphicalReportHandler, GraphicalTheme}; - +use miette::{ + Diagnostic, GraphicalReportHandler, GraphicalTheme, MietteError, NamedSource, + NarratableReportHandler, Report, SourceSpan, +}; use thiserror::Error; fn fmt_report(diag: Report) -> String { @@ -363,7 +363,9 @@ fn multiline_highlight_no_label() -> Result<(), MietteError> { } #[derive(Debug, Error)] - #[error("something went wrong\n\nHere's a more detailed explanation of everything that actually went wrong because it's actually important.\n")] + #[error( + "something went wrong\n\nHere's a more detailed explanation of everything that actually went wrong because it's actually important.\n" + )] struct Inner(#[source] InnerInner); #[derive(Debug, Error)] diff --git a/tests/test_boxed.rs b/tests/test_boxed.rs index fcfb81b..22cc414 100644 --- a/tests/test_boxed.rs +++ b/tests/test_boxed.rs @@ -1,6 +1,6 @@ +use std::{error::Error as StdError, io}; + use miette::{miette, Diagnostic, LabeledSpan, Report, SourceSpan}; -use std::error::Error as StdError; -use std::io; use thiserror::Error; #[derive(Error, Debug)] @@ -58,14 +58,14 @@ struct CustomDiagnostic { } impl CustomDiagnostic { - const DISPLAY: &'static str = "CustomDiagnostic display"; - const DESCRIPTION: &'static str = "CustomDiagnostic description"; const CODE: &'static str = "A042"; - const SEVERITY: miette::Severity = miette::Severity::Advice; + const DESCRIPTION: &'static str = "CustomDiagnostic description"; + const DISPLAY: &'static str = "CustomDiagnostic display"; const HELP: &'static str = "CustomDiagnostic help"; - const URL: &'static str = "https://custom-diagnostic-url"; const LABEL: &'static str = "CustomDiagnostic label"; + const SEVERITY: miette::Severity = miette::Severity::Advice; const SOURCE_CODE: &'static str = "this-is-some-source-code"; + const URL: &'static str = "https://custom-diagnostic-url"; fn new() -> Self { Self { source: None, related: Vec::new() } diff --git a/tests/test_context.rs b/tests/test_context.rs index 530dc6d..b46d34d 100644 --- a/tests/test_context.rs +++ b/tests/test_context.rs @@ -1,10 +1,12 @@ mod drop; -use crate::drop::{DetectDrop, Flag}; -use miette::{Diagnostic, IntoDiagnostic, Report, Result, WrapErr}; use std::fmt::{self, Display}; + +use miette::{Diagnostic, IntoDiagnostic, Report, Result, WrapErr}; use thiserror::Error; +use crate::drop::{DetectDrop, Flag}; + // https://github.com/dtolnay/miette/issues/18 #[test] fn test_inference() -> Result<()> { diff --git a/tests/test_convert.rs b/tests/test_convert.rs index ca9da39..6cac55e 100644 --- a/tests/test_convert.rs +++ b/tests/test_convert.rs @@ -1,8 +1,9 @@ mod drop; -use self::drop::{DetectDrop, Flag}; use miette::{Diagnostic, Report, Result}; +use self::drop::{DetectDrop, Flag}; + #[test] fn test_convert() { let has_dropped = Flag::new(); diff --git a/tests/test_downcast.rs b/tests/test_downcast.rs index bc57959..ac7b330 100644 --- a/tests/test_downcast.rs +++ b/tests/test_downcast.rs @@ -1,12 +1,18 @@ mod common; mod drop; -use self::common::*; -use self::drop::{DetectDrop, Flag}; +use std::{ + error::Error as StdError, + fmt::{self, Display}, + io, +}; + use miette::{Diagnostic, MietteDiagnostic, Report}; -use std::error::Error as StdError; -use std::fmt::{self, Display}; -use std::io; + +use self::{ + common::*, + drop::{DetectDrop, Flag}, +}; #[test] fn test_downcast() { diff --git a/tests/test_fmt.rs b/tests/test_fmt.rs index abf3873..b310582 100644 --- a/tests/test_fmt.rs +++ b/tests/test_fmt.rs @@ -1,6 +1,7 @@ -use miette::{bail, Result, WrapErr}; use std::io; +use miette::{bail, Result, WrapErr}; + fn f() -> Result<()> { bail!(io::Error::new(io::ErrorKind::PermissionDenied, "oh no!")); } diff --git a/tests/test_json.rs b/tests/test_json.rs index 1a02f65..a3ab026 100644 --- a/tests/test_json.rs +++ b/tests/test_json.rs @@ -1,10 +1,7 @@ #![allow(clippy::print_stdout, clippy::unnecessary_wraps)] mod json_report_handler { - use miette::{Diagnostic, MietteError, NamedSource, Report, SourceSpan}; - - use miette::JSONReportHandler; - + use miette::{Diagnostic, JSONReportHandler, MietteError, NamedSource, Report, SourceSpan}; use thiserror::Error; fn fmt_report(diag: Report) -> String { @@ -450,7 +447,9 @@ mod json_report_handler { } #[derive(Debug, Error)] - #[error("something went wrong\n\nHere's a more detailed explanation of everything that actually went wrong because it's actually important.\n")] + #[error( + "something went wrong\n\nHere's a more detailed explanation of everything that actually went wrong because it's actually important.\n" + )] struct Inner(#[source] InnerInner); #[derive(Debug, Error)] diff --git a/tests/test_macros.rs b/tests/test_macros.rs index 22bf8cc..50e9cab 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -1,9 +1,10 @@ #![allow(clippy::eq_op)] mod common; -use self::common::*; use miette::{ensure, Result}; +use self::common::*; + #[test] fn test_messages() { assert_eq!("oh no!", bail_literal().unwrap_err().to_string()); diff --git a/tests/test_repr.rs b/tests/test_repr.rs index 5989dce..d5b0137 100644 --- a/tests/test_repr.rs +++ b/tests/test_repr.rs @@ -1,9 +1,11 @@ mod drop; -use self::drop::{DetectDrop, Flag}; -use miette::Report; use std::mem; +use miette::Report; + +use self::drop::{DetectDrop, Flag}; + #[test] fn test_error_size() { assert_eq!(mem::size_of::(), mem::size_of::()); diff --git a/tests/test_source.rs b/tests/test_source.rs index 9511bdb..1b4076b 100644 --- a/tests/test_source.rs +++ b/tests/test_source.rs @@ -1,7 +1,10 @@ +use std::{ + error::Error as StdError, + fmt::{self, Display}, + io, +}; + use miette::{miette, Report}; -use std::error::Error as StdError; -use std::fmt::{self, Display}; -use std::io; #[derive(Debug)] enum TestError {