From 648f8b219456a2e3a8b8ad68329e471f6d7ddff5 Mon Sep 17 00:00:00 2001 From: Dmitry Zakharov Date: Wed, 23 Oct 2024 21:40:34 +0300 Subject: [PATCH] docs(linter): add schema to config examples closes #6762 --- crates/oxc_linter/src/config/categories.rs | 1 + crates/oxc_linter/src/config/globals.rs | 1 + crates/oxc_linter/src/config/oxlintrc.rs | 2 ++ crates/oxc_linter/src/snapshots/schema_json.snap | 6 +++--- npm/oxlint/configuration_schema.json | 6 +++--- tasks/website/src/linter/snapshots/schema_markdown.snap | 7 +++++++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/crates/oxc_linter/src/config/categories.rs b/crates/oxc_linter/src/config/categories.rs index ef79217432825..6eb3ee16d5e60 100644 --- a/crates/oxc_linter/src/config/categories.rs +++ b/crates/oxc_linter/src/config/categories.rs @@ -64,6 +64,7 @@ Rules enabled or disabled this way will be overwritten by individual rules in th # Example ```json { + "$schema": "./node_modules/oxlint/configuration_schema.json", "categories": { "correctness": "warn" }, diff --git a/crates/oxc_linter/src/config/globals.rs b/crates/oxc_linter/src/config/globals.rs index 82069d28917cf..9951fb3beac82 100644 --- a/crates/oxc_linter/src/config/globals.rs +++ b/crates/oxc_linter/src/config/globals.rs @@ -16,6 +16,7 @@ use serde::{de::Visitor, Deserialize, Serialize}; /// ```json /// /// { +/// "$schema": "./node_modules/oxlint/configuration_schema.json", /// "env": { /// "es6": true /// }, diff --git a/crates/oxc_linter/src/config/oxlintrc.rs b/crates/oxc_linter/src/config/oxlintrc.rs index 7e161fbcb7603..d830eccfe675a 100644 --- a/crates/oxc_linter/src/config/oxlintrc.rs +++ b/crates/oxc_linter/src/config/oxlintrc.rs @@ -29,6 +29,8 @@ use crate::{options::LintPlugins, utils::read_to_string}; /// /// ```json /// { +/// "$schema": "./node_modules/oxlint/configuration_schema.json", +/// "plugins": ["import", "unicorn"], /// "env": { /// "browser": true /// }, diff --git a/crates/oxc_linter/src/snapshots/schema_json.snap b/crates/oxc_linter/src/snapshots/schema_json.snap index d2cc90856ced8..d30a04f8800c8 100644 --- a/crates/oxc_linter/src/snapshots/schema_json.snap +++ b/crates/oxc_linter/src/snapshots/schema_json.snap @@ -5,7 +5,7 @@ expression: json { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Oxlintrc", - "description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json { \"env\": { \"browser\": true }, \"globals\": { \"foo\": \"readonly\" }, \"settings\": { }, \"rules\": { \"eqeqeq\": \"warn\", \"import/no-cycle\": \"error\" } } ```", + "description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json { \"$schema\": \"./node_modules/oxlint/configuration_schema.json\", \"plugins\": [\"import\", \"unicorn\"], \"env\": { \"browser\": true }, \"globals\": { \"foo\": \"readonly\" }, \"settings\": { }, \"rules\": { \"eqeqeq\": \"warn\", \"import/no-cycle\": \"error\" } } ```", "type": "object", "properties": { "categories": { @@ -277,7 +277,7 @@ expression: json }, "OxlintCategories": { "title": "Rule Categories", - "description": "Configure an entire category of rules all at once.\n\nRules enabled or disabled this way will be overwritten by individual rules in the `rules` field.\n\n# Example\n```json\n{\n \"categories\": {\n \"correctness\": \"warn\"\n },\n \"rules\": {\n \"eslint/no-unused-vars\": \"error\"\n }\n}\n```", + "description": "Configure an entire category of rules all at once.\n\nRules enabled or disabled this way will be overwritten by individual rules in the `rules` field.\n\n# Example\n```json\n{\n \"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n \"categories\": {\n \"correctness\": \"warn\"\n },\n \"rules\": {\n \"eslint/no-unused-vars\": \"error\"\n }\n}\n```", "examples": [ { "correctness": "warn" @@ -316,7 +316,7 @@ expression: json } }, "OxlintGlobals": { - "description": "Add or remove global variables.\n\nFor each global variable, set the corresponding value equal to `\"writable\"` to allow the variable to be overwritten or `\"readonly\"` to disallow overwriting.\n\nGlobals can be disabled by setting their value to `\"off\"`. For example, in an environment where most Es2015 globals are available but `Promise` is unavailable, you might use this config:\n\n```json\n\n{ \"env\": { \"es6\": true }, \"globals\": { \"Promise\": \"off\" } }\n\n```\n\nYou may also use `\"readable\"` or `false` to represent `\"readonly\"`, and `\"writeable\"` or `true` to represent `\"writable\"`.", + "description": "Add or remove global variables.\n\nFor each global variable, set the corresponding value equal to `\"writable\"` to allow the variable to be overwritten or `\"readonly\"` to disallow overwriting.\n\nGlobals can be disabled by setting their value to `\"off\"`. For example, in an environment where most Es2015 globals are available but `Promise` is unavailable, you might use this config:\n\n```json\n\n{ \"$schema\": \"./node_modules/oxlint/configuration_schema.json\", \"env\": { \"es6\": true }, \"globals\": { \"Promise\": \"off\" } }\n\n```\n\nYou may also use `\"readable\"` or `false` to represent `\"readonly\"`, and `\"writeable\"` or `true` to represent `\"writable\"`.", "type": "object", "additionalProperties": { "$ref": "#/definitions/GlobalValue" diff --git a/npm/oxlint/configuration_schema.json b/npm/oxlint/configuration_schema.json index c921205af3d17..11cb88437cfe2 100644 --- a/npm/oxlint/configuration_schema.json +++ b/npm/oxlint/configuration_schema.json @@ -1,7 +1,7 @@ { "$schema": "http://json-schema.org/draft-07/schema#", "title": "Oxlintrc", - "description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json { \"env\": { \"browser\": true }, \"globals\": { \"foo\": \"readonly\" }, \"settings\": { }, \"rules\": { \"eqeqeq\": \"warn\", \"import/no-cycle\": \"error\" } } ```", + "description": "Oxlint Configuration File\n\nThis configuration is aligned with ESLint v8's configuration schema (`eslintrc.json`).\n\nUsage: `oxlint -c oxlintrc.json --import-plugin`\n\n::: danger NOTE\n\nOnly the `.json` format is supported. You can use comments in configuration files.\n\n:::\n\nExample\n\n`.oxlintrc.json`\n\n```json { \"$schema\": \"./node_modules/oxlint/configuration_schema.json\", \"plugins\": [\"import\", \"unicorn\"], \"env\": { \"browser\": true }, \"globals\": { \"foo\": \"readonly\" }, \"settings\": { }, \"rules\": { \"eqeqeq\": \"warn\", \"import/no-cycle\": \"error\" } } ```", "type": "object", "properties": { "categories": { @@ -273,7 +273,7 @@ }, "OxlintCategories": { "title": "Rule Categories", - "description": "Configure an entire category of rules all at once.\n\nRules enabled or disabled this way will be overwritten by individual rules in the `rules` field.\n\n# Example\n```json\n{\n \"categories\": {\n \"correctness\": \"warn\"\n },\n \"rules\": {\n \"eslint/no-unused-vars\": \"error\"\n }\n}\n```", + "description": "Configure an entire category of rules all at once.\n\nRules enabled or disabled this way will be overwritten by individual rules in the `rules` field.\n\n# Example\n```json\n{\n \"$schema\": \"./node_modules/oxlint/configuration_schema.json\",\n \"categories\": {\n \"correctness\": \"warn\"\n },\n \"rules\": {\n \"eslint/no-unused-vars\": \"error\"\n }\n}\n```", "examples": [ { "correctness": "warn" @@ -312,7 +312,7 @@ } }, "OxlintGlobals": { - "description": "Add or remove global variables.\n\nFor each global variable, set the corresponding value equal to `\"writable\"` to allow the variable to be overwritten or `\"readonly\"` to disallow overwriting.\n\nGlobals can be disabled by setting their value to `\"off\"`. For example, in an environment where most Es2015 globals are available but `Promise` is unavailable, you might use this config:\n\n```json\n\n{ \"env\": { \"es6\": true }, \"globals\": { \"Promise\": \"off\" } }\n\n```\n\nYou may also use `\"readable\"` or `false` to represent `\"readonly\"`, and `\"writeable\"` or `true` to represent `\"writable\"`.", + "description": "Add or remove global variables.\n\nFor each global variable, set the corresponding value equal to `\"writable\"` to allow the variable to be overwritten or `\"readonly\"` to disallow overwriting.\n\nGlobals can be disabled by setting their value to `\"off\"`. For example, in an environment where most Es2015 globals are available but `Promise` is unavailable, you might use this config:\n\n```json\n\n{ \"$schema\": \"./node_modules/oxlint/configuration_schema.json\", \"env\": { \"es6\": true }, \"globals\": { \"Promise\": \"off\" } }\n\n```\n\nYou may also use `\"readable\"` or `false` to represent `\"readonly\"`, and `\"writeable\"` or `true` to represent `\"writable\"`.", "type": "object", "additionalProperties": { "$ref": "#/definitions/GlobalValue" diff --git a/tasks/website/src/linter/snapshots/schema_markdown.snap b/tasks/website/src/linter/snapshots/schema_markdown.snap index 6eac93ddbd046..9dba7f7d28260 100644 --- a/tasks/website/src/linter/snapshots/schema_markdown.snap +++ b/tasks/website/src/linter/snapshots/schema_markdown.snap @@ -20,6 +20,11 @@ Example ```json { + "$schema": "./node_modules/oxlint/configuration_schema.json", + "plugins": [ + "import", + "unicorn" + ], "env": { "browser": true }, @@ -47,6 +52,7 @@ Rules enabled or disabled this way will be overwritten by individual rules in th # Example ```json { + "$schema": "./node_modules/oxlint/configuration_schema.json", "categories": { "correctness": "warn" }, @@ -129,6 +135,7 @@ Globals can be disabled by setting their value to `"off"`. For example, in an en ```json { + "$schema": "./node_modules/oxlint/configuration_schema.json", "env": { "es6": true },