Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::{

use cow_utils::CowUtils;
use ignore::{gitignore::Gitignore, overrides::OverrideBuilder};
use oxc_diagnostics::{DiagnosticService, GraphicalReportHandler, OxcDiagnostic};
use oxc_diagnostics::{GraphicalReportHandler, OxcDiagnostic};
use oxc_linter::{
AllowWarnDeny, ConfigStore, ConfigStoreBuilder, InvalidFilterKind, LintFilter, LintOptions,
LintService, LintServiceOptions, Linter, Oxlintrc,
AllowWarnDeny, ConfigStore, ConfigStoreBuilder, DiagnosticService, InvalidFilterKind,
LintFilter, LintOptions, LintService, LintServiceOptions, Linter, Oxlintrc,
};
use rustc_hash::{FxHashMap, FxHashSet};
use serde_json::Value;
Expand Down
13 changes: 4 additions & 9 deletions apps/oxlint/src/output_formatter/checkstyle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ use std::borrow::Cow;

use rustc_hash::FxHashMap;

use oxc_diagnostics::{
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};

use crate::output_formatter::{InternalFormatter, xml_utils::xml_escape};
use oxc_diagnostics::{Error, Severity};
use oxc_linter::{DiagnosticReporter, DiagnosticResult, Info};

#[derive(Debug, Default)]
pub struct CheckStyleOutputFormatter;
Expand Down Expand Up @@ -68,10 +65,8 @@ fn format_checkstyle(diagnostics: &[Error]) -> String {

#[cfg(test)]
mod test {
use oxc_diagnostics::{
NamedSource, OxcDiagnostic,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
use oxc_linter::{DiagnosticReporter, DiagnosticResult};
use oxc_span::Span;

use super::CheckstyleReporter;
Expand Down
15 changes: 5 additions & 10 deletions apps/oxlint/src/output_formatter/default.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
use std::time::Duration;

use crate::output_formatter::InternalFormatter;
use oxc_diagnostics::{
Error, GraphicalReportHandler,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_linter::table::RuleTable;
use oxc_diagnostics::{Error, GraphicalReportHandler};
use oxc_linter::{DiagnosticReporter, DiagnosticResult, table::RuleTable};

#[derive(Debug)]
pub struct DefaultOutputFormatter;
Expand Down Expand Up @@ -115,10 +112,8 @@ fn get_diagnostic_result_output(result: &DiagnosticResult) -> String {

#[cfg(test)]
mod test_implementation {
use oxc_diagnostics::{
Error, GraphicalReportHandler, GraphicalTheme,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};
use oxc_diagnostics::{Error, GraphicalReportHandler, GraphicalTheme};
use oxc_linter::{DiagnosticReporter, DiagnosticResult, Info};

use crate::output_formatter::default::get_diagnostic_result_output;

Expand Down Expand Up @@ -159,7 +154,7 @@ mod test {
InternalFormatter, LintCommandInfo,
default::{DefaultOutputFormatter, GraphicalReporter},
};
use oxc_diagnostics::reporter::{DiagnosticReporter, DiagnosticResult};
use oxc_linter::{DiagnosticReporter, DiagnosticResult};

#[test]
fn all_rules() {
Expand Down
13 changes: 5 additions & 8 deletions apps/oxlint/src/output_formatter/github.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::borrow::Cow;

use oxc_diagnostics::{
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};
use oxc_diagnostics::{Error, Severity};
use oxc_linter::{DiagnosticReporter, DiagnosticResult, Info};

use crate::output_formatter::InternalFormatter;

Expand Down Expand Up @@ -81,10 +79,9 @@ fn escape_property(value: &str) -> String {

#[cfg(test)]
mod test {
use oxc_diagnostics::{
NamedSource, OxcDiagnostic,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
use oxc_linter::{DiagnosticReporter, DiagnosticResult};

use oxc_span::Span;

use super::GithubReporter;
Expand Down
13 changes: 4 additions & 9 deletions apps/oxlint/src/output_formatter/json.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use oxc_diagnostics::{
Error,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_linter::{RuleCategory, rules::RULES};
use oxc_diagnostics::Error;
use oxc_linter::{DiagnosticReporter, DiagnosticResult, RuleCategory, rules::RULES};

use miette::JSONReportHandler;

Expand Down Expand Up @@ -76,10 +73,8 @@ fn format_json(diagnostics: &mut Vec<Error>) -> String {

#[cfg(test)]
mod test {
use oxc_diagnostics::{
NamedSource, OxcDiagnostic,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
use oxc_linter::{DiagnosticReporter, DiagnosticResult};
use oxc_span::Span;

use super::JsonReporter;
Expand Down
10 changes: 5 additions & 5 deletions apps/oxlint/src/output_formatter/junit.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use oxc_diagnostics::{
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};
use oxc_diagnostics::{Error, Severity};
use oxc_linter::{DiagnosticReporter, DiagnosticResult, Info};

use rustc_hash::FxHashMap;

use super::{InternalFormatter, xml_utils::xml_escape};
Expand Down Expand Up @@ -99,7 +98,8 @@ fn format_junit(diagnostics: &[Error]) -> String {
#[cfg(test)]
mod test {
use super::*;
use oxc_diagnostics::{NamedSource, OxcDiagnostic, reporter::DiagnosticResult};
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
use oxc_linter::DiagnosticResult;
use oxc_span::Span;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion apps/oxlint/src/output_formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use junit::JUnitOutputFormatter;
use stylish::StylishOutputFormatter;
use unix::UnixOutputFormatter;

use oxc_diagnostics::reporter::DiagnosticReporter;
use oxc_linter::DiagnosticReporter;

use crate::output_formatter::{default::DefaultOutputFormatter, json::JsonOutputFormatter};

Expand Down
9 changes: 4 additions & 5 deletions apps/oxlint/src/output_formatter/stylish.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use std::fmt::Write;

use oxc_diagnostics::{
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};
use oxc_diagnostics::{Error, Severity};
use oxc_linter::{DiagnosticReporter, DiagnosticResult, Info};
use rustc_hash::FxHashMap;

use crate::output_formatter::InternalFormatter;
Expand Down Expand Up @@ -114,7 +112,8 @@ fn format_stylish(diagnostics: &[Error]) -> String {
#[cfg(test)]
mod test {
use super::*;
use oxc_diagnostics::{NamedSource, OxcDiagnostic, reporter::DiagnosticResult};
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
use oxc_linter::DiagnosticResult;
use oxc_span::Span;

#[test]
Expand Down
12 changes: 4 additions & 8 deletions apps/oxlint/src/output_formatter/unix.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::borrow::Cow;

use oxc_diagnostics::{
Error, Severity,
reporter::{DiagnosticReporter, DiagnosticResult, Info},
};
use oxc_diagnostics::{Error, Severity};

use crate::output_formatter::InternalFormatter;
use oxc_linter::{DiagnosticReporter, DiagnosticResult, Info};

#[derive(Debug, Default)]
pub struct UnixOutputFormatter;
Expand Down Expand Up @@ -53,10 +51,8 @@ fn format_unix(diagnostic: &Error) -> String {

#[cfg(test)]
mod test {
use oxc_diagnostics::{
NamedSource, OxcDiagnostic,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_diagnostics::{NamedSource, OxcDiagnostic};
use oxc_linter::{DiagnosticReporter, DiagnosticResult};
use oxc_span::Span;

use super::UnixReporter;
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_diagnostics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ workspace = true
doctest = false

[dependencies]
cow-utils = { workspace = true }
miette = { workspace = true }
13 changes: 1 addition & 12 deletions crates/oxc_diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
//!
//! See the [miette] documentation for more information on how to interact with diagnostics.
//!
//! ## Reporting
//! If you are writing your own tools that may produce their own errors, you can use
//! [`DiagnosticService`] to format and render them to a string or a stream. It can receive
//! [`Error`]s over a multi-producer, single consumer
//!
//! ```
//! use std::{sync::Arc, thread};
//! use oxc_diagnostics::{DiagnosticService, Error, OxcDiagnostic};
Expand Down Expand Up @@ -48,25 +43,19 @@
//! service.run();
//! ```

mod service;

use std::{
borrow::Cow,
fmt::{self, Display},
ops::{Deref, DerefMut},
};

pub mod reporter;

pub use crate::service::{DiagnosticSender, DiagnosticService, DiagnosticTuple};

pub type Error = miette::Error;
pub type Severity = miette::Severity;

pub type Result<T> = std::result::Result<T, OxcDiagnostic>;

use miette::{Diagnostic, SourceCode};
pub use miette::{GraphicalReportHandler, GraphicalTheme, LabeledSpan, NamedSource};
pub use miette::{GraphicalReportHandler, GraphicalTheme, LabeledSpan, NamedSource, SourceSpan};

/// Describes an error or warning that occurred.
///
Expand Down
5 changes: 4 additions & 1 deletion crates/oxc_linter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ pub use crate::{
options::LintOptions,
options::{AllowWarnDeny, InvalidFilterKind, LintFilter, LintFilterKind},
rule::{RuleCategory, RuleFixMeta, RuleMeta, RuleWithSeverity},
service::{LintService, LintServiceOptions},
service::{
DiagnosticReporter, DiagnosticResult, DiagnosticService, Info, LintService,
LintServiceOptions,
},
};
use crate::{
config::{LintConfig, OxlintEnv, OxlintGlobals, OxlintSettings, ResolvedLinterState},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ use std::{
};

use cow_utils::CowUtils;
use miette::LabeledSpan;

use crate::{
Error, NamedSource, OxcDiagnostic, Severity,
reporter::{DiagnosticReporter, DiagnosticResult},
};
use oxc_diagnostics::{Error, LabeledSpan, NamedSource, OxcDiagnostic, Severity};

use super::{DiagnosticReporter, DiagnosticResult};

pub type DiagnosticTuple = (PathBuf, Vec<Error>);
pub type DiagnosticSender = mpsc::Sender<Option<DiagnosticTuple>>;
Expand All @@ -26,10 +24,34 @@ pub type DiagnosticReceiver = mpsc::Receiver<Option<DiagnosticTuple>>;
/// # Example
/// ```rust
/// use std::thread;
/// use oxc_diagnostics::{Error, OxcDiagnostic, DiagnosticService};
/// use oxc_diagnostics::{Error, OxcDiagnostic, GraphicalReportHandler};
/// use oxc_linter::{DiagnosticService, DiagnosticResult, DiagnosticReporter};
/// use std::path::PathBuf;
///
/// struct GraphicalReporter {
/// handler: GraphicalReportHandler,
/// }
///
/// impl Default for GraphicalReporter {
/// fn default() -> Self {
/// Self { handler: GraphicalReportHandler::new() }
/// }
/// }
///
/// impl DiagnosticReporter for GraphicalReporter {
/// fn finish(&mut self, result: &DiagnosticResult) -> Option<String> {
/// None
/// }
///
/// fn render_error(&mut self, error: Error) -> Option<String> {
/// let mut output = String::new();
/// self.handler.render_report(&mut output, error.as_ref()).unwrap();
/// Some(output)
/// }
/// }
///
/// // By default, services will pretty-print diagnostics to the console
/// let mut service = DiagnosticService::default();
/// let mut service = DiagnosticService::new(Box::new(GraphicalReporter::default()));
/// // Get a clone of the sender to send diagnostics to the service
/// let mut sender = service.sender().clone();
///
Expand All @@ -45,8 +67,9 @@ pub type DiagnosticReceiver = mpsc::Receiver<Option<DiagnosticTuple>>;
/// sender.send(None);
/// });
///
/// // Listen for and process messages
/// service.run()
/// // Process messages and report a statistic about the number of errors/warnings.
/// let mut output = std::io::stdout();
/// let result: DiagnosticResult = service.run(&mut output);
/// ```
pub struct DiagnosticService {
reporter: Box<dyn DiagnosticReporter>,
Expand Down
Loading
Loading