Skip to content

Commit df143ca

Browse files
committedNov 21, 2024·
docs(linter): add docs for config settings (#4827)
1 parent 849489e commit df143ca

File tree

7 files changed

+195
-7
lines changed

7 files changed

+195
-7
lines changed
 

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

+35-1
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

+28-1
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

+17
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

+42-1
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

+10-1
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

+10-1
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": {

‎tasks/website/src/linter/snapshots/schema_markdown.snap

+53-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
source: tasks/website/src/linter/json_schema.rs
33
expression: snapshot
4+
snapshot_kind: text
45
---
56
# Oxlint Configuration File
67

@@ -214,7 +215,35 @@ See [Oxlint Rules](https://oxc.rs/docs/guide/usage/linter/rules.html)
214215
type: `object`
215216

216217

217-
Shared settings for plugins
218+
Configure the behavior of linter plugins.
219+
220+
## Example
221+
222+
Here's an example if you're using Next.js in a monorepo:
223+
224+
```json
225+
{
226+
"settings": {
227+
"next": {
228+
"rootDir": "apps/dashboard/"
229+
},
230+
"react": {
231+
"linkComponents": [
232+
{
233+
"name": "Link",
234+
"linkAttribute": "to"
235+
}
236+
]
237+
},
238+
"jsx-a11y": {
239+
"components": {
240+
"Link": "a",
241+
"Button": "button"
242+
}
243+
}
244+
}
245+
}
246+
```
218247

219248

220249
### settings.jsdoc
@@ -302,7 +331,9 @@ default: `{}`
302331
type: `object`
303332

304333

334+
Configure JSX A11y plugin rules.
305335

336+
See [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s configuration for a full reference.
306337

307338

308339
#### settings.jsx-a11y.components
@@ -311,7 +342,11 @@ type: `Record<string, string>`
311342

312343
default: `{}`
313344

345+
To have your custom components be checked as DOM elements, you can provide a mapping of your component names to the DOM element name.
314346

347+
## Example
348+
349+
```json { "settings": { "jsx-a11y": { "components": { "Link": "a", "IconButton": "button" } } } } ```
315350

316351

317352
#### settings.jsx-a11y.polymorphicPropName
@@ -322,15 +357,21 @@ type: `[
322357
]`
323358

324359

360+
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.
361+
362+
For example, if you set the `polymorphicPropName` to `as`, then this element:
325363

364+
```jsx <Box as="h3">Hello</Box> ```
365+
366+
Will be treated as an `h3`. If not set, this component will be treated as a `Box`.
326367

327368

328369
### settings.next
329370

330371
type: `object`
331372

332373

333-
374+
Configure Next.js plugin rules.
334375

335376

336377
#### settings.next.rootDir
@@ -345,7 +386,9 @@ type: `object`
345386
type: `object`
346387

347388

389+
Configure React plugin rules.
348390

391+
Derived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)
349392

350393

351394
#### settings.react.formComponents
@@ -354,7 +397,11 @@ type: `array`
354397

355398
default: `[]`
356399

400+
Components used as alternatives to `<form>` for forms, such as `<Formik>`.
357401

402+
## Example
403+
404+
```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"] } ] } } } ```
358405
359406
360407
##### settings.react.formComponents[n]
@@ -370,7 +417,11 @@ type: `array`
370417
371418
default: `[]`
372419
420+
Components used as alternatives to `<a>` for linking, such as `<Link>`.
421+
422+
## Example
373423
424+
```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"] } ] } } } ```
374425
375426
376427
##### settings.react.linkComponents[n]

0 commit comments

Comments
 (0)
Please sign in to comment.