Skip to content

Commit 9304f9f

Browse files
authored
fix(linter): Fix JSON schema to deny additional properties for plugins enum. (#15259)
This ensures that VS Code and other editors will not accept unknown values for the plugins field. I believe `string` was allowed initially because of the way jsPlugins were going to be implemented (see #12117), but then the jsPlugins plans changed to use a separate config field? I'm not 100% sure, but that appears to be the case. Anyway, the schema was never updated after that pivot, and so this fixes the problem. We could probably remove the `any_of` to simplify things, but eh I just want to fix this for now. With this change, jsPlugins still allows arbitrary values, while `plugins` only allows known values: <img width="222" height="280" alt="Screenshot 2025-11-03 at 11 16 41 PM" src="https://github.com/user-attachments/assets/7f7c8756-f9c3-4dad-8642-189197cfa1cc" /> In the future, it'd probably be good to add tests to do basic schema validation (e.g. here are 10 JSON blobs that should pass, here are 10 JSON blobs that should fail) so we can ensure regressions don't occur for this kind of developer experience nice-to-have. Part of #15247.
1 parent b4ebdf5 commit 9304f9f

File tree

3 files changed

+1
-14
lines changed

3 files changed

+1
-14
lines changed

crates/oxc_linter/src/config/plugins.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,9 @@ impl JsonSchema for LintPlugins {
249249

250250
let enum_schema = r#gen.subschema_for::<LintPluginOptionsSchema>();
251251

252-
let string_schema = Schema::Object(schemars::schema::SchemaObject {
253-
instance_type: Some(schemars::schema::SingleOrVec::Single(Box::new(
254-
schemars::schema::InstanceType::String,
255-
))),
256-
..Default::default()
257-
});
258-
259252
let item_schema = Schema::Object(schemars::schema::SchemaObject {
260253
subschemas: Some(Box::new(schemars::schema::SubschemaValidation {
261-
any_of: Some(vec![enum_schema, string_schema]),
254+
any_of: Some(vec![enum_schema]),
262255
..Default::default()
263256
})),
264257
..Default::default()

crates/oxc_linter/src/snapshots/schema_json.snap

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ expression: json
327327
"anyOf": [
328328
{
329329
"$ref": "#/definitions/LintPluginOptionsSchema"
330-
},
331-
{
332-
"type": "string"
333330
}
334331
]
335332
}

npm/oxlint/configuration_schema.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@
323323
"anyOf": [
324324
{
325325
"$ref": "#/definitions/LintPluginOptionsSchema"
326-
},
327-
{
328-
"type": "string"
329326
}
330327
]
331328
}

0 commit comments

Comments
 (0)