mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(task/website): support render subschemas.all_of (#4800)
To solve unexpected snapshot update in #4742 : https://github.com/oxc-project/oxc/pull/4742/files#diff-4c1a03dc03cfd00f9eaecb5c66b61f4e57272c6262253f0dc82ea1b71223bac2
This commit is contained in:
parent
e8de4bde41
commit
4d28d037e6
5 changed files with 57 additions and 12 deletions
|
|
@ -14,6 +14,7 @@ use crate::AllowWarnDeny;
|
|||
// - type SeverityConf = 0 | 1 | 2 | "off" | "warn" | "error";
|
||||
// - type RuleConf = SeverityConf | [SeverityConf, ...any[]];
|
||||
// <https://github.com/eslint/eslint/blob/ce838adc3b673e52a151f36da0eedf5876977514/lib/shared/types.js#L12>
|
||||
// Note: when update document comment, also update `DummyRuleMap`'s description in this file.
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct OxlintRules(Vec<ESLintRule>);
|
||||
|
||||
|
|
@ -42,7 +43,13 @@ impl JsonSchema for OxlintRules {
|
|||
Toggle(AllowWarnDeny),
|
||||
ToggleAndConfig(Vec<serde_json::Value>),
|
||||
}
|
||||
gen.subschema_for::<FxHashMap<String, DummyRule>>()
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Debug, JsonSchema)]
|
||||
#[schemars(description = "See [Oxlint Rules](./rules)")]
|
||||
struct DummyRuleMap(pub FxHashMap<String, DummyRule>);
|
||||
|
||||
gen.subschema_for::<DummyRuleMap>()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -100,6 +100,13 @@ expression: json
|
|||
}
|
||||
]
|
||||
},
|
||||
"DummyRuleMap": {
|
||||
"description": "See [Oxlint Rules](./rules)",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/DummyRule"
|
||||
}
|
||||
},
|
||||
"GlobalValue": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
@ -208,10 +215,7 @@ expression: json
|
|||
}
|
||||
},
|
||||
"OxlintRules": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/DummyRule"
|
||||
}
|
||||
"$ref": "#/definitions/DummyRuleMap"
|
||||
},
|
||||
"OxlintSettings": {
|
||||
"description": "Shared settings for plugins",
|
||||
|
|
|
|||
|
|
@ -96,6 +96,13 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"DummyRuleMap": {
|
||||
"description": "See [Oxlint Rules](./rules)",
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/DummyRule"
|
||||
}
|
||||
},
|
||||
"GlobalValue": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
|
|
@ -204,10 +211,7 @@
|
|||
}
|
||||
},
|
||||
"OxlintRules": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"$ref": "#/definitions/DummyRule"
|
||||
}
|
||||
"$ref": "#/definitions/DummyRuleMap"
|
||||
},
|
||||
"OxlintSettings": {
|
||||
"description": "Shared settings for plugins",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use handlebars::Handlebars;
|
||||
use oxc_linter::OxlintConfig;
|
||||
use schemars::{
|
||||
schema::{RootSchema, Schema, SchemaObject, SingleOrVec},
|
||||
schema::{RootSchema, Schema, SchemaObject, SingleOrVec, SubschemaValidation},
|
||||
schema_for,
|
||||
};
|
||||
use serde::Serialize;
|
||||
|
|
@ -140,12 +140,41 @@ impl Renderer {
|
|||
return object
|
||||
.properties
|
||||
.iter()
|
||||
.map(|(key, schema)| {
|
||||
.flat_map(|(key, schema)| {
|
||||
let key = parent_key.map_or_else(|| key.clone(), |k| format!("{k}.{key}"));
|
||||
self.render_schema(depth + 1, &key, Self::get_schema_object(schema))
|
||||
let schema_object = Self::get_schema_object(schema);
|
||||
|
||||
if let Some(subschemas) = &schema_object.subschemas {
|
||||
return self.render_sub_schema(depth, &key, subschemas);
|
||||
}
|
||||
|
||||
vec![self.render_schema(depth + 1, &key, schema_object)]
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
if let Some(subschemas) = &schema.subschemas {
|
||||
let key = parent_key.unwrap_or("");
|
||||
return self.render_sub_schema(depth, key, subschemas);
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
fn render_sub_schema(
|
||||
&self,
|
||||
depth: usize,
|
||||
key: &str,
|
||||
subschemas: &SubschemaValidation,
|
||||
) -> Vec<Section> {
|
||||
if let Some(schemas) = &subschemas.all_of {
|
||||
return schemas
|
||||
.iter()
|
||||
.map(|schema| {
|
||||
let schema = Self::get_schema_object(schema);
|
||||
let schema = self.get_referenced_schema(schema);
|
||||
self.render_schema(depth + 1, key, schema)
|
||||
})
|
||||
.collect::<Vec<Section>>();
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ Add or remove global variables.
|
|||
|
||||
## rules
|
||||
|
||||
type: `object`
|
||||
|
||||
See [Oxlint Rules](./rules)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue