From 8404da45d6804f826460262abd6653b06defbcd1 Mon Sep 17 00:00:00 2001 From: camc314 <18101008+camc314@users.noreply.github.com> Date: Thu, 26 Jun 2025 09:23:34 +0000 Subject: [PATCH] refactor(linter): remove unused `LintPluginOptions` (#11919) --- crates/oxc_linter/src/config/plugins.rs | 199 ------------------------ 1 file changed, 199 deletions(-) diff --git a/crates/oxc_linter/src/config/plugins.rs b/crates/oxc_linter/src/config/plugins.rs index 7f0c5b8fefdb5..b95a1784e498b 100644 --- a/crates/oxc_linter/src/config/plugins.rs +++ b/crates/oxc_linter/src/config/plugins.rs @@ -47,26 +47,6 @@ impl Default for LintPlugins { } } -impl From for LintPlugins { - fn from(options: LintPluginOptions) -> Self { - let mut plugins = LintPlugins::empty(); - plugins.set(LintPlugins::REACT, options.react); - plugins.set(LintPlugins::UNICORN, options.unicorn); - plugins.set(LintPlugins::TYPESCRIPT, options.typescript); - plugins.set(LintPlugins::OXC, options.oxc); - plugins.set(LintPlugins::IMPORT, options.import); - plugins.set(LintPlugins::JSDOC, options.jsdoc); - plugins.set(LintPlugins::JEST, options.jest); - plugins.set(LintPlugins::VITEST, options.vitest); - plugins.set(LintPlugins::JSX_A11Y, options.jsx_a11y); - plugins.set(LintPlugins::NEXTJS, options.nextjs); - plugins.set(LintPlugins::REACT_PERF, options.react_perf); - plugins.set(LintPlugins::PROMISE, options.promise); - plugins.set(LintPlugins::NODE, options.node); - plugins - } -} - impl LintPlugins { /// Returns `true` if the Vitest plugin is enabled. #[inline] @@ -241,182 +221,3 @@ impl JsonSchema for LintPlugins { r#gen.subschema_for::>() } } - -#[derive(Debug)] -#[non_exhaustive] -pub struct LintPluginOptions { - /// On by default. - pub react: bool, - /// On by default. - pub unicorn: bool, - /// On by default. - pub typescript: bool, - /// On by default. - pub oxc: bool, - pub import: bool, - pub jsdoc: bool, - pub jest: bool, - pub vitest: bool, - pub jsx_a11y: bool, - pub nextjs: bool, - pub react_perf: bool, - pub promise: bool, - pub node: bool, -} - -impl Default for LintPluginOptions { - fn default() -> Self { - Self { - react: false, - unicorn: true, - typescript: true, - oxc: true, - import: false, - jsdoc: false, - jest: false, - vitest: false, - jsx_a11y: false, - nextjs: false, - react_perf: false, - promise: false, - node: false, - } - } -} - -impl LintPluginOptions { - /// Create a new instance with all plugins disabled. - #[must_use] - pub fn none() -> Self { - Self { - react: false, - unicorn: false, - typescript: false, - oxc: false, - import: false, - jsdoc: false, - jest: false, - vitest: false, - jsx_a11y: false, - nextjs: false, - react_perf: false, - promise: false, - node: false, - } - } - - /// Create a new instance with all plugins enabled. - #[must_use] - pub fn all() -> Self { - Self { - react: true, - unicorn: true, - typescript: true, - oxc: true, - import: true, - jsdoc: true, - jest: true, - vitest: true, - jsx_a11y: true, - nextjs: true, - react_perf: true, - promise: true, - node: true, - } - } -} - -impl> FromIterator<(S, bool)> for LintPluginOptions { - fn from_iter>(iter: I) -> Self { - let mut options = Self::none(); - for (s, enabled) in iter { - let flags = LintPlugins::from(s.as_ref()); - match flags { - LintPlugins::REACT => options.react = enabled, - LintPlugins::UNICORN => options.unicorn = enabled, - LintPlugins::TYPESCRIPT => options.typescript = enabled, - LintPlugins::OXC => options.oxc = enabled, - LintPlugins::IMPORT => options.import = enabled, - LintPlugins::JSDOC => options.jsdoc = enabled, - LintPlugins::JEST => options.jest = enabled, - LintPlugins::VITEST => options.vitest = enabled, - LintPlugins::JSX_A11Y => options.jsx_a11y = enabled, - LintPlugins::NEXTJS => options.nextjs = enabled, - LintPlugins::REACT_PERF => options.react_perf = enabled, - LintPlugins::PROMISE => options.promise = enabled, - LintPlugins::NODE => options.node = enabled, - _ => {} // ignored - } - } - - options - } -} - -impl<'s> FromIterator<&'s str> for LintPluginOptions { - fn from_iter>(iter: T) -> Self { - iter.into_iter().map(|s| (s, true)).collect() - } -} - -#[cfg(test)] -mod test { - use super::*; - impl PartialEq for LintPluginOptions { - fn eq(&self, other: &Self) -> bool { - self.react == other.react - && self.unicorn == other.unicorn - && self.typescript == other.typescript - && self.oxc == other.oxc - && self.import == other.import - && self.jsdoc == other.jsdoc - && self.jest == other.jest - && self.vitest == other.vitest - && self.jsx_a11y == other.jsx_a11y - && self.nextjs == other.nextjs - && self.react_perf == other.react_perf - && self.promise == other.promise - && self.node == other.node - } - } - - #[test] - fn test_default_conversion() { - let plugins = LintPlugins::default(); - let options = LintPluginOptions::default(); - assert_eq!(LintPlugins::from(options), plugins); - } - - #[test] - fn test_collect_empty() { - let empty: &[&str] = &[]; - let plugins: LintPluginOptions = empty.iter().copied().collect(); - assert_eq!(plugins, LintPluginOptions::none()); - - let empty: Vec<(String, bool)> = vec![]; - let plugins: LintPluginOptions = empty.into_iter().collect(); - assert_eq!(plugins, LintPluginOptions::none()); - } - - #[test] - fn test_collect_strings() { - let enabled = vec!["react", "typescript", "jest"]; - let plugins: LintPluginOptions = enabled.into_iter().collect(); - let expected = LintPluginOptions { - react: true, - unicorn: false, - typescript: true, - oxc: false, - import: false, - jsdoc: false, - jest: true, - vitest: false, - jsx_a11y: false, - nextjs: false, - react_perf: false, - promise: false, - node: false, - }; - assert_eq!(plugins, expected); - } -}