Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): fix panic when no paths are provided #944

Merged
merged 4 commits into from
Sep 30, 2023
Merged
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
4 changes: 4 additions & 0 deletions crates/oxc_cli/src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions crates/oxc_cli/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions crates/oxc_cli/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Loading