mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(oxc_diagnostics): remove error declarations
Make this crate not dependent on `oxc_ast`
This commit is contained in:
parent
04592b3e4f
commit
bb18132da5
9 changed files with 42 additions and 28 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -974,7 +974,6 @@ dependencies = [
|
|||
"is-terminal",
|
||||
"miette",
|
||||
"owo-colors",
|
||||
"oxc_ast",
|
||||
"textwrap 0.16.0",
|
||||
"thiserror",
|
||||
"unicode-width",
|
||||
|
|
|
|||
|
|
@ -12,7 +12,11 @@ use std::{
|
|||
use miette::NamedSource;
|
||||
use oxc_allocator::Allocator;
|
||||
use oxc_ast::SourceType;
|
||||
use oxc_diagnostics::{Error, GraphicalReportHandler, MinifiedFileError, Severity};
|
||||
use oxc_diagnostics::{
|
||||
miette::{self, Diagnostic},
|
||||
thiserror::Error,
|
||||
Error, GraphicalReportHandler, Severity,
|
||||
};
|
||||
use oxc_linter::{Fixer, Linter, RuleCategory, RuleEnum, RULES};
|
||||
use oxc_parser::Parser;
|
||||
use oxc_semantic::SemanticBuilder;
|
||||
|
|
@ -27,6 +31,11 @@ pub struct LintRunner {
|
|||
linter: Arc<Linter>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
#[error("File is too long to fit on the screen")]
|
||||
#[diagnostic(help("{0:?} seems like a minified file"))]
|
||||
pub struct MinifiedFileError(pub PathBuf);
|
||||
|
||||
impl LintRunner {
|
||||
#[must_use]
|
||||
pub fn new(options: LintOptions) -> Self {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,6 @@ license.workspace = true
|
|||
repository.workspace = true
|
||||
|
||||
[dependencies]
|
||||
oxc_ast = { workspace = true }
|
||||
|
||||
thiserror = { workspace = true }
|
||||
miette = { workspace = true }
|
||||
|
||||
|
|
|
|||
|
|
@ -4,31 +4,12 @@
|
|||
mod graphic_reporter;
|
||||
mod graphical_theme;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub use graphic_reporter::GraphicalReportHandler;
|
||||
pub use miette;
|
||||
use miette::Diagnostic;
|
||||
use oxc_ast::{Atom, Span};
|
||||
pub use thiserror;
|
||||
use thiserror::Error;
|
||||
|
||||
pub type Error = miette::Error;
|
||||
pub type Severity = miette::Severity;
|
||||
pub type Report = miette::Report;
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
#[error("Identifier `{0}` has already been declared")]
|
||||
#[diagnostic()]
|
||||
pub struct Redeclaration(
|
||||
pub Atom,
|
||||
#[label("`{0}` has already been declared here")] pub Span,
|
||||
#[label("It can not be redeclared here")] pub Span,
|
||||
);
|
||||
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
#[error("File is too long to fit on the screen")]
|
||||
#[diagnostic(help("{0:?} seems like a minified file"))]
|
||||
pub struct MinifiedFileError(pub PathBuf);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
use oxc_allocator::Vec;
|
||||
use oxc_ast::{ast::*, syntax_directed_operations::PrivateBoundIdentifiers, Atom, GetSpan, Span};
|
||||
use oxc_diagnostics::{Redeclaration, Result};
|
||||
use oxc_diagnostics::{
|
||||
miette::{self, Diagnostic},
|
||||
thiserror::{self, Error},
|
||||
Result,
|
||||
};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::diagnostics;
|
||||
|
|
@ -8,6 +12,15 @@ use crate::lexer::Kind;
|
|||
use crate::list::{NormalList, SeparatedList};
|
||||
use crate::Parser;
|
||||
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
#[error("Identifier `{0}` has already been declared")]
|
||||
#[diagnostic()]
|
||||
struct Redeclaration(
|
||||
pub Atom,
|
||||
#[label("`{0}` has already been declared here")] pub Span,
|
||||
#[label("It can not be redeclared here")] pub Span,
|
||||
);
|
||||
|
||||
/// ObjectExpression.properties
|
||||
pub struct ObjectExpressionProperties<'a> {
|
||||
pub elements: Vec<'a, ObjectProperty<'a>>,
|
||||
|
|
|
|||
|
|
@ -9,11 +9,12 @@ use oxc_ast::{
|
|||
ast::*, module_record::ModuleRecord, visit::Visit, AstKind, Atom, GetSpan, SourceType, Span,
|
||||
Trivias,
|
||||
};
|
||||
use oxc_diagnostics::{Error, Redeclaration};
|
||||
use oxc_diagnostics::Error;
|
||||
|
||||
use crate::{
|
||||
binder::Binder,
|
||||
checker::EarlyErrorJavaScript,
|
||||
diagnostics::Redeclaration,
|
||||
module_record::ModuleRecordBuilder,
|
||||
node::{AstNodeId, AstNodes, NodeFlags, SemanticNode},
|
||||
scope::{ScopeBuilder, ScopeId},
|
||||
|
|
|
|||
|
|
@ -8,13 +8,11 @@ use oxc_ast::{
|
|||
use oxc_diagnostics::{
|
||||
miette::{self, Diagnostic},
|
||||
thiserror::{self, Error},
|
||||
Redeclaration,
|
||||
};
|
||||
use phf::{phf_set, Set};
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use crate::scope::ScopeFlags;
|
||||
use crate::{builder::SemanticBuilder, AstNode};
|
||||
use crate::{builder::SemanticBuilder, diagnostics::Redeclaration, scope::ScopeFlags, AstNode};
|
||||
|
||||
pub struct EarlyErrorJavaScript;
|
||||
|
||||
|
|
|
|||
14
crates/oxc_semantic/src/diagnostics.rs
Normal file
14
crates/oxc_semantic/src/diagnostics.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use oxc_ast::{Atom, Span};
|
||||
use oxc_diagnostics::{
|
||||
miette::{self, Diagnostic},
|
||||
thiserror::{self, Error},
|
||||
};
|
||||
|
||||
#[derive(Debug, Error, Diagnostic)]
|
||||
#[error("Identifier `{0}` has already been declared")]
|
||||
#[diagnostic()]
|
||||
pub struct Redeclaration(
|
||||
pub Atom,
|
||||
#[label("`{0}` has already been declared here")] pub Span,
|
||||
#[label("It can not be redeclared here")] pub Span,
|
||||
);
|
||||
|
|
@ -4,6 +4,7 @@
|
|||
mod binder;
|
||||
mod builder;
|
||||
mod checker;
|
||||
mod diagnostics;
|
||||
mod module_record;
|
||||
mod node;
|
||||
mod scope;
|
||||
|
|
|
|||
Loading…
Reference in a new issue