Skip to content

Commit

Permalink
docs(linter): add docs for config settings
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Aug 11, 2024
1 parent 9a2736b commit c05c6b5
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 9 deletions.
36 changes: 35 additions & 1 deletion crates/oxc_linter/src/config/settings/jsx_a11y.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,45 @@ use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::Deserialize;

// <https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations>
/// Configure JSX A11y plugin rules.
///
/// See
/// [eslint-plugin-jsx-a11y](https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations)'s
/// configuration for a full reference.
#[derive(Debug, Deserialize, Default, JsonSchema)]
pub struct JSXA11yPluginSettings {
/// 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.
///
/// For example, if you set the `polymorphicPropName` to `as`, then this element:
///
/// ```jsx
/// <Box as="h3">Hello</Box>
/// ```
///
/// Will be treated as an `h3`. If not set, this component will be treated
/// as a `Box`.
#[serde(rename = "polymorphicPropName")]
pub polymorphic_prop_name: Option<CompactStr>,

/// To have your custom components be checked as DOM elements, you can
/// provide a mapping of your component names to the DOM element name.
///
/// ## Example
///
/// ```json
/// {
/// "settings": {
/// "jsx-a11y": {
/// "components": {
/// "Link": "a",
/// "IconButton": "button"
/// }
/// }
/// }
/// }
/// ```
#[serde(default)]
pub components: FxHashMap<CompactStr, CompactStr>,
}
30 changes: 29 additions & 1 deletion crates/oxc_linter/src/config/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,35 @@ use self::{
react::ReactPluginSettings,
};

/// Shared settings for plugins
/// # Oxlint Plugin Settings
///
/// Configure the behavior of linter plugins.
///
/// ## Example
///
/// Here's an example if you're using Next.js in a monorepo:
///
/// ```jsonc
/// {
/// "settings": {
/// "next": {
/// "rootDir": "apps/dashboard/"
/// },
/// "react": {
/// "linkComponents": [
/// // support next/link
/// { "name": "Link", "linkAttribute": "to" }
/// ]
/// },
/// "jsx-a11y": {
/// "components": {
/// "Link": "a",
/// "Button": "button"
/// }
/// }
/// }
/// }
/// ```
#[derive(Debug, Deserialize, Default, JsonSchema)]
pub struct OxlintSettings {
#[serde(default)]
Expand Down
17 changes: 17 additions & 0 deletions crates/oxc_linter/src/config/settings/next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ use std::borrow::Cow;
use schemars::JsonSchema;
use serde::Deserialize;

/// Configure Next.js plugin rules.
#[derive(Debug, Deserialize, Default, JsonSchema)]
pub struct NextPluginSettings {
/// The root directory of the Next.js project.
///
/// This is particularly useful when you have a monorepo and your Next.js
/// project is in a subfolder.
///
/// ## Example
///
/// ```json
/// {
/// "settings": {
/// "next": {
/// "rootDir": "apps/dashboard/"
/// }
/// }
/// }
/// ```
#[serde(default)]
#[serde(rename = "rootDir")]
root_dir: OneOrMany<String>,
Expand Down
43 changes: 42 additions & 1 deletion crates/oxc_linter/src/config/settings/react.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,54 @@ use oxc_span::CompactStr;
use schemars::JsonSchema;
use serde::Deserialize;

// <https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc->
/// Configure React plugin rules.
///
/// Derived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)
#[derive(Debug, Deserialize, Default, JsonSchema)]
pub struct ReactPluginSettings {
/// Components used as alternatives to `<form>` for forms, such as `<Formik>`.
///
/// ## Example
///
/// ```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"] }
/// ]
/// }
/// }
/// }
/// ```
#[serde(default)]
#[serde(rename = "formComponents")]
form_components: Vec<CustomComponent>,

/// Components used as alternatives to `<a>` for linking, such as `<Link>`.
///
/// ## Example
///
/// ```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"] }
/// ]
/// }
/// }
/// }
/// ```
#[serde(default)]
#[serde(rename = "linkComponents")]
link_components: Vec<CustomComponent>,
Expand Down
17 changes: 15 additions & 2 deletions crates/oxc_linter/src/snapshots/schema_json.snap
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,19 @@ expression: json
}
},
"JSXA11yPluginSettings": {
"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.",
"type": "object",
"properties": {
"components": {
"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\" } } } } ```",
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"polymorphicPropName": {
"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`.",
"type": [
"string",
"null"
Expand All @@ -173,10 +176,16 @@ expression: json
}
},
"NextPluginSettings": {
"description": "Configure Next.js plugin rules.",
"type": "object",
"properties": {
"rootDir": {
"$ref": "#/definitions/OneOrMany_for_String"
"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/\" } } } ```",
"allOf": [
{
"$ref": "#/definitions/OneOrMany_for_String"
}
]
}
}
},
Expand Down Expand Up @@ -214,7 +223,8 @@ expression: json
}
},
"OxlintSettings": {
"description": "Shared settings for plugins",
"title": "Oxlint Plugin Settings",
"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```jsonc { \"settings\": { \"next\": { \"rootDir\": \"apps/dashboard/\" }, \"react\": { \"linkComponents\": [ // support next/link { \"name\": \"Link\", \"linkAttribute\": \"to\" } ] }, \"jsx-a11y\": { \"components\": { \"Link\": \"a\", \"Button\": \"button\" } } } } ```",
"type": "object",
"properties": {
"jsdoc": {
Expand All @@ -232,15 +242,18 @@ expression: json
}
},
"ReactPluginSettings": {
"description": "Configure React plugin rules.\n\nDerived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)",
"type": "object",
"properties": {
"formComponents": {
"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\"] } ] } } } ```",
"type": "array",
"items": {
"$ref": "#/definitions/CustomComponent"
}
},
"linkComponents": {
"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\"] } ] } } } ```",
"type": "array",
"items": {
"$ref": "#/definitions/CustomComponent"
Expand Down
17 changes: 15 additions & 2 deletions npm/oxlint/configuration_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@
}
},
"JSXA11yPluginSettings": {
"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.",
"type": "object",
"properties": {
"components": {
"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\" } } } } ```",
"default": {},
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"polymorphicPropName": {
"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`.",
"type": [
"string",
"null"
Expand All @@ -169,10 +172,16 @@
}
},
"NextPluginSettings": {
"description": "Configure Next.js plugin rules.",
"type": "object",
"properties": {
"rootDir": {
"$ref": "#/definitions/OneOrMany_for_String"
"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/\" } } } ```",
"allOf": [
{
"$ref": "#/definitions/OneOrMany_for_String"
}
]
}
}
},
Expand Down Expand Up @@ -210,7 +219,8 @@
}
},
"OxlintSettings": {
"description": "Shared settings for plugins",
"title": "Oxlint Plugin Settings",
"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```jsonc { \"settings\": { \"next\": { \"rootDir\": \"apps/dashboard/\" }, \"react\": { \"linkComponents\": [ // support next/link { \"name\": \"Link\", \"linkAttribute\": \"to\" } ] }, \"jsx-a11y\": { \"components\": { \"Link\": \"a\", \"Button\": \"button\" } } } } ```",
"type": "object",
"properties": {
"jsdoc": {
Expand All @@ -228,15 +238,18 @@
}
},
"ReactPluginSettings": {
"description": "Configure React plugin rules.\n\nDerived from [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react#configuration-legacy-eslintrc-)",
"type": "object",
"properties": {
"formComponents": {
"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\"] } ] } } } ```",
"type": "array",
"items": {
"$ref": "#/definitions/CustomComponent"
}
},
"linkComponents": {
"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\"] } ] } } } ```",
"type": "array",
"items": {
"$ref": "#/definitions/CustomComponent"
Expand Down
Loading

0 comments on commit c05c6b5

Please sign in to comment.