diff --git a/crates/oxc_diagnostics/src/lib.rs b/crates/oxc_diagnostics/src/lib.rs index 4ba9fba8c..22cc8bb1e 100644 --- a/crates/oxc_diagnostics/src/lib.rs +++ b/crates/oxc_diagnostics/src/lib.rs @@ -11,8 +11,6 @@ use std::{ ops::Deref, }; -pub use miette; - pub use crate::{ graphic_reporter::GraphicalReportHandler, graphical_theme::GraphicalTheme, @@ -21,7 +19,6 @@ pub use crate::{ pub type Error = miette::Error; pub type Severity = miette::Severity; -pub type Report = miette::Report; pub type Result = std::result::Result; diff --git a/crates/oxc_diagnostics/src/reporter/checkstyle.rs b/crates/oxc_diagnostics/src/reporter/checkstyle.rs index f4ddb1cb5..20b9508c8 100644 --- a/crates/oxc_diagnostics/src/reporter/checkstyle.rs +++ b/crates/oxc_diagnostics/src/reporter/checkstyle.rs @@ -1,6 +1,6 @@ use std::{borrow::Cow, collections::HashMap}; -use crate::{miette::Error, Severity}; +use crate::{Error, Severity}; use super::{DiagnosticReporter, Info}; diff --git a/crates/oxc_diagnostics/src/reporter/github.rs b/crates/oxc_diagnostics/src/reporter/github.rs index 70e1a2892..16db57940 100644 --- a/crates/oxc_diagnostics/src/reporter/github.rs +++ b/crates/oxc_diagnostics/src/reporter/github.rs @@ -3,7 +3,7 @@ use std::{ io::{BufWriter, Stdout, Write}, }; -use crate::{miette::Error, Severity}; +use crate::{Error, Severity}; use super::{writer, DiagnosticReporter, Info}; diff --git a/crates/oxc_diagnostics/src/reporter/graphical.rs b/crates/oxc_diagnostics/src/reporter/graphical.rs index a9b49cdc2..44efda02e 100644 --- a/crates/oxc_diagnostics/src/reporter/graphical.rs +++ b/crates/oxc_diagnostics/src/reporter/graphical.rs @@ -1,6 +1,6 @@ use std::io::{BufWriter, Stdout, Write}; -use crate::{miette::Error, GraphicalReportHandler}; +use crate::{Error, GraphicalReportHandler}; use super::{writer, DiagnosticReporter}; diff --git a/crates/oxc_diagnostics/src/reporter/json.rs b/crates/oxc_diagnostics/src/reporter/json.rs index 46f6ca00c..d3193379b 100644 --- a/crates/oxc_diagnostics/src/reporter/json.rs +++ b/crates/oxc_diagnostics/src/reporter/json.rs @@ -1,4 +1,6 @@ -use crate::miette::{Error, JSONReportHandler}; +use miette::JSONReportHandler; + +use crate::Error; use super::DiagnosticReporter; diff --git a/crates/oxc_diagnostics/src/reporter/mod.rs b/crates/oxc_diagnostics/src/reporter/mod.rs index dd12eb16d..253f8c876 100644 --- a/crates/oxc_diagnostics/src/reporter/mod.rs +++ b/crates/oxc_diagnostics/src/reporter/mod.rs @@ -11,7 +11,7 @@ pub use self::{ use std::io::{BufWriter, Stdout}; -use crate::{miette::Error, Severity}; +use crate::{Error, Severity}; /// stdio is blocked by LineWriter, use a BufWriter to reduce syscalls. /// See `https://github.com/rust-lang/rust/issues/60673`. diff --git a/crates/oxc_diagnostics/src/reporter/unix.rs b/crates/oxc_diagnostics/src/reporter/unix.rs index 8883f4dc9..98312fabc 100644 --- a/crates/oxc_diagnostics/src/reporter/unix.rs +++ b/crates/oxc_diagnostics/src/reporter/unix.rs @@ -3,7 +3,7 @@ use std::{ io::{BufWriter, Stdout, Write}, }; -use crate::{miette::Error, Severity}; +use crate::{Error, Severity}; use super::{writer, DiagnosticReporter, Info}; diff --git a/crates/oxc_diagnostics/src/service.rs b/crates/oxc_diagnostics/src/service.rs index 0974660fb..e8da236f2 100644 --- a/crates/oxc_diagnostics/src/service.rs +++ b/crates/oxc_diagnostics/src/service.rs @@ -5,12 +5,11 @@ use std::{ }; use crate::{ - miette::NamedSource, reporter::{ CheckstyleReporter, DiagnosticReporter, GithubReporter, GraphicalReporter, JsonReporter, UnixReporter, }, - Error, OxcDiagnostic, Severity, + Error, NamedSource, OxcDiagnostic, Severity, }; pub type DiagnosticTuple = (PathBuf, Vec); diff --git a/crates/oxc_language_server/src/linter.rs b/crates/oxc_language_server/src/linter.rs index 12afc3eae..03ee501b8 100644 --- a/crates/oxc_language_server/src/linter.rs +++ b/crates/oxc_language_server/src/linter.rs @@ -6,9 +6,8 @@ use std::{ sync::Arc, }; -use miette::NamedSource; use oxc_allocator::Allocator; -use oxc_diagnostics::{miette, Error, Severity}; +use oxc_diagnostics::{Error, NamedSource, Severity}; use oxc_linter::{ partial_loader::{ AstroPartialLoader, JavaScriptSource, SveltePartialLoader, VuePartialLoader, diff --git a/crates/oxc_linter/src/lib.rs b/crates/oxc_linter/src/lib.rs index 0e2a5be02..ff5394cb6 100644 --- a/crates/oxc_linter/src/lib.rs +++ b/crates/oxc_linter/src/lib.rs @@ -22,7 +22,7 @@ use std::{io::Write, rc::Rc, sync::Arc}; use rustc_hash::{FxHashMap, FxHashSet}; -use oxc_diagnostics::Report; +use oxc_diagnostics::Error; use oxc_semantic::AstNode; pub use crate::{ @@ -67,7 +67,7 @@ impl Linter { /// # Errors /// /// Returns `Err` if there are any errors parsing the configuration file. - pub fn from_options(options: LintOptions) -> Result { + pub fn from_options(options: LintOptions) -> Result { let (rules, eslint_config) = options.derive_rules_and_config()?; let rules = rules.into_iter().map(|rule| (rule.name(), rule)).collect(); Ok(Self { rules, options, eslint_config: Arc::new(eslint_config) }) diff --git a/crates/oxc_semantic/tests/util/mod.rs b/crates/oxc_semantic/tests/util/mod.rs index be6142f5f..0152dc6fb 100644 --- a/crates/oxc_semantic/tests/util/mod.rs +++ b/crates/oxc_semantic/tests/util/mod.rs @@ -5,7 +5,7 @@ use std::{path::PathBuf, sync::Arc}; use itertools::Itertools; use oxc_allocator::Allocator; -use oxc_diagnostics::{miette::NamedSource, Error}; +use oxc_diagnostics::{Error, NamedSource}; use oxc_semantic::{print_basic_block, Semantic, SemanticBuilder}; use oxc_span::SourceType; diff --git a/crates/oxc_semantic/tests/util/symbol_tester.rs b/crates/oxc_semantic/tests/util/symbol_tester.rs index 9e8dfa07c..3308141bb 100644 --- a/crates/oxc_semantic/tests/util/symbol_tester.rs +++ b/crates/oxc_semantic/tests/util/symbol_tester.rs @@ -1,6 +1,6 @@ use std::rc::Rc; -use oxc_diagnostics::{miette::miette, Error}; +use oxc_diagnostics::{Error, OxcDiagnostic}; use oxc_semantic::{Reference, ScopeFlags, Semantic, SymbolFlags, SymbolId}; use oxc_span::Atom; @@ -13,7 +13,7 @@ pub struct SymbolTester<'a> { /// Name of the subject symbol target_symbol_name: String, /// Symbol data, or error if not found - test_result: Result, + test_result: Result, } impl<'a> SymbolTester<'a> { @@ -24,7 +24,10 @@ impl<'a> SymbolTester<'a> { ) -> Self { let decl = semantic.scopes().get_binding(semantic.scopes().root_scope_id(), &Atom::from(target)); - let data = decl.map_or_else(|| Err(miette!("Could not find declaration for {target}")), Ok); + let data = decl.map_or_else( + || Err(OxcDiagnostic::error(format!("Could not find declaration for {target}"))), + Ok, + ); SymbolTester { parent, @@ -45,9 +48,9 @@ impl<'a> SymbolTester<'a> { .filter(|(_, _, name)| name.as_str() == target) .collect(); let data = match symbols_with_target_name.len() { - 0 => Err(miette!("Could not find declaration for {target}")), + 0 => Err(OxcDiagnostic::error(format!("Could not find declaration for {target}"))), 1 => Ok(symbols_with_target_name.iter().map(|(_, symbol_id, _)| *symbol_id).next().unwrap()), - n if n > 1 => Err(miette!("Couldn't uniquely resolve symbol id for target {target}; {n} symbols with that name are declared in the source.")), + n if n > 1 => Err(OxcDiagnostic::error(format!("Couldn't uniquely resolve symbol id for target {target}; {n} symbols with that name are declared in the source."))), _ => unreachable!() }; @@ -72,12 +75,10 @@ impl<'a> SymbolTester<'a> { if found_flags.contains(flags) { Ok(symbol_id) } else { - Err(miette!( + Err(OxcDiagnostic::error(format!( "Expected {} to contain flags {:?}, but it had {:?}", - self.target_symbol_name, - flags, - found_flags - )) + self.target_symbol_name, flags, found_flags + ))) } } err => err, @@ -92,12 +93,10 @@ impl<'a> SymbolTester<'a> { if found_flags.intersects(flags) { Ok(symbol_id) } else { - Err(miette!( + Err(OxcDiagnostic::error(format!( "Expected {} to intersect with flags {:?}, but it had {:?}", - self.target_symbol_name, - flags, - found_flags - )) + self.target_symbol_name, flags, found_flags + ))) } } err => err, @@ -134,7 +133,7 @@ impl<'a> SymbolTester<'a> { if num_accepted == ref_count { Ok(symbol_id) } else { - Err(miette!("Expected to find {ref_count} acceptable references, but only found {num_accepted}")) + Err(OxcDiagnostic::error(format!("Expected to find {ref_count} acceptable references, but only found {num_accepted}"))) } } e => e, @@ -152,15 +151,15 @@ impl<'a> SymbolTester<'a> { && self.semantic.scopes().get_root_binding(&binding) == Some(symbol_id); let has_export_flag = self.semantic.symbols().get_flag(symbol_id).is_export(); match (is_in_module_record, has_export_flag) { - (false, false) => Err(miette!( + (false, false) => Err(OxcDiagnostic::error(format!( "Expected {binding} to be exported. Symbol is not in module record and does not have SymbolFlags::Export" - )), - (false, true) => Err(miette!( + ))), + (false, true) => Err(OxcDiagnostic::error(format!( "Expected {binding} to be exported. Symbol is not in module record, but has SymbolFlags::Export" - )), - (true, false) => Err(miette!( + ))), + (true, false) => Err(OxcDiagnostic::error(format!( "Expected {binding} to be exported. Symbol is in module record, but does not have SymbolFlags::Export" - )), + ))), (true, true) => Ok(symbol_id) } } @@ -175,16 +174,18 @@ impl<'a> SymbolTester<'a> { Ok(symbol_id) => { let binding = self.target_symbol_name.clone(); if self.semantic.symbols().get_flag(symbol_id).contains(SymbolFlags::Export) { - Err(miette!("Expected {binding} to not be exported. Symbol has export flag.")) + Err(OxcDiagnostic::error(format!( + "Expected {binding} to not be exported. Symbol has export flag." + ))) } else if self .semantic .module_record() .exported_bindings .contains_key(binding.as_str()) { - Err(miette!( + Err(OxcDiagnostic::error(format!( "Expected {binding} to not be exported. Binding is in the module record" - )) + ))) } else { Ok(symbol_id) } @@ -204,7 +205,7 @@ impl<'a> SymbolTester<'a> { if scope_flags.contains(expected_flags) { Ok(symbol_id) } else { - Err(miette!("Binding {target_name} is not in a scope with expected flags.\n\tExpected: {expected_flags:?}\n\tActual: {scope_flags:?}")) + Err(OxcDiagnostic::error(format!("Binding {target_name} is not in a scope with expected flags.\n\tExpected: {expected_flags:?}\n\tActual: {scope_flags:?}"))) } } e => e, @@ -220,7 +221,7 @@ impl<'a> SymbolTester<'a> { let scope_id = self.semantic.symbol_scope(symbol_id); let scope_flags = self.semantic.scopes().get_flags(scope_id); if scope_flags.contains(excluded_flags) { - Err(miette!("Binding {target_name} is in a scope with excluded flags.\n\tExpected: not {excluded_flags:?}\n\tActual: {scope_flags:?}")) + Err(OxcDiagnostic::error(format!("Binding {target_name} is in a scope with excluded flags.\n\tExpected: not {excluded_flags:?}\n\tActual: {scope_flags:?}"))) } else { Ok(symbol_id) } @@ -249,7 +250,7 @@ impl<'a> Expect<(Rc>, SymbolId), bool> for SymbolTester<'a> { if did_pass { self } else { - Self { test_result: Err(miette!("Expectation failed")), ..self } + Self { test_result: Err(OxcDiagnostic::error("Expectation failed")), ..self } } } } @@ -262,16 +263,16 @@ impl<'a> Expect<(Rc>, SymbolId), Result<(), &'static str>> for Symb let Ok(symbol_id) = self.test_result else { return self }; let did_pass = expectation((Rc::clone(&self.semantic), symbol_id)); if let Err(e) = did_pass { - Self { test_result: Err(miette!(e)), ..self } + Self { test_result: Err(OxcDiagnostic::error(e)), ..self } } else { self } } } -impl<'a> Expect<(Rc>, SymbolId), Result<(), Error>> for SymbolTester<'a> { +impl<'a> Expect<(Rc>, SymbolId), Result<(), OxcDiagnostic>> for SymbolTester<'a> { fn expect<'e, F>(self, expectation: F) -> Self where - F: FnOnce((Rc>, SymbolId)) -> Result<(), Error>, + F: FnOnce((Rc>, SymbolId)) -> Result<(), OxcDiagnostic>, { let Ok(symbol_id) = self.test_result else { return self }; let did_pass = expectation((Rc::clone(&self.semantic), symbol_id)); diff --git a/napi/parser/src/lib.rs b/napi/parser/src/lib.rs index a20d2ad4f..69a7b166d 100644 --- a/napi/parser/src/lib.rs +++ b/napi/parser/src/lib.rs @@ -7,7 +7,7 @@ use napi_derive::napi; use oxc_allocator::Allocator; pub use oxc_ast::ast::Program; use oxc_ast::CommentKind; -use oxc_diagnostics::{miette::NamedSource, Error}; +use oxc_diagnostics::{Error, NamedSource}; use oxc_parser::{Parser, ParserReturn}; use oxc_span::SourceType; diff --git a/tasks/coverage/src/suite.rs b/tasks/coverage/src/suite.rs index 50b220ffc..ce3c89af3 100644 --- a/tasks/coverage/src/suite.rs +++ b/tasks/coverage/src/suite.rs @@ -18,7 +18,7 @@ use walkdir::WalkDir; use oxc_allocator::Allocator; use oxc_ast::Trivias; -use oxc_diagnostics::{miette::NamedSource, Error, GraphicalReportHandler, GraphicalTheme}; +use oxc_diagnostics::{Error, GraphicalReportHandler, GraphicalTheme, NamedSource}; use oxc_parser::Parser; use oxc_semantic::SemanticBuilder; use oxc_span::{SourceType, Span}; diff --git a/tasks/transform_conformance/src/test_case.rs b/tasks/transform_conformance/src/test_case.rs index 666b92a7f..fd12136e8 100644 --- a/tasks/transform_conformance/src/test_case.rs +++ b/tasks/transform_conformance/src/test_case.rs @@ -8,7 +8,7 @@ use serde_json::Value; use oxc_allocator::Allocator; use oxc_codegen::{Codegen, CodegenOptions}; -use oxc_diagnostics::{miette::miette, Error}; +use oxc_diagnostics::{Error, OxcDiagnostic}; use oxc_parser::Parser; use oxc_span::{SourceType, VALID_EXTENSIONS}; use oxc_tasks_common::{normalize_path, print_diff_in_terminal, BabelOptions}; @@ -191,7 +191,7 @@ pub trait TestCase { let transform_options = match self.transform_options() { Ok(transform_options) => transform_options, Err(json_err) => { - return Err(vec![miette!(format!("{json_err:?}"))]); + return Err(vec![OxcDiagnostic::error(format!("{json_err:?}")).into()]); } };