diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs index d70da6f072810..67570f3c1d99b 100644 --- a/crates/oxc_linter/src/config/rules.rs +++ b/crates/oxc_linter/src/config/rules.rs @@ -14,6 +14,7 @@ use crate::AllowWarnDeny; // - type SeverityConf = 0 | 1 | 2 | "off" | "warn" | "error"; // - type RuleConf = SeverityConf | [SeverityConf, ...any[]]; // +// Note: when update document comment, also update `DummyRuleMap`'s description in this file. #[derive(Debug, Clone, Default)] pub struct OxlintRules(Vec); @@ -42,7 +43,13 @@ impl JsonSchema for OxlintRules { Toggle(AllowWarnDeny), ToggleAndConfig(Vec), } - gen.subschema_for::>() + + #[allow(unused)] + #[derive(Debug, JsonSchema)] + #[schemars(description = "See [Oxlint Rules](./rules)")] + struct DummyRuleMap(pub FxHashMap); + + gen.subschema_for::() } } diff --git a/crates/oxc_linter/src/snapshots/schema_json.snap b/crates/oxc_linter/src/snapshots/schema_json.snap index 1005698068189..929e03c8408c2 100644 --- a/crates/oxc_linter/src/snapshots/schema_json.snap +++ b/crates/oxc_linter/src/snapshots/schema_json.snap @@ -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", diff --git a/npm/oxlint/configuration_schema.json b/npm/oxlint/configuration_schema.json index f87fc078da0d5..c3d4ea510056a 100644 --- a/npm/oxlint/configuration_schema.json +++ b/npm/oxlint/configuration_schema.json @@ -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", diff --git a/tasks/website/src/linter/json_schema.rs b/tasks/website/src/linter/json_schema.rs index 3f31232965a6f..b42d138546a43 100644 --- a/tasks/website/src/linter/json_schema.rs +++ b/tasks/website/src/linter/json_schema.rs @@ -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::>(); } + 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
{ + 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![] } diff --git a/tasks/website/src/linter/snapshots/schema_markdown.snap b/tasks/website/src/linter/snapshots/schema_markdown.snap index 819563aa57524..ae6f0c29ab6a0 100644 --- a/tasks/website/src/linter/snapshots/schema_markdown.snap +++ b/tasks/website/src/linter/snapshots/schema_markdown.snap @@ -52,6 +52,7 @@ Add or remove global variables. ## rules +type: `object` See [Oxlint Rules](./rules)