Skip to content

Commit

Permalink
feat(cli): run oxlint with no file arguments (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Nov 9, 2023
1 parent a503586 commit d82ba5b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ The binary is located at `./target/release/oxlint` once the project is built.
Under the hood, `cargo instruments` invokes the `xcrun` command, equivalent to

```bash
xcrun xctrace record --template 'Time Profile' --output . --launch -- /path/to/oxc/target/release/oxlint --quiet .
xcrun xctrace record --template 'Time Profile' --output . --launch -- /path/to/oxc/target/release/oxlint --quiet
```

Running the command above produces the following output
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The linter is ready to catch mistakes for you. It comes with over 60 default rul
To start using, install [oxlint][npm-oxlint] or via `npx`:

```bash
npx oxlint@latest .
npx oxlint@latest
```

To give you an idea of its capabilities, here is an example from the [vscode] repository, which finishes linting 4000+ files in 0.5 seconds.
Expand Down Expand Up @@ -127,7 +127,7 @@ Unlike other linters like [ESLint], which often require intricate configurations
our linter only requires a single command that you can immediately run on your codebase:

```bash
npx oxlint@latest .
npx oxlint@latest
```

We also plan to port essential plugins such as [eslint-plugin-import] and [eslint-plugin-jest].
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_cli/src/lint/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() -> CliRunResult {
init_tracing();
init_miette();

let command = oxc_cli::lint_command().fallback_to_usage().run();
let command = oxc_cli::lint_command().run();
command.handle_threads();
LintRunner::new(command.lint_options).run()
}
Expand Down
22 changes: 20 additions & 2 deletions crates/oxc_cli/src/lint/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{io::BufWriter, path::Path, vec::Vec};
use std::{env, io::BufWriter, path::Path, vec::Vec};

use oxc_diagnostics::DiagnosticService;
use oxc_linter::{LintOptions, LintService, Linter};
Expand Down Expand Up @@ -37,8 +37,16 @@ impl Runner for LintRunner {
enable_plugins,
} = self.options;

let mut paths = paths;

if paths.is_empty() {
return CliRunResult::InvalidOptions { message: "No paths provided.".to_string() };
if let Ok(cwd) = env::current_dir() {
paths.push(cwd);
} else {
return CliRunResult::InvalidOptions {
message: "Failed to get current working directory.".to_string(),
};
}
}

let now = std::time::Instant::now();
Expand Down Expand Up @@ -158,6 +166,16 @@ mod test {
test(args);
}

#[test]
fn no_arg() {
let args = &[];
let result = test(args);
assert!(result.number_of_rules > 0);
assert_eq!(result.number_of_files, 2);
assert_eq!(result.number_of_warnings, 2);
assert_eq!(result.number_of_errors, 0);
}

#[test]
fn dir() {
let args = &["fixtures"];
Expand Down
4 changes: 2 additions & 2 deletions npm/oxlint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ This is the linter for oxc.

Run

* `npx --yes oxlint@latest .` in your JavaScript / TypeScript codebase and see it complete in milliseconds. No configurations are required.
* `npx oxlint@latest` --help for usage instructions.
* `npx --yes oxlint@latest` in your JavaScript / TypeScript codebase and see it complete in milliseconds. No configurations are required.
* `npx oxlint@latest --help` for usage instructions.
* `npx oxlint@latest --rules` for the list of rules.


Expand Down

0 comments on commit d82ba5b

Please sign in to comment.