Skip to content

Commit

Permalink
refactor(linter): make fields of LintServiceOptions private
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 29, 2024
1 parent d28af6c commit eb7c9b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
8 changes: 4 additions & 4 deletions apps/oxlint/src/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,19 @@ impl Runner for LintRunner {
}
};

let tsconfig = basic_options.tsconfig;
if let Some(path) = tsconfig.as_ref() {
let mut options = LintServiceOptions::new(cwd, paths);
if let Some(path) = basic_options.tsconfig {
if !path.is_file() {
let path = if path.is_relative() { cwd.join(path) } else { path.clone() };
let path = if path.is_relative() { options.cwd().join(path) } else { path.clone() };
return CliRunResult::InvalidOptions {
message: format!(
"The tsconfig file {path:?} does not exist, Please provide a valid tsconfig file.",
),
};
}
options = options.with_tsconfig(path);
}

let options = LintServiceOptions { cwd, paths, tsconfig };
let lint_service = LintService::new(linter, options);
let mut diagnostic_service =
Self::get_diagnostic_service(&warning_options, &output_options, &misc_options);
Expand Down
24 changes: 21 additions & 3 deletions crates/oxc_linter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,33 @@ use crate::{
Fixer, Linter, Message,
};

#[derive(Debug, Clone)]
pub struct LintServiceOptions {
/// Current working directory
pub cwd: Box<Path>,
cwd: Box<Path>,

/// All paths to lint
pub paths: Vec<Box<Path>>,
paths: Vec<Box<Path>>,

/// TypeScript `tsconfig.json` path for reading path alias and project references
pub tsconfig: Option<PathBuf>,
tsconfig: Option<PathBuf>,
}

impl LintServiceOptions {
#[must_use]
pub fn new<T: Into<Box<Path>>, U: Into<Box<Path>>>(cwd: T, paths: Vec<U>) -> Self {
Self { cwd: cwd.into(), paths: paths.into_iter().map(Into::into).collect(), tsconfig: None }
}

#[must_use]
pub fn with_tsconfig<P: Into<PathBuf>>(mut self, tsconfig: P) -> Self {
self.tsconfig = Some(tsconfig.into());
self
}

pub fn cwd(&self) -> &Path {
&self.cwd
}
}

#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_linter/src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ impl Tester {

let cwd = self.current_working_directory.clone();
let paths = vec![path_to_lint.into_boxed_path()];
let options = LintServiceOptions { cwd, paths, tsconfig: None };
let options = LintServiceOptions::new(cwd, paths);
let lint_service = LintService::from_linter(linter, options);
let diagnostic_service = DiagnosticService::default();
let tx_error = diagnostic_service.sender();
Expand Down

0 comments on commit eb7c9b9

Please sign in to comment.