mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(cli): add tsconfig file validation in LintRunner (#2850)
This commit is contained in:
parent
76cc90684a
commit
23651980d1
3 changed files with 35 additions and 6 deletions
1
crates/oxc_cli/fixtures/tsconfig/tsconfig.json
Normal file
1
crates/oxc_cli/fixtures/tsconfig/tsconfig.json
Normal file
|
|
@ -0,0 +1 @@
|
|||
{}
|
||||
|
|
@ -113,6 +113,15 @@ impl Runner for LintRunner {
|
|||
}
|
||||
};
|
||||
|
||||
if let Some(path) = tsconfig.as_ref() {
|
||||
if !path.is_file() {
|
||||
let path = if path.is_relative() { cwd.join(path) } else { path.clone() };
|
||||
return CliRunResult::InvalidOptions {
|
||||
message: format!("The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file.", ),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
let options = LintServiceOptions { cwd, paths, tsconfig };
|
||||
let lint_service = LintService::new(linter, options);
|
||||
let mut diagnostic_service =
|
||||
|
|
@ -173,6 +182,18 @@ mod test {
|
|||
}
|
||||
}
|
||||
|
||||
fn test_invalid_options(args: &[&str]) -> String {
|
||||
let mut new_args = vec!["--quiet"];
|
||||
new_args.extend(args);
|
||||
let options = lint_command().run_inner(new_args.as_slice()).unwrap().lint_options;
|
||||
match LintRunner::new(options).run() {
|
||||
CliRunResult::InvalidOptions { message } => message,
|
||||
other => {
|
||||
panic!("Expected InvalidOptions, got {other:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_arg() {
|
||||
let args = &[];
|
||||
|
|
@ -402,4 +423,14 @@ mod test {
|
|||
assert_eq!(result.number_of_warnings, 1);
|
||||
assert_eq!(result.number_of_errors, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_tsconfig_option() {
|
||||
// passed
|
||||
test(&["--tsconfig", "fixtures/tsconfig/tsconfig.json"]);
|
||||
|
||||
// failed
|
||||
assert!(test_invalid_options(&["--tsconfig", "oxc/tsconfig.json"])
|
||||
.contains("oxc/tsconfig.json\" does not exist, Please provide a valid tsconfig file."));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,17 +150,14 @@ impl Runtime {
|
|||
|
||||
fn get_resolver(tsconfig: Option<PathBuf>) -> Resolver {
|
||||
use oxc_resolver::{ResolveOptions, TsconfigOptions, TsconfigReferences};
|
||||
let tsconfig = if let Some(path) = tsconfig {
|
||||
let tsconfig = tsconfig.and_then(|path| {
|
||||
if path.is_file() {
|
||||
Some(TsconfigOptions { config_file: path, references: TsconfigReferences::Auto })
|
||||
} else {
|
||||
// TODO: crates/oxc_cli/src/lint/mod.rs
|
||||
eprintln!("Tsconfig {path:?} is not a file");
|
||||
None
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
});
|
||||
|
||||
Resolver::new(ResolveOptions {
|
||||
extensions: VALID_EXTENSIONS.iter().map(|ext| format!(".{ext}")).collect(),
|
||||
condition_names: vec!["module".into(), "require".into()],
|
||||
|
|
|
|||
Loading…
Reference in a new issue