mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
refactor(diagnostics): remove export of miette
This commit is contained in:
parent
551632a348
commit
dbde5b3a04
15 changed files with 49 additions and 51 deletions
|
|
@ -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<T> = std::result::Result<T, OxcDiagnostic>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::{borrow::Cow, collections::HashMap};
|
||||
|
||||
use crate::{miette::Error, Severity};
|
||||
use crate::{Error, Severity};
|
||||
|
||||
use super::{DiagnosticReporter, Info};
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
io::{BufWriter, Stdout, Write},
|
||||
};
|
||||
|
||||
use crate::{miette::Error, Severity};
|
||||
use crate::{Error, Severity};
|
||||
|
||||
use super::{writer, DiagnosticReporter, Info};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::io::{BufWriter, Stdout, Write};
|
||||
|
||||
use crate::{miette::Error, GraphicalReportHandler};
|
||||
use crate::{Error, GraphicalReportHandler};
|
||||
|
||||
use super::{writer, DiagnosticReporter};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use crate::miette::{Error, JSONReportHandler};
|
||||
use miette::JSONReportHandler;
|
||||
|
||||
use crate::Error;
|
||||
|
||||
use super::DiagnosticReporter;
|
||||
|
||||
|
|
|
|||
|
|
@ -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`.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{
|
|||
io::{BufWriter, Stdout, Write},
|
||||
};
|
||||
|
||||
use crate::{miette::Error, Severity};
|
||||
use crate::{Error, Severity};
|
||||
|
||||
use super::{writer, DiagnosticReporter, Info};
|
||||
|
||||
|
|
|
|||
|
|
@ -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<Error>);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Self, Report> {
|
||||
pub fn from_options(options: LintOptions) -> Result<Self, Error> {
|
||||
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) })
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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<SymbolId, oxc_diagnostics::Error>,
|
||||
test_result: Result<SymbolId, OxcDiagnostic>,
|
||||
}
|
||||
|
||||
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<Semantic<'a>>, 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<Semantic<'a>>, 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<Semantic<'a>>, SymbolId), Result<(), Error>> for SymbolTester<'a> {
|
||||
impl<'a> Expect<(Rc<Semantic<'a>>, SymbolId), Result<(), OxcDiagnostic>> for SymbolTester<'a> {
|
||||
fn expect<'e, F>(self, expectation: F) -> Self
|
||||
where
|
||||
F: FnOnce((Rc<Semantic<'a>>, SymbolId)) -> Result<(), Error>,
|
||||
F: FnOnce((Rc<Semantic<'a>>, SymbolId)) -> Result<(), OxcDiagnostic>,
|
||||
{
|
||||
let Ok(symbol_id) = self.test_result else { return self };
|
||||
let did_pass = expectation((Rc::clone(&self.semantic), symbol_id));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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};
|
||||
|
|
|
|||
|
|
@ -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()]);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue