Skip to main content

oxlint_config/
plugins.rs

1use super::*;
2
3/// The plugins for oxlint. See more: https://oxc.rs/docs/guide/usage/linter/plugins.html
4#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq)]
5#[cfg_attr(feature = "schemars", derive(JsonSchema))]
6#[serde(rename_all = "lowercase")]
7pub enum Plugins {
8	Eslint,
9	Import,
10	Jest,
11	Jsdoc,
12	#[serde(rename = "jsx-a11y")]
13	JsxA11y,
14	NextJs,
15	Node,
16	Oxc,
17	Promise,
18	React,
19	#[serde(rename = "react-perf")]
20	ReactPerf,
21	Regex,
22	Typescript,
23	Unicorn,
24	Vitest,
25	Vue,
26}
27
28impl Plugins {
29	pub const fn as_str(&self) -> &str {
30		match self {
31			Self::Eslint => "eslint",
32			Self::Import => "import",
33			Self::Jest => "jest",
34			Self::Jsdoc => "jsdoc",
35			Self::JsxA11y => "jsx-a11y",
36			Self::NextJs => "nextjs",
37			Self::Node => "node",
38			Self::Oxc => "oxc",
39			Self::Promise => "promise",
40			Self::React => "react",
41			Self::ReactPerf => "react-perf",
42			Self::Regex => "regex",
43			Self::Typescript => "typescript",
44			Self::Unicorn => "unicorn",
45			Self::Vitest => "vitest",
46			Self::Vue => "vue",
47		}
48	}
49}
50
51impl Plugin {
52	pub const fn as_str(&self) -> &str {
53		match self {
54			Self::Known(variant) => variant.as_str(),
55			Self::Custom(name) => name.as_str(),
56		}
57	}
58}
59
60impl PartialOrd for Plugin {
61	fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
62		Some(self.cmp(other))
63	}
64}
65
66impl Ord for Plugin {
67	fn cmp(&self, other: &Self) -> std::cmp::Ordering {
68		self.as_str().cmp(other.as_str())
69	}
70}
71
72/// Ways of referring to a plugin.
73#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
74#[cfg_attr(feature = "schemars", derive(JsonSchema))]
75#[serde(untagged)]
76pub enum Plugin {
77	Known(Plugins),
78	Custom(String),
79}
80
81/// Specifies allows custom tags for Jsdoc annotations.
82#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
83#[cfg_attr(feature = "schemars", derive(JsonSchema))]
84#[serde(untagged, rename_all = "camelCase")]
85pub enum TagNamePreference {
86	String(String),
87	Data {
88		message: String,
89		replacement: String,
90	},
91	Message {
92		message: String,
93	},
94	Bool(bool),
95}
96
97/// Settings for the Jsdoc plugin. See more: https://oxc.rs/docs/guide/usage/linter/config-file-reference.html#settings-jsdoc
98#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
99#[cfg_attr(feature = "schemars", derive(JsonSchema))]
100#[serde(rename_all = "camelCase")]
101#[serde(default)]
102#[serde(deny_unknown_fields)]
103pub struct JsDocPluginSettings {
104	/// Only for `require-(yields|returns|description|example|param|throws)` rules.
105	#[serde(skip_serializing_if = "Option::is_none")]
106	pub augments_extends_replaces_docs: Option<bool>,
107
108	/// Only for `require-param-type` and `require-param-description` rule.
109	#[serde(skip_serializing_if = "Option::is_none")]
110	pub exempt_destructured_roots_from_chekcs: Option<bool>,
111
112	/// For all rules but NOT apply to `empty-tags` rule.
113	#[serde(skip_serializing_if = "Option::is_none")]
114	pub ignore_internal: Option<bool>,
115
116	/// For all rules but NOT apply to `check-access` and `empty-tags` rule.
117	#[serde(skip_serializing_if = "Option::is_none")]
118	pub ignore_private: Option<bool>,
119
120	/// Only for `require-(yields|returns|description|example|param|throws)` rules.
121	#[serde(skip_serializing_if = "Option::is_none")]
122	pub ignore_replaces_docs: Option<bool>,
123
124	/// Only for `require-(yields|returns|description|example|param|throws)` rules.
125	#[serde(skip_serializing_if = "Option::is_none")]
126	pub implements_replaces_docs: Option<bool>,
127
128	/// Only for `require-(yields|returns|description|example|param|throws)` rules.
129	#[serde(skip_serializing_if = "Option::is_none")]
130	pub override_replaces_docs: Option<bool>,
131
132	/// Specifies allows custom tags for Jsdoc annotations.
133	#[serde(skip_serializing_if = "Option::is_none")]
134	pub tag_name_preference: Option<BTreeMap<String, TagNamePreference>>,
135}
136
137/// Settings for the jsx-a11y plugin. See more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y#configurations
138#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
139#[cfg_attr(feature = "schemars", derive(JsonSchema))]
140#[serde(rename_all = "camelCase")]
141#[serde(default)]
142#[serde(deny_unknown_fields)]
143pub struct JsxA11yPluginSettings {
144	/// Map of attribute names to their DOM equivalents.This is useful for non-React frameworks that use different attribute names.
145	///
146	/// Example:
147	/// ```json
148	/// {
149	///   "settings\":
150	///   {
151	///     "jsx-a11y":
152	///     {
153	///       "attributes": {
154	///         "for": [
155	///           "htmlFor",
156	///           "for"
157	///         ]
158	///       }
159	///     }
160	///   }
161	/// }
162	/// ```
163	#[serde(skip_serializing_if = "Option::is_none")]
164	pub attributes: Option<BTreeMap<String, BTreeSet<String>>>,
165
166	/// To have your custom components be checked as DOM elements, you can\nprovide a mapping of your component names to the DOM element name.
167	///
168	/// Example:
169	/// ```json
170	/// {
171	///   "settings": {
172	///     "jsx-a11y": {
173	///       "components": {
174	///         "Link": "a",
175	///         "IconButton": "button"
176	///       }
177	///     }
178	///   }
179	/// }
180	/// ```
181	#[serde(skip_serializing_if = "Option::is_none")]
182	pub components: Option<BTreeMap<String, String>>,
183
184	/// An optional setting that define the prop your code uses to create polymorphic components.
185	/// This setting will be used to determine the element type in rules that
186	/// require semantic context.
187	///
188	/// For example, if you set the `polymorphicPropName` to `as`, then this element:
189	///
190	/// ```jsx
191	/// <Box as="h3">Hello</Box>
192	/// ```
193	///
194	/// Will be treated as an `h3`. If not set, this component will be treated
195	/// as a `Box`.
196	#[serde(skip_serializing_if = "Option::is_none")]
197	pub polymorphic_prop_name: Option<String>,
198}
199
200/// Settings for the nextjs plugin. See more: https://oxc.rs/docs/guide/usage/linter/config-file-reference.html#settings-next
201#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
202#[cfg_attr(feature = "schemars", derive(JsonSchema))]
203#[serde(rename_all = "camelCase")]
204#[serde(deny_unknown_fields)]
205pub struct NextPluginSettings {
206	/// The root directory of the Next.js project.
207	///
208	/// This is particularly useful when you have a monorepo and your Next.js
209	/// project is in a subfolder.
210	///
211	/// Example:
212	///
213	/// ```json
214	/// {
215	///   "settings": {
216	///     "next": {
217	///       "rootDir": "apps/dashboard/"
218	///     }
219	///   }
220	/// }
221	/// ```
222	#[serde(skip_serializing_if = "Option::is_none")]
223	pub root_dir: Option<OneOrManyStrings>,
224}
225
226#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
227#[cfg_attr(feature = "schemars", derive(JsonSchema))]
228#[serde(untagged)]
229pub enum OneOrManyStrings {
230	One(String),
231	Many(BTreeSet<String>),
232}
233
234/// Settings for the react plugin. See more: https://oxc.rs/docs/guide/usage/linter/config-file-reference.html#settings-react
235#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
236#[cfg_attr(feature = "schemars", derive(JsonSchema))]
237#[serde(rename_all = "camelCase")]
238#[serde(deny_unknown_fields)]
239#[serde(default)]
240pub struct ReactPluginSettings {
241	/// Components used as alternatives to `<form>` for forms, such as `<Formik>`.
242	///
243	/// Example:
244	///
245	/// ```jsonc
246	/// {
247	///   "settings": {
248	///     "react": {
249	///       "formComponents": [
250	///         "CustomForm",
251	///         // OtherForm is considered a form component and has an endpoint attribute
252	///         { "name": "OtherForm", "formAttribute": "endpoint" },
253	///         // allows specifying multiple properties if necessary
254	///         { "name": "Form", "formAttribute": ["registerEndpoint", "loginEndpoint"] }
255	///       ]
256	///     }
257	///   }
258	/// }
259	/// ```
260	#[serde(skip_serializing_if = "Option::is_none")]
261	pub form_components: Option<Vec<CustomComponent>>,
262
263	/// Components used as alternatives to `<a>` for linking, such as `<Link>`.
264	///
265	/// Example:
266	///
267	/// ```jsonc
268	/// {
269	///   "settings": {
270	///     "react": {
271	///       "linkComponents": [
272	///         "HyperLink",
273	///         // Use `linkAttribute` for components that use a different prop name
274	///         // than `href`.
275	///         { "name": "MyLink", "linkAttribute": "to" },
276	///         // allows specifying multiple properties if necessary
277	///         { "name": "Link", "linkAttribute": ["to", "href"] }
278	///       ]
279	///     }
280	///   }
281	/// }
282	/// ```
283	#[serde(skip_serializing_if = "Option::is_none")]
284	pub link_components: Option<Vec<CustomComponent>>,
285}
286
287#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
288#[cfg_attr(feature = "schemars", derive(JsonSchema))]
289#[serde(untagged)]
290pub enum CustomComponent {
291	NameOnly(String),
292	ObjectWithOneAttr {
293		name: String,
294		#[serde(alias = "formAttribute", alias = "linkAttribute")]
295		attribute: String,
296	},
297	ObjectWithManyAttrs {
298		name: String,
299		#[serde(alias = "formAttribute", alias = "linkAttribute")]
300		attributes: BTreeSet<String>,
301	},
302}