diff --git a/apps/oxlint/src-js/package/config.generated.ts b/apps/oxlint/src-js/package/config.generated.ts index 814e87f639f54..e77f25ed6312f 100644 --- a/apps/oxlint/src-js/package/config.generated.ts +++ b/apps/oxlint/src-js/package/config.generated.ts @@ -57,7 +57,7 @@ export type LintPluginOptionsSchema = | "node" | "vue"; export type LintPlugins = LintPluginOptionsSchema[]; -export type DummyRule = AllowWarnDeny | unknown[]; +export type DummyRule = AllowWarnDeny | [AllowWarnDeny, ...unknown[]]; export type OxlintOverrides = OxlintOverride[]; export type TagNamePreference = | string diff --git a/crates/oxc_linter/src/config/rules.rs b/crates/oxc_linter/src/config/rules.rs index 459289985eb6d..8bba05d40bb2e 100644 --- a/crates/oxc_linter/src/config/rules.rs +++ b/crates/oxc_linter/src/config/rules.rs @@ -2,7 +2,11 @@ use std::{borrow::Cow, fmt}; use itertools::Itertools; use rustc_hash::FxHashMap; -use schemars::{JsonSchema, r#gen::SchemaGenerator, schema::Schema}; +use schemars::{ + JsonSchema, + r#gen::SchemaGenerator, + schema::{ArrayValidation, InstanceType, Schema, SchemaObject}, +}; use serde::{ Deserialize, Serialize, Serializer, de::{self, Deserializer, Visitor}, @@ -243,7 +247,38 @@ impl JsonSchema for OxlintRules { #[serde(untagged)] enum DummyRule { Toggle(AllowWarnDeny), - ToggleAndConfig(Vec), + ToggleAndConfig(ToggleAndConfig), + } + + #[derive(Debug, Clone)] + struct ToggleAndConfig; + + impl JsonSchema for ToggleAndConfig { + fn is_referenceable() -> bool { + false + } + + fn schema_name() -> String { + "ToggleAndConfig".to_string() + } + + fn schema_id() -> Cow<'static, str> { + "ToggleAndConfig".into() + } + + fn json_schema(r#gen: &mut SchemaGenerator) -> Schema { + SchemaObject { + instance_type: Some(InstanceType::Array.into()), + array: Some(Box::new(ArrayValidation { + items: Some(vec![r#gen.subschema_for::()].into()), + min_items: Some(1), + additional_items: Some(Box::new(Schema::Bool(true))), + ..Default::default() + })), + ..Default::default() + } + .into() + } } #[expect(unused)] diff --git a/npm/oxlint/configuration_schema.json b/npm/oxlint/configuration_schema.json index c3a8939d967f2..b094a7d347ca3 100644 --- a/npm/oxlint/configuration_schema.json +++ b/npm/oxlint/configuration_schema.json @@ -224,7 +224,13 @@ }, { "type": "array", - "items": true + "items": [ + { + "$ref": "#/definitions/AllowWarnDeny" + } + ], + "additionalItems": true, + "minItems": 1 } ] }, @@ -761,4 +767,4 @@ } }, "markdownDescription": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json`\n\nExample\n\n`.oxlintrc.json`\n\n```json\n{\n\"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n\"plugins\": [\"import\", \"typescript\", \"unicorn\"],\n\"env\": {\n\"browser\": true\n},\n\"globals\": {\n\"foo\": \"readonly\"\n},\n\"settings\": {\n\"react\": {\n\"version\": \"18.2.0\"\n},\n\"custom\": { \"option\": true }\n},\n\"rules\": {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\n\"overrides\": [\n{\n\"files\": [\"*.test.ts\", \"*.spec.ts\"],\n\"rules\": {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n}\n```\n\n`oxlint.config.ts`\n\n```ts\nimport { defineConfig } from \"oxlint\";\n\nexport default defineConfig({\nplugins: [\"import\", \"typescript\", \"unicorn\"],\nenv: {\n\"browser\": true\n},\nglobals: {\n\"foo\": \"readonly\"\n},\nsettings: {\nreact: {\nversion: \"18.2.0\"\n},\ncustom: { option: true }\n},\nrules: {\n\"eqeqeq\": \"warn\",\n\"import/no-cycle\": \"error\",\n\"react/self-closing-comp\": [\"error\", { \"html\": false }]\n},\noverrides: [\n{\nfiles: [\"*.test.ts\", \"*.spec.ts\"],\nrules: {\n\"@typescript-eslint/no-explicit-any\": \"off\"\n}\n}\n]\n});\n```" -} +} \ No newline at end of file diff --git a/tasks/website_linter/src/snapshots/schema_json.snap b/tasks/website_linter/src/snapshots/schema_json.snap index cbe3fe96f7cbc..f388f041bf346 100644 --- a/tasks/website_linter/src/snapshots/schema_json.snap +++ b/tasks/website_linter/src/snapshots/schema_json.snap @@ -228,7 +228,13 @@ expression: json }, { "type": "array", - "items": true + "items": [ + { + "$ref": "#/definitions/AllowWarnDeny" + } + ], + "additionalItems": true, + "minItems": 1 } ] },