Skip to content
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
5 changes: 5 additions & 0 deletions apps/oxlint/fixtures/auto_config_parse_error/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules" {
"no-debugger": "error"
}
}
1 change: 1 addition & 0 deletions apps/oxlint/fixtures/auto_config_parse_error/debugger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
debugger;
64 changes: 24 additions & 40 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ impl Runner for LintRunner {
}
};

let handler = if cfg!(any(test, feature = "force_test_reporter")) {
GraphicalReportHandler::new_themed(miette::GraphicalTheme::none())
} else {
GraphicalReportHandler::new()
};

let config_search_result =
Self::find_oxlint_config(&self.cwd, basic_options.config.as_ref());

Expand All @@ -90,8 +96,12 @@ impl Runner for LintRunner {
Err(err) => {
print_and_flush_stdout(
stdout,
&format!("Failed to parse configuration file.\n{err}\n"),
&format!(
"Failed to parse configuration file.\n{}\n",
render_report(&handler, &err)
),
);

return CliRunResult::InvalidOptionConfig;
}
};
Expand Down Expand Up @@ -172,12 +182,6 @@ impl Runner for LintRunner {
let paths = walker.paths();
let number_of_files = paths.len();

let handler = if cfg!(any(test, feature = "force_test_reporter")) {
GraphicalReportHandler::new_themed(miette::GraphicalTheme::none())
} else {
GraphicalReportHandler::new()
};

let mut external_plugin_store = ExternalPluginStore::default();

let search_for_nested_configs = !disable_nested_config &&
Expand Down Expand Up @@ -485,40 +489,14 @@ impl LintRunner {
// when config is provided, but not found, an String with the formatted error is returned, else the oxlintrc config file is returned
// when no config is provided, it will search for the default file names in the current working directory
// when no file is found, the default configuration is returned
fn find_oxlint_config(cwd: &Path, config: Option<&PathBuf>) -> Result<Oxlintrc, String> {
if let Some(config_path) = config {
let full_path = match absolute(cwd.join(config_path)) {
Ok(path) => path,
Err(e) => {
let handler = GraphicalReportHandler::new();
let mut err = String::new();
handler
.render_report(
&mut err,
&OxcDiagnostic::error(format!(
"Failed to resolve config path {}: {e}",
config_path.display()
)),
)
.unwrap();
return Err(err);
}
};
return match Oxlintrc::from_file(&full_path) {
Ok(config) => Ok(config),
Err(diagnostic) => {
let handler = GraphicalReportHandler::new();
let mut err = String::new();
handler.render_report(&mut err, &diagnostic).unwrap();
return Err(err);
}
};
fn find_oxlint_config(cwd: &Path, config: Option<&PathBuf>) -> Result<Oxlintrc, OxcDiagnostic> {
let path: &Path = config.map_or(Self::DEFAULT_OXLINTRC.as_ref(), PathBuf::as_ref);
let full_path = cwd.join(path);

if config.is_some() || full_path.exists() {
return Oxlintrc::from_file(&full_path);
}
// no config argument is provided,
// auto detect default config file from current work directory
// or return the default configuration, when no valid file is found
let config_path = cwd.join(Self::DEFAULT_OXLINTRC);
Oxlintrc::from_file(&config_path).or_else(|_| Ok(Oxlintrc::default()))
Ok(Oxlintrc::default())
}

/// Looks in a directory for an oxlint config file, returns the oxlint config if it exists
Expand Down Expand Up @@ -715,6 +693,12 @@ mod test {
Tester::new().with_cwd("fixtures/auto_config_detection".into()).test_and_snapshot(args);
}

#[test]
fn oxlint_config_auto_detection_parse_error() {
let args = &["debugger.js"];
Tester::new().with_cwd("fixtures/auto_config_parse_error".into()).test_and_snapshot(args);
}

#[test]
fn eslintrc_no_undef() {
let args = &[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
source: apps/oxlint/src/tester.rs
---
##########
arguments: debugger.js
working directory: fixtures/auto_config_parse_error
----------
Failed to parse configuration file.

x Failed to parse eslint config <cwd>/fixtures/auto_config_parse_error/.oxlintrc.json.
| expected `:` at line 2 column 11

----------
CLI result: InvalidOptionConfig
----------
Loading