From ba2121f17dc1fd083243c9a20acc75dfdc80e672 Mon Sep 17 00:00:00 2001 From: Yuji Sugiura <6259812+leaysgur@users.noreply.github.com> Date: Fri, 12 Apr 2024 11:39:12 +0900 Subject: [PATCH] feat(linter): Add --jsdoc-plugin flag (#2935) Add flag to: ```sh $ oxlint --jsdoc-plugin ``` ![image](https://github.com/oxc-project/oxc/assets/6259812/0e12ceab-966f-47e1-b4b9-5bc2eb6bdb56) --- crates/oxc_cli/src/command/lint.rs | 4 ++++ crates/oxc_cli/src/lint/mod.rs | 1 + crates/oxc_linter/src/options.rs | 14 +++++++++++++- tasks/benchmark/benches/linter.rs | 6 +++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/oxc_cli/src/command/lint.rs b/crates/oxc_cli/src/command/lint.rs index 780a88578..2f1e2a53b 100644 --- a/crates/oxc_cli/src/command/lint.rs +++ b/crates/oxc_cli/src/command/lint.rs @@ -165,6 +165,10 @@ pub struct EnablePlugins { #[bpaf(switch, hide_usage)] pub import_plugin: bool, + /// Enable the experimental jsdoc plugin and detect JSDoc problems + #[bpaf(switch, hide_usage)] + pub jsdoc_plugin: bool, + /// Enable the Jest plugin and detect test problems #[bpaf(switch, hide_usage)] pub jest_plugin: bool, diff --git a/crates/oxc_cli/src/lint/mod.rs b/crates/oxc_cli/src/lint/mod.rs index 321ef693c..8c911d6e8 100644 --- a/crates/oxc_cli/src/lint/mod.rs +++ b/crates/oxc_cli/src/lint/mod.rs @@ -95,6 +95,7 @@ impl Runner for LintRunner { .with_config_path(config) .with_fix(fix_options.fix) .with_import_plugin(enable_plugins.import_plugin) + .with_jsdoc_plugin(enable_plugins.jsdoc_plugin) .with_jest_plugin(enable_plugins.jest_plugin) .with_jsx_a11y_plugin(enable_plugins.jsx_a11y_plugin) .with_nextjs_plugin(enable_plugins.nextjs_plugin) diff --git a/crates/oxc_linter/src/options.rs b/crates/oxc_linter/src/options.rs index 3db83150a..37fd69c74 100644 --- a/crates/oxc_linter/src/options.rs +++ b/crates/oxc_linter/src/options.rs @@ -24,6 +24,7 @@ pub struct LintOptions { pub fix: bool, pub timing: bool, pub import_plugin: bool, + pub jsdoc_plugin: bool, pub jest_plugin: bool, pub jsx_a11y_plugin: bool, pub nextjs_plugin: bool, @@ -39,6 +40,7 @@ impl Default for LintOptions { fix: false, timing: false, import_plugin: false, + jsdoc_plugin: false, jest_plugin: false, jsx_a11y_plugin: false, nextjs_plugin: false, @@ -81,6 +83,12 @@ impl LintOptions { self } + #[must_use] + pub fn with_jsdoc_plugin(mut self, yes: bool) -> Self { + self.jsdoc_plugin = yes; + self + } + #[must_use] pub fn with_jest_plugin(mut self, yes: bool) -> Self { self.jest_plugin = yes; @@ -167,6 +175,8 @@ impl TryFrom<&Number> for AllowWarnDeny { } } +const IMPORT_PLUGIN_NAME: &str = "import"; +const JSDOC_PLUGIN_NAME: &str = "jsdoc"; const JEST_PLUGIN_NAME: &str = "jest"; const JSX_A11Y_PLUGIN_NAME: &str = "jsx_a11y"; const NEXTJS_PLUGIN_NAME: &str = "nextjs"; @@ -236,7 +246,7 @@ impl LintOptions { Ok((rules, settings, env)) } - // get final filtered rules by reading `self.jest_plugin` and `self.jsx_a11y_plugin` + // get final filtered rules by reading `self.xxx_plugin` fn get_filtered_rules(&self) -> Vec { let mut rules = RULES.clone(); @@ -246,6 +256,8 @@ impl LintOptions { } }; + may_exclude_plugin_rules(self.import_plugin, IMPORT_PLUGIN_NAME); + may_exclude_plugin_rules(self.jsdoc_plugin, JSDOC_PLUGIN_NAME); may_exclude_plugin_rules(self.jest_plugin, JEST_PLUGIN_NAME); may_exclude_plugin_rules(self.jsx_a11y_plugin, JSX_A11Y_PLUGIN_NAME); may_exclude_plugin_rules(self.nextjs_plugin, NEXTJS_PLUGIN_NAME); diff --git a/tasks/benchmark/benches/linter.rs b/tasks/benchmark/benches/linter.rs index 429095c8d..ea7a5b0d9 100644 --- a/tasks/benchmark/benches/linter.rs +++ b/tasks/benchmark/benches/linter.rs @@ -34,8 +34,12 @@ fn bench_linter(criterion: &mut Criterion) { .build(program); let lint_options = LintOptions::default() .with_filter(vec![(AllowWarnDeny::Deny, "all".into())]) + .with_import_plugin(true) + .with_jsdoc_plugin(true) .with_jest_plugin(true) - .with_jsx_a11y_plugin(true); + .with_jsx_a11y_plugin(true) + .with_nextjs_plugin(true) + .with_react_perf_plugin(true); let linter = Linter::from_options(lint_options).unwrap(); let semantic = Rc::new(semantic_ret.semantic); b.iter(|| {