chore(cli): improve help message (#3309)

Added a CLI page https://oxc-project.github.io/docs/guide/usage/linter-cli.html
This commit is contained in:
Boshen 2024-05-16 11:53:33 +00:00
parent 8ab9856dea
commit e4d94dc379
2 changed files with 25 additions and 18 deletions

View file

@ -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<PathBuf>,
}
/// 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<PathBuf>,
/// Single file, single path or list of paths
#[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE), map(expand_glob))]
pub paths: Vec<PathBuf>,
}
// 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(

View file

@ -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() };