mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(cli): fix panic when no paths are provided (#944)
This commit is contained in:
parent
86b483518b
commit
d5b70c3b2c
3 changed files with 11 additions and 0 deletions
|
|
@ -33,6 +33,10 @@ impl Runner for LintRunner {
|
|||
misc_options,
|
||||
} = self.options;
|
||||
|
||||
if paths.is_empty() {
|
||||
return CliRunResult::InvalidOptions { message: "No paths provided.".to_string() };
|
||||
}
|
||||
|
||||
let now = std::time::Instant::now();
|
||||
|
||||
let paths = Walk::new(&paths, &ignore_options).paths();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use std::{
|
|||
#[derive(Debug)]
|
||||
pub enum CliRunResult {
|
||||
None,
|
||||
InvalidOptions { message: String },
|
||||
PathNotFound { paths: Vec<PathBuf> },
|
||||
LintResult(LintResult),
|
||||
TypeCheckResult { duration: Duration, number_of_diagnostics: usize },
|
||||
|
|
@ -26,6 +27,10 @@ impl Termination for CliRunResult {
|
|||
fn report(self) -> ExitCode {
|
||||
match self {
|
||||
Self::None => ExitCode::from(0),
|
||||
Self::InvalidOptions { message } => {
|
||||
println!("Invalid Options: {message}");
|
||||
ExitCode::from(1)
|
||||
}
|
||||
Self::PathNotFound { paths } => {
|
||||
println!("Path {paths:?} does not exist.");
|
||||
ExitCode::from(1)
|
||||
|
|
|
|||
|
|
@ -52,6 +52,8 @@ impl ignore::ParallelVisitor for WalkCollector {
|
|||
impl Walk {
|
||||
/// # Panics
|
||||
pub fn new(paths: &[PathBuf], options: &IgnoreOptions) -> Self {
|
||||
assert!(!paths.is_empty(), "At least one path must be provided to Walk::new");
|
||||
|
||||
let paths = paths
|
||||
.iter()
|
||||
.map(|p| p.canonicalize().unwrap_or_else(|_| p.clone()))
|
||||
|
|
|
|||
Loading…
Reference in a new issue