mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(linter): impl serde and schemars traits for LintPlugins (#5706)
This commit is contained in:
parent
7caae5bca7
commit
f61e8b53dd
1 changed files with 56 additions and 0 deletions
|
|
@ -1,4 +1,6 @@
|
||||||
use bitflags::bitflags;
|
use bitflags::bitflags;
|
||||||
|
use schemars::{gen::SchemaGenerator, schema::Schema, JsonSchema};
|
||||||
|
use serde::{de::Deserializer, ser::Serializer, Deserialize, Serialize};
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
// NOTE: may be increased to a u32 if needed
|
// NOTE: may be increased to a u32 if needed
|
||||||
|
|
@ -105,6 +107,60 @@ impl From<&str> for LintPlugins {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<LintPlugins> for &'static str {
|
||||||
|
fn from(value: LintPlugins) -> Self {
|
||||||
|
match value {
|
||||||
|
LintPlugins::REACT => "react",
|
||||||
|
LintPlugins::UNICORN => "unicorn",
|
||||||
|
LintPlugins::TYPESCRIPT => "typescript",
|
||||||
|
LintPlugins::OXC => "oxc",
|
||||||
|
LintPlugins::IMPORT => "import",
|
||||||
|
LintPlugins::JSDOC => "jsdoc",
|
||||||
|
LintPlugins::JEST => "jest",
|
||||||
|
LintPlugins::VITEST => "vitest",
|
||||||
|
LintPlugins::JSX_A11Y => "jsx-a11y",
|
||||||
|
LintPlugins::NEXTJS => "nextjs",
|
||||||
|
LintPlugins::REACT_PERF => "react-perf",
|
||||||
|
LintPlugins::PROMISE => "promise",
|
||||||
|
LintPlugins::NODE => "node",
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<S: AsRef<str>> FromIterator<S> for LintPlugins {
|
||||||
|
fn from_iter<T: IntoIterator<Item = S>>(iter: T) -> Self {
|
||||||
|
iter.into_iter()
|
||||||
|
.map(|plugin| plugin.as_ref().into())
|
||||||
|
.fold(LintPlugins::default(), LintPlugins::union)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'de> Deserialize<'de> for LintPlugins {
|
||||||
|
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
|
||||||
|
Vec::<&str>::deserialize(deserializer).map(|vec| vec.into_iter().collect())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Serialize for LintPlugins {
|
||||||
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||||
|
let vec: Vec<&str> = self.iter().map(Into::into).collect();
|
||||||
|
vec.serialize(serializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl JsonSchema for LintPlugins {
|
||||||
|
fn schema_name() -> String {
|
||||||
|
"LintPlugins".to_string()
|
||||||
|
}
|
||||||
|
fn schema_id() -> std::borrow::Cow<'static, str> {
|
||||||
|
std::borrow::Cow::Borrowed("LintPlugins")
|
||||||
|
}
|
||||||
|
fn json_schema(gen: &mut SchemaGenerator) -> Schema {
|
||||||
|
gen.subschema_for::<Vec<&str>>()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[non_exhaustive]
|
#[non_exhaustive]
|
||||||
pub struct LintPluginOptions {
|
pub struct LintPluginOptions {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue