Skip to content

Commit

Permalink
feat(oxlint): auto detect config file in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Nov 23, 2024
1 parent 5cdff9b commit 5fe8522
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 25 deletions.
6 changes: 1 addition & 5 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ pub struct BasicOptions {
/// * only `.json` extension is supported
/// * tries to be compatible with the ESLint v8's format
///
/// If not provided, Oxlint will look for the following files in the current working directory:
/// * `oxlintrc.json`
/// * `oxlint.json`
/// * `.oxlintrc.json`
/// * `.oxlint.json`
/// If not provided, Oxlint will look for `.oxlintrc.json` in the current working directory.
#[bpaf(long, short, argument("./oxlintrc.json"))]
pub config: Option<PathBuf>,

Expand Down
23 changes: 8 additions & 15 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ impl Runner for LintRunner {
}

impl LintRunner {
const DEFAULT_OXLINTRC: &'static str = ".oxlintrc.json";

#[must_use]
pub fn with_cwd(mut self, cwd: PathBuf) -> Self {
self.cwd = cwd;
Expand Down Expand Up @@ -259,22 +261,13 @@ impl LintRunner {
}

// no config argument is provided,
// auto detect possible files from current work directory
let search_configs = &[
"oxlintrc.json",
"oxlint.json",
".oxlintrc.json",
".oxlint.json"
];

for config_file in search_configs {
let mut config_path = cwd.to_path_buf();
config_path.push(config_file);
// auto detect default config file from current work directory
let mut config_path = cwd.to_path_buf();
config_path.push(Self::DEFAULT_OXLINTRC);

if let Ok(result) = Oxlintrc::from_file(&config_path) {
return Ok(result);
};
}
if let Ok(result) = Oxlintrc::from_file(&config_path) {
return Ok(result);
};

Ok(Oxlintrc::default())
}
Expand Down
6 changes: 1 addition & 5 deletions tasks/website/src/linter/snapshots/cli.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ snapshot_kind: text
* only `.json` extension is supported
* tries to be compatible with the ESLint v8's format

If not provided, Oxlint will look for the following files in the current working directory:
* `oxlintrc.json`
* `oxlint.json`
* `.oxlintrc.json`
* `.oxlint.json`
If not provided, Oxlint will look for `.oxlintrc.json` in the current working directory.
- **` --tsconfig`**=_`<./tsconfig.json>`_ &mdash;
TypeScript `tsconfig.json` path for reading path alias and project references for import plugin

Expand Down

0 comments on commit 5fe8522

Please sign in to comment.