Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
199 changes: 0 additions & 199 deletions crates/oxc_linter/src/config/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,26 +47,6 @@ impl Default for LintPlugins {
}
}

impl From<LintPluginOptions> 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]
Expand Down Expand Up @@ -241,182 +221,3 @@ impl JsonSchema for LintPlugins {
r#gen.subschema_for::<Vec<LintPluginOptionsSchema>>()
}
}

#[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<S: AsRef<str>> FromIterator<(S, bool)> for LintPluginOptions {
fn from_iter<I: IntoIterator<Item = (S, bool)>>(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<T: IntoIterator<Item = &'s str>>(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);
}
}
Loading