refactor(cli): remove unused lint/error.rs (#792)

This commit is contained in:
Boshen 2023-08-25 16:46:26 +08:00 committed by GitHub
parent 592137586c
commit 1b5ef7cdc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 55 deletions

View file

@ -1,43 +0,0 @@
use std::{
error::Error as STDError,
fmt::{self, Display},
io,
path::{Path, PathBuf},
};
#[derive(Debug)]
pub struct Error {
path: PathBuf,
error: io::Error,
}
impl STDError for Error {}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{} when accessing \"{}\"", self.error, self.path.display())
}
}
impl Error {
fn new(path: PathBuf, error: io::Error) -> Self {
Self { path, error }
}
}
// allow simple conversion from io::Result using the `with_path` method
pub trait ErrorWithPath<T> {
/// Convert an io::Result to lint::error, which allows associating a path with the error for
/// better error messages.
fn with_path(self, path: impl AsRef<Path>) -> Result<T>;
}
impl<T> ErrorWithPath<T> for io::Result<T> {
fn with_path(self, path: impl AsRef<Path>) -> Result<T> {
match self {
Ok(t) => Ok(t),
Err(error) => Err(Error::new(path.as_ref().to_path_buf(), error)),
}
}
}
pub type Result<T> = std::result::Result<T, Error>;

View file

@ -1,5 +1,3 @@
mod error;
use std::{
io::BufWriter,
sync::{
@ -8,10 +6,7 @@ use std::{
},
};
pub use self::error::Error;
use oxc_diagnostics::DiagnosticService;
use oxc_index::assert_impl_all;
use oxc_linter::{LintOptions, LintService, Linter, PathWork};
use crate::{command::LintOptions as CliLintOptions, walk::Walk, CliRunResult, Runner};
@ -19,7 +14,6 @@ use crate::{command::LintOptions as CliLintOptions, walk::Walk, CliRunResult, Ru
pub struct LintRunner {
options: CliLintOptions,
}
assert_impl_all!(LintRunner: Send, Sync);
impl Runner for LintRunner {
type Options = CliLintOptions;

View file

@ -7,7 +7,6 @@ use std::{
#[derive(Debug)]
pub enum CliRunResult {
None,
IOError(crate::lint::Error),
PathNotFound {
paths: Vec<PathBuf>,
},
@ -33,10 +32,6 @@ impl Termination for CliRunResult {
println!("Path {paths:?} does not exist.");
ExitCode::from(1)
}
Self::IOError(e) => {
println!("IO Error: {e}");
ExitCode::from(1)
}
Self::LintResult {
duration,
number_of_rules,

View file

@ -1,7 +1,7 @@
use crate::CliRunResult;
/// A trait for exposing functionality to the CLI.
pub trait Runner: Send + Sync {
pub trait Runner {
type Options;
fn new(matches: Self::Options) -> Self;