feat(cli): run oxlint with no file arguments (#1201)

closes #1190

See: `https://github.com/eslint/eslint/issues/14308`
This commit is contained in:
Boshen 2023-11-09 11:22:13 +08:00 committed by GitHub
parent a503586d3e
commit d82ba5b523
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 8 deletions

View file

@ -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 Under the hood, `cargo instruments` invokes the `xcrun` command, equivalent to
```bash ```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 Running the command above produces the following output

View file

@ -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`: To start using, install [oxlint][npm-oxlint] or via `npx`:
```bash ```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. 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.
@ -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: our linter only requires a single command that you can immediately run on your codebase:
```bash ```bash
npx oxlint@latest . npx oxlint@latest
``` ```
We also plan to port essential plugins such as [eslint-plugin-import] and [eslint-plugin-jest]. We also plan to port essential plugins such as [eslint-plugin-import] and [eslint-plugin-jest].

View file

@ -14,7 +14,7 @@ fn main() -> CliRunResult {
init_tracing(); init_tracing();
init_miette(); init_miette();
let command = oxc_cli::lint_command().fallback_to_usage().run(); let command = oxc_cli::lint_command().run();
command.handle_threads(); command.handle_threads();
LintRunner::new(command.lint_options).run() LintRunner::new(command.lint_options).run()
} }

View file

@ -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_diagnostics::DiagnosticService;
use oxc_linter::{LintOptions, LintService, Linter}; use oxc_linter::{LintOptions, LintService, Linter};
@ -37,8 +37,16 @@ impl Runner for LintRunner {
enable_plugins, enable_plugins,
} = self.options; } = self.options;
let mut paths = paths;
if paths.is_empty() { 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(); let now = std::time::Instant::now();
@ -158,6 +166,16 @@ mod test {
test(args); 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] #[test]
fn dir() { fn dir() {
let args = &["fixtures"]; let args = &["fixtures"];

View file

@ -44,8 +44,8 @@ This is the linter for oxc.
Run Run
* `npx --yes oxlint@latest .` in your JavaScript / TypeScript codebase and see it complete in milliseconds. No configurations are required. * `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 --help` for usage instructions.
* `npx oxlint@latest --rules` for the list of rules. * `npx oxlint@latest --rules` for the list of rules.