From e4d94dc379f45477740b751e3adbbc01be856e20 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Thu, 16 May 2024 11:53:33 +0000 Subject: [PATCH] chore(cli): improve help message (#3309) Added a CLI page https://oxc-project.github.io/docs/guide/usage/linter-cli.html --- crates/oxc_cli/src/command/lint.rs | 37 ++++++++++++++++++------------ crates/oxc_cli/src/lint/mod.rs | 6 ++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/crates/oxc_cli/src/command/lint.rs b/crates/oxc_cli/src/command/lint.rs index f01af98ab..f04daa839 100644 --- a/crates/oxc_cli/src/command/lint.rs +++ b/crates/oxc_cli/src/command/lint.rs @@ -27,7 +27,10 @@ impl LintCommand { #[derive(Debug, Clone, Bpaf)] pub struct LintOptions { - #[bpaf(external(lint_filter), map(LintFilter::into_tuple), many)] + #[bpaf(external)] + pub basic_options: BasicOptions, + + #[bpaf(external(lint_filter), map(LintFilter::into_tuple), many, hide_usage)] pub filter: Vec<(AllowWarnDeny, String)>, #[bpaf(external)] @@ -52,6 +55,14 @@ pub struct LintOptions { #[bpaf(external)] pub misc_options: MiscOptions, + /// Single file, single path or list of paths + #[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE), map(expand_glob))] + pub paths: Vec, +} + +/// Basic Configuration +#[derive(Debug, Clone, Bpaf)] +pub struct BasicOptions { /// ESLint configuration file (experimental) /// /// * only `.json` extension is supported @@ -61,10 +72,6 @@ pub struct LintOptions { /// TypeScript `tsconfig.json` path for reading path alias and project references for import plugin #[bpaf(argument("./tsconfig.json"), hide_usage)] pub tsconfig: Option, - - /// Single file, single path or list of paths - #[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE), map(expand_glob))] - pub paths: Vec, } // This is formatted according to @@ -72,18 +79,18 @@ pub struct LintOptions { /// Allowing / Denying Multiple Lints /// For example `-D correctness -A no-debugger` or `-A all -D no-debugger`. /// ㅤ -/// The default category is "-D correctness". -/// Use "--rules" for rule names. -/// Use "--help --help" for rule categories. +/// The default category is `-D correctness`. +/// Use `--rules` for rule names. +/// Use `--help --help` for rule categories. /// /// The categories are: -/// * correctness - code that is outright wrong or useless -/// * suspicious - code that is most likely wrong or useless -/// * pedantic - lints which are rather strict or have occasional false positives -/// * style - code that should be written in a more idiomatic way -/// * nursery - new lints that are still under development -/// * restriction - lints which prevent the use of language and library features -/// * all - all the categories listed above +/// * `correctness` - code that is outright wrong or useless +/// * `suspicious` - code that is most likely wrong or useless +/// * `pedantic` - lints which are rather strict or have occasional false positives +/// * `style` - code that should be written in a more idiomatic way +/// * `nursery` - new lints that are still under development +/// * `restriction` - lints which prevent the use of language and library features +/// * `all` - all the categories listed above #[derive(Debug, Clone, Bpaf)] pub enum LintFilter { Allow( diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index e93b03ccc..ded1d1947 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -34,12 +34,11 @@ impl Runner for LintRunner { let CliLintOptions { paths, filter, + basic_options, warning_options, ignore_options, fix_options, enable_plugins, - config, - tsconfig, output_options, .. } = self.options; @@ -92,7 +91,7 @@ impl Runner for LintRunner { let cwd = std::env::current_dir().unwrap().into_boxed_path(); let lint_options = LintOptions::default() .with_filter(filter) - .with_config_path(config) + .with_config_path(basic_options.config) .with_fix(fix_options.fix) .with_react_plugin(enable_plugins.react_plugin) .with_unicorn_plugin(enable_plugins.unicorn_plugin) @@ -117,6 +116,7 @@ impl Runner for LintRunner { } }; + let tsconfig = basic_options.tsconfig; if let Some(path) = tsconfig.as_ref() { if !path.is_file() { let path = if path.is_relative() { cwd.join(path) } else { path.clone() };