Skip to content

Commit

Permalink
refactor(linter): move DiagnosticsReporters to oxlint
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Jan 13, 2025
1 parent 6a3ff9e commit 7b0403a
Showing 1 changed file with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,16 @@ use crate::{Error, Severity};
///
/// ## Example
/// ```
/// use std::io::{self, Write, BufWriter, Stderr};
/// use oxc_diagnostics::{DiagnosticReporter, Error, Severity};
///
/// pub struct BufReporter {
/// writer: BufWriter<Stderr>,
/// }
///
/// impl Default for BufReporter {
/// fn default() -> Self {
/// Self { writer: BufWriter::new(io::stderr()) }
/// }
/// }
/// #[derive(Default)]
/// pub struct BufferedReporter;
///
/// impl DiagnosticReporter for BufferedReporter {
/// // flush all remaining bytes when no more diagnostics will be reported
/// fn finish(&mut self) {
/// self.writer.flush().unwrap();
/// }
///
/// // write rendered reports to stderr
/// fn render_diagnostics(&mut self, s: &[u8]) {
/// self.writer.write_all(s).unwrap();
/// // render the finished output, some reporters will store the errors in memory
/// // to output all diagnostics at the end
/// fn finish(&mut self) -> Option<String> {
/// None
/// }
///
/// // render diagnostics to a simple Apache-like log format
Expand All @@ -50,8 +38,7 @@ use crate::{Error, Severity};
pub trait DiagnosticReporter {
/// Lifecycle hook that gets called when no more diagnostics will be reported.
///
/// Used primarily for flushing output stream buffers, but you don't just have to use it for
/// that. Some reporters (e.g. `JSONReporter`) store all diagnostics in memory, then write them
/// Some reporters (e.g. `JSONReporter`) store all diagnostics in memory, then write them
/// all at once.
///
/// While this method _should_ only ever be called a single time, this is not a guarantee
Expand All @@ -62,8 +49,7 @@ pub trait DiagnosticReporter {
/// might return a stringified JSON object on a single line. Returns [`None`] to skip reporting
/// of this diagnostic.
///
/// Reporters should not use this method to write diagnostics to their output stream. That
/// should be done in [`render_diagnostics`](DiagnosticReporter::render_diagnostics).
/// Reporters should use this method to write diagnostics to their output stream.
fn render_error(&mut self, error: Error) -> Option<String>;
}

Expand Down

0 comments on commit 7b0403a

Please sign in to comment.