Skip to content

Commit

Permalink
feat(oxlint): add --working-dir argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Sysix committed Nov 19, 2024
1 parent 5af54d4 commit 631301a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
6 changes: 3 additions & 3 deletions apps/oxlint/src/command/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ pub struct BasicOptions {
/// TypeScript `tsconfig.json` path for reading path alias and project references for import plugin
#[bpaf(argument("./tsconfig.json"), hide_usage)]
pub tsconfig: Option<PathBuf>,

/// The working directory where oxlint should be executed
/// defaults to `env::current_dir()`
#[bpaf(long("working-dir"), hide_usage)]
/// appends the path to the current work directory
#[bpaf(long("working-dir"), argument("./package/sub-package"), hide_usage)]
pub working_dir: Option<PathBuf>,
}

Expand Down
15 changes: 9 additions & 6 deletions apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,19 @@ impl Runner for LintRunner {
let now = Instant::now();

let mut cwd = env::current_dir().expect("Failed to get current working directory");

// append the working directory paths
if let Some(working_dir) = basic_options.working_dir {
cwd.push(working_dir);

paths = paths.into_iter().map(|x| {
let mut new = cwd.clone();
new.push(x);
new
}).collect()
paths = paths
.into_iter()
.map(|x| {
let mut new = cwd.clone();
new.push(x);
new
})
.collect()
}

// The ignore crate whitelists explicit paths, but priority
Expand Down
3 changes: 3 additions & 0 deletions tasks/website/src/linter/snapshots/cli.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tasks/website/src/linter/cli.rs
expression: snapshot
snapshot_kind: text
---
## Usage
**`oxlint`** \[**`-c`**=_`<./oxlintrc.json>`_\] \[_`PATH`_\]...
Expand All @@ -12,6 +13,8 @@ expression: snapshot
* tries to be compatible with the ESLint v8's format
- **` --tsconfig`**=_`<./tsconfig.json>`_ &mdash;
TypeScript `tsconfig.json` path for reading path alias and project references for import plugin
- **` --working-dir`**=_`<./package/sub-package>`_ &mdash;
The working directory where oxlint should be executed appends the path to the current work directory



Expand Down
3 changes: 3 additions & 0 deletions tasks/website/src/linter/snapshots/cli_terminal.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: tasks/website/src/linter/cli.rs
expression: snapshot
snapshot_kind: text
---
Usage: [-c=<./oxlintrc.json>] [PATH]...

Expand All @@ -10,6 +11,8 @@ Basic Configuration
* tries to be compatible with the ESLint v8's format
--tsconfig=<./tsconfig.json> TypeScript `tsconfig.json` path for reading path alias and
project references for import plugin
--working-dir=<./package/sub-package> The working directory where oxlint should be executed
appends the path to the current work directory

Allowing / Denying Multiple Lints
Accumulate rules and categories from left to right on the command-line.
Expand Down

0 comments on commit 631301a

Please sign in to comment.