Skip to content
Merged
Show file tree
Hide file tree
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
39 changes: 38 additions & 1 deletion crates/oxc_linter/src/config/oxlintrc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ impl Oxlintrc {
/// Panics if the schema generation fails.
pub fn generate_schema_json() -> String {
let mut schema = schema_for!(Oxlintrc);

// Allow comments and trailing commas for vscode-json-languageservice
// NOTE: This is NOT part of standard JSON Schema specification
// https://github.com/microsoft/vscode-json-languageservice/blob/fb83547762901f32d8449d57e24666573016b10c/src/jsonLanguageTypes.ts#L151-L159
Expand All @@ -212,7 +213,43 @@ impl Oxlintrc {
.schema
.extensions
.insert("allowTrailingCommas".to_string(), serde_json::Value::Bool(true));
serde_json::to_string_pretty(&schema).unwrap()

// Inject markdownDescription fields for better editor support (e.g., VS Code)
let mut json = serde_json::to_value(&schema).unwrap();
Self::inject_markdown_descriptions(&mut json);

serde_json::to_string_pretty(&json).unwrap()
}

/// Recursively inject `markdownDescription` fields into the JSON schema.
/// This is a non-standard field that some editors (like VS Code) use to render
/// markdown in hover tooltips.
fn inject_markdown_descriptions(value: &mut serde_json::Value) {
match value {
serde_json::Value::Object(map) => {
// If this object has a `description` field, copy it to `markdownDescription`
if let Some(serde_json::Value::String(desc_str)) = map.get("description") {
map.insert(
"markdownDescription".to_string(),
serde_json::Value::String(desc_str.clone()),
);
}

// Recursively process all values in the object
for value in map.values_mut() {
Self::inject_markdown_descriptions(value);
}
}
serde_json::Value::Array(items) => {
// Recursively process all items in the array
for item in items {
Self::inject_markdown_descriptions(item);
}
}
_ => {
// Primitive values don't need processing
}
}
}

/// Merges two [Oxlintrc] files together
Expand Down
Loading
Loading