Skip to content

Commit df143ca

Browse files
committed
docs(linter): add docs for config settings (#4827)
1 parent 849489e commit df143ca

7 files changed

Lines changed: 195 additions & 7 deletions

File tree

crates/oxc_linter/src/config/settings/jsx_a11y.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,46 @@ use rustc_hash::FxHashMap;
33
use schemars::JsonSchema;
44
use serde::{Deserialize, Serialize};
55

6-
// <https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations>
6+
/// Configure JSX A11y plugin rules.
7+
///
8+
/// See
9+
/// [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s
10+
/// configuration for a full reference.
711
#[derive(Debug, Clone, Deserialize, Default, Serialize, JsonSchema)]
812
#[cfg_attr(test, derive(PartialEq))]
913
pub struct JSXA11yPluginSettings {
14+
/// An optional setting that define the prop your code uses to create polymorphic components.
15+
/// This setting will be used to determine the element type in rules that
16+
/// require semantic context.
17+
///
18+
/// For example, if you set the `polymorphicPropName` to `as`, then this element:
19+
///
20+
/// ```jsx
21+
/// <Box as="h3">Hello</Box>
22+
/// ```
23+
///
24+
/// Will be treated as an `h3`. If not set, this component will be treated
25+
/// as a `Box`.
1026
#[serde(rename = "polymorphicPropName")]
1127
pub polymorphic_prop_name: Option<CompactStr>,
28+
29+
/// To have your custom components be checked as DOM elements, you can
30+
/// provide a mapping of your component names to the DOM element name.
31+
///
32+
/// ## Example
33+
///
34+
/// ```json
35+
/// {
36+
/// "settings": {
37+
/// "jsx-a11y": {
38+
/// "components": {
39+
/// "Link": "a",
40+
/// "IconButton": "button"
41+
/// }
42+
/// }
43+
/// }
44+
/// }
45+
/// ```
1246
#[serde(default)]
1347
pub components: FxHashMap<CompactStr, CompactStr>,
1448
}

crates/oxc_linter/src/config/settings/mod.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ use self::{
1111
react::ReactPluginSettings,
1212
};
1313

14-
/// Shared settings for plugins
14+
/// # Oxlint Plugin Settings
15+
///
16+
/// Configure the behavior of linter plugins.
17+
///
18+
/// ## Example
19+
///
20+
/// Here's an example if you're using Next.js in a monorepo:
21+
///
22+
/// ```json
23+
/// {
24+
/// "settings": {
25+
/// "next": {
26+
/// "rootDir": "apps/dashboard/"
27+
/// },
28+
/// "react": {
29+
/// "linkComponents": [
30+
/// { "name": "Link", "linkAttribute": "to" }
31+
/// ]
32+
/// },
33+
/// "jsx-a11y": {
34+
/// "components": {
35+
/// "Link": "a",
36+
/// "Button": "button"
37+
/// }
38+
/// }
39+
/// }
40+
/// }
41+
/// ```
1542
#[derive(Debug, Clone, Deserialize, Serialize, Default, JsonSchema)]
1643
#[cfg_attr(test, derive(PartialEq))]
1744
pub struct OxlintSettings {

crates/oxc_linter/src/config/settings/next.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,26 @@ use std::borrow::Cow;
33
use schemars::JsonSchema;
44
use serde::{Deserialize, Serialize, Serializer};
55

6+
/// Configure Next.js plugin rules.
67
#[derive(Debug, Clone, Deserialize, Default, Serialize, JsonSchema)]
78
#[cfg_attr(test, derive(PartialEq))]
89
pub struct NextPluginSettings {
10+
/// The root directory of the Next.js project.
11+
///
12+
/// This is particularly useful when you have a monorepo and your Next.js
13+
/// project is in a subfolder.
14+
///
15+
/// ## Example
16+
///
17+
/// ```json
18+
/// {
19+
/// "settings": {
20+
/// "next": {
21+
/// "rootDir": "apps/dashboard/"
22+
/// }
23+
/// }
24+
/// }
25+
/// ```
926
#[serde(default)]
1027
#[serde(rename = "rootDir")]
1128
root_dir: OneOrMany<String>,

crates/oxc_linter/src/config/settings/react.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,55 @@ use oxc_span::CompactStr;
44
use schemars::JsonSchema;
55
use serde::{Deserialize, Serialize};
66

7-
// <https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc->
7+
/// Configure React plugin rules.
8+
///
9+
/// Derived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)
810
#[derive(Debug, Clone, Deserialize, Default, Serialize, JsonSchema)]
911
#[cfg_attr(test, derive(PartialEq))]
1012
pub struct ReactPluginSettings {
13+
/// Components used as alternatives to `<form>` for forms, such as `<Formik>`.
14+
///
15+
/// ## Example
16+
///
17+
/// ```jsonc
18+
/// {
19+
/// "settings": {
20+
/// "react": {
21+
/// "formComponents": [
22+
/// "CustomForm",
23+
/// // OtherForm is considered a form component and has an endpoint attribute
24+
/// { "name": "OtherForm", "formAttribute": "endpoint" },
25+
/// // allows specifying multiple properties if necessary
26+
/// { "name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"] }
27+
/// ]
28+
/// }
29+
/// }
30+
/// }
31+
/// ```
1132
#[serde(default)]
1233
#[serde(rename = "formComponents")]
1334
form_components: Vec<CustomComponent>,
1435

36+
/// Components used as alternatives to `<a>` for linking, such as `<Link>`.
37+
///
38+
/// ## Example
39+
///
40+
/// ```jsonc
41+
/// {
42+
/// "settings": {
43+
/// "react": {
44+
/// "linkComponents": [
45+
/// "HyperLink",
46+
/// // Use `linkAttribute` for components that use a different prop name
47+
/// // than `href`.
48+
/// { "name": "MyLink", "linkAttribute": "to" },
49+
/// // allows specifying multiple properties if necessary
50+
/// { "name": "Link", "linkAttribute": ["to", "href"] }
51+
/// ]
52+
/// }
53+
/// }
54+
/// }
55+
/// ```
1556
#[serde(default)]
1657
#[serde(rename = "linkComponents")]
1758
link_components: Vec<CustomComponent>,

crates/oxc_linter/src/snapshots/schema_json.snap

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,16 +241,19 @@ snapshot_kind: text
241241
}
242242
},
243243
"JSXA11yPluginSettings": {
244+
"description": "Configure JSX A11y plugin rules.\n\nSee [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s configuration for a full reference.",
244245
"type": "object",
245246
"properties": {
246247
"components": {
248+
"description": "To have your custom components be checked as DOM elements, you can provide a mapping of your component names to the DOM element name.\n\n## Example\n\n```json { \"settings\": { \"jsx-a11y\": { \"components\": { \"Link\": \"a\", \"IconButton\": \"button\" } } } } ```",
247249
"default": {},
248250
"type": "object",
249251
"additionalProperties": {
250252
"type": "string"
251253
}
252254
},
253255
"polymorphicPropName": {
256+
"description": "An optional setting that define the prop your code uses to create polymorphic components. This setting will be used to determine the element type in rules that require semantic context.\n\nFor example, if you set the `polymorphicPropName` to `as`, then this element:\n\n```jsx <Box as=\"h3\">Hello</Box> ```\n\nWill be treated as an `h3`. If not set, this component will be treated as a `Box`.",
254257
"type": [
255258
"string",
256259
"null"
@@ -265,9 +268,11 @@ snapshot_kind: text
265268
}
266269
},
267270
"NextPluginSettings": {
271+
"description": "Configure Next.js plugin rules.",
268272
"type": "object",
269273
"properties": {
270274
"rootDir": {
275+
"description": "The root directory of the Next.js project.\n\nThis is particularly useful when you have a monorepo and your Next.js project is in a subfolder.\n\n## Example\n\n```json { \"settings\": { \"next\": { \"rootDir\": \"apps/dashboard/\" } } } ```",
271276
"default": [],
272277
"allOf": [
273278
{
@@ -383,7 +388,8 @@ snapshot_kind: text
383388
"$ref": "#/definitions/DummyRuleMap"
384389
},
385390
"OxlintSettings": {
386-
"description": "Shared settings for plugins",
391+
"title": "Oxlint Plugin Settings",
392+
"description": "Configure the behavior of linter plugins.\n\n## Example\n\nHere's an example if you're using Next.js in a monorepo:\n\n```json { \"settings\": { \"next\": { \"rootDir\": \"apps/dashboard/\" }, \"react\": { \"linkComponents\": [ { \"name\": \"Link\", \"linkAttribute\": \"to\" } ] }, \"jsx-a11y\": { \"components\": { \"Link\": \"a\", \"Button\": \"button\" } } } } ```",
387393
"type": "object",
388394
"properties": {
389395
"jsdoc": {
@@ -438,16 +444,19 @@ snapshot_kind: text
438444
}
439445
},
440446
"ReactPluginSettings": {
447+
"description": "Configure React plugin rules.\n\nDerived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)",
441448
"type": "object",
442449
"properties": {
443450
"formComponents": {
451+
"description": "Components used as alternatives to `<form>` for forms, such as `<Formik>`.\n\n## Example\n\n```jsonc { \"settings\": { \"react\": { \"formComponents\": [ \"CustomForm\", // OtherForm is considered a form component and has an endpoint attribute { \"name\": \"OtherForm\", \"formAttribute\": \"endpoint\" }, // allows specifying multiple properties if necessary { \"name\": \"Form\", \"formAttribute\": [\"registerEndpoint\", \"loginEndpoint\"] } ] } } } ```",
444452
"default": [],
445453
"type": "array",
446454
"items": {
447455
"$ref": "#/definitions/CustomComponent"
448456
}
449457
},
450458
"linkComponents": {
459+
"description": "Components used as alternatives to `<a>` for linking, such as `<Link>`.\n\n## Example\n\n```jsonc { \"settings\": { \"react\": { \"linkComponents\": [ \"HyperLink\", // Use `linkAttribute` for components that use a different prop name // than `href`. { \"name\": \"MyLink\", \"linkAttribute\": \"to\" }, // allows specifying multiple properties if necessary { \"name\": \"Link\", \"linkAttribute\": [\"to\", \"href\"] } ] } } } ```",
451460
"default": [],
452461
"type": "array",
453462
"items": {

npm/oxlint/configuration_schema.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,19 @@
236236
}
237237
},
238238
"JSXA11yPluginSettings": {
239+
"description": "Configure JSX A11y plugin rules.\n\nSee [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s configuration for a full reference.",
239240
"type": "object",
240241
"properties": {
241242
"components": {
243+
"description": "To have your custom components be checked as DOM elements, you can provide a mapping of your component names to the DOM element name.\n\n## Example\n\n```json { \"settings\": { \"jsx-a11y\": { \"components\": { \"Link\": \"a\", \"IconButton\": \"button\" } } } } ```",
242244
"default": {},
243245
"type": "object",
244246
"additionalProperties": {
245247
"type": "string"
246248
}
247249
},
248250
"polymorphicPropName": {
251+
"description": "An optional setting that define the prop your code uses to create polymorphic components. This setting will be used to determine the element type in rules that require semantic context.\n\nFor example, if you set the `polymorphicPropName` to `as`, then this element:\n\n```jsx <Box as=\"h3\">Hello</Box> ```\n\nWill be treated as an `h3`. If not set, this component will be treated as a `Box`.",
249252
"type": [
250253
"string",
251254
"null"
@@ -260,9 +263,11 @@
260263
}
261264
},
262265
"NextPluginSettings": {
266+
"description": "Configure Next.js plugin rules.",
263267
"type": "object",
264268
"properties": {
265269
"rootDir": {
270+
"description": "The root directory of the Next.js project.\n\nThis is particularly useful when you have a monorepo and your Next.js project is in a subfolder.\n\n## Example\n\n```json { \"settings\": { \"next\": { \"rootDir\": \"apps/dashboard/\" } } } ```",
266271
"default": [],
267272
"allOf": [
268273
{
@@ -378,7 +383,8 @@
378383
"$ref": "#/definitions/DummyRuleMap"
379384
},
380385
"OxlintSettings": {
381-
"description": "Shared settings for plugins",
386+
"title": "Oxlint Plugin Settings",
387+
"description": "Configure the behavior of linter plugins.\n\n## Example\n\nHere's an example if you're using Next.js in a monorepo:\n\n```json { \"settings\": { \"next\": { \"rootDir\": \"apps/dashboard/\" }, \"react\": { \"linkComponents\": [ { \"name\": \"Link\", \"linkAttribute\": \"to\" } ] }, \"jsx-a11y\": { \"components\": { \"Link\": \"a\", \"Button\": \"button\" } } } } ```",
382388
"type": "object",
383389
"properties": {
384390
"jsdoc": {
@@ -433,16 +439,19 @@
433439
}
434440
},
435441
"ReactPluginSettings": {
442+
"description": "Configure React plugin rules.\n\nDerived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)",
436443
"type": "object",
437444
"properties": {
438445
"formComponents": {
446+
"description": "Components used as alternatives to `<form>` for forms, such as `<Formik>`.\n\n## Example\n\n```jsonc { \"settings\": { \"react\": { \"formComponents\": [ \"CustomForm\", // OtherForm is considered a form component and has an endpoint attribute { \"name\": \"OtherForm\", \"formAttribute\": \"endpoint\" }, // allows specifying multiple properties if necessary { \"name\": \"Form\", \"formAttribute\": [\"registerEndpoint\", \"loginEndpoint\"] } ] } } } ```",
439447
"default": [],
440448
"type": "array",
441449
"items": {
442450
"$ref": "#/definitions/CustomComponent"
443451
}
444452
},
445453
"linkComponents": {
454+
"description": "Components used as alternatives to `<a>` for linking, such as `<Link>`.\n\n## Example\n\n```jsonc { \"settings\": { \"react\": { \"linkComponents\": [ \"HyperLink\", // Use `linkAttribute` for components that use a different prop name // than `href`. { \"name\": \"MyLink\", \"linkAttribute\": \"to\" }, // allows specifying multiple properties if necessary { \"name\": \"Link\", \"linkAttribute\": [\"to\", \"href\"] } ] } } } ```",
446455
"default": [],
447456
"type": "array",
448457
"items": {

0 commit comments

Comments
 (0)