Skip to content

Commit 030e397

Browse files
committed
refactor(linter): simplify parsing CLI args (oxc-project#12802)
Pure refactor. Just simplify this code a little and move comment about what it does.
1 parent 5475075 commit 030e397

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

apps/oxlint/src/lib.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{ffi::OsStr, io::BufWriter};
1+
use std::io::BufWriter;
22

33
pub use oxc_linter::{
44
ExternalLinter, ExternalLinterLintFileCb, ExternalLinterLoadPluginCb, LintFileResult,
@@ -29,16 +29,14 @@ pub fn lint(external_linter: Option<ExternalLinter>) -> CliRunResult {
2929
init_tracing();
3030
init_miette();
3131

32-
let mut args = std::env::args_os().peekable();
33-
34-
let args = match args.peek() {
35-
Some(s) if s == OsStr::new("node") => args.skip(2),
36-
_ => args.skip(1),
37-
};
32+
let mut args = std::env::args_os();
33+
// If first arg is `node`, also skip script path (`node script.js ...`).
34+
// Otherwise, just skip first arg (`oxlint ...`).
35+
if args.next().is_some_and(|arg| arg == "node") {
36+
args.next();
37+
}
3838
let args = args.collect::<Vec<_>>();
3939

40-
// SAFELY skip first two args (node + script.js)
41-
// let cli_args = std::env::args_os().skip(2);
4240
let cmd = crate::cli::lint_command();
4341
let command = match cmd.run_inner(&*args) {
4442
Ok(cmd) => cmd,

0 commit comments

Comments
 (0)