feat(linter): add schema for jsx_a11y/alt-text (#23369)

upstream docs: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/alt-text.md
This commit is contained in:
Sysix committed 2026-06-13 15:08:23 +00:00
1 parent c966384e77
commit e3fd735e59
5 files changed
+201 -7

No files matched your search

+24 -1
View File
@@ -92,6 +92,7 @@ export type Target = "single" | "any";
export type TestCaseName = "it" | "test";
export type JestFnType = "hook" | "describe" | "test" | "expect" | "jest" | "unknown";
export type SnapshotHintMode = "always" | "multi";
export type AltTextElements = "img" | "object" | "area" | 'input[type="image"]';
export type CountThis = "always" | "never" | "except-void";
export type NoCondAssignConfig = "except-parens" | "always";
export type CheckLoopsConfig = boolean | CheckLoops;
@@ -916,7 +917,7 @@ export interface DummyRuleMap {
"jsdoc/require-yields"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, RequireYieldsConfig];
"jsdoc/require-yields-description"?: RuleNoConfig;
"jsdoc/require-yields-type"?: RuleNoConfig;
"jsx-a11y/alt-text"?: DummyRule;
"jsx-a11y/alt-text"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, AltTextConfigSchema];
"jsx-a11y/anchor-ambiguous-text"?: AllowWarnDeny | [AllowWarnDeny] | [AllowWarnDeny, AnchorAmbiguousTextConfig];
"jsx-a11y/anchor-has-content"?: RuleNoConfig;
"jsx-a11y/anchor-is-valid"?: DummyRule;
@@ -2431,6 +2432,28 @@ export interface RequireYieldsConfig {
*/
withGeneratorTag?: boolean;
}
export interface AltTextConfigSchema {
/**
* Custom components to check for alt text on `area` elements.
*/
area?: string[];
/**
* Custom components to check for alt text on any of the supported elements.
*/
elements?: AltTextElements[];
/**
* Custom components to check for alt text on `img` elements.
*/
img?: string[];
/**
* Custom components to check for alt text on `input[type="image"]` elements.
*/
'input[type="image"]'?: string[];
/**
* Custom components to check for alt text on `object` elements.
*/
object?: string[];
}
export interface AnchorAmbiguousTextConfig {
/**
* List of ambiguous words or phrases that should be flagged in anchor text.
@@ -72,7 +72,7 @@ fn input_type_image(span: Span) -> OxcDiagnostic {
pub struct AltText(Box<AltTextConfig>);
#[derive(Debug, Clone, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "camelCase", default)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct AltTextConfig {
/// Custom components to check for alt text on `img` elements.
img: Option<Vec<CompactStr>>,
@@ -103,6 +103,26 @@ impl std::default::Default for AltTextConfig {
}
}
}
#[derive(Debug, Default, JsonSchema)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
#[expect(unused)]
struct AltTextConfigSchema {
#[serde(flatten)]
base: AltTextConfig,
/// Custom components to check for alt text on any of the supported elements.
elements: Option<Vec<AltTextElements>>,
}
#[derive(Debug, JsonSchema)]
#[serde(rename_all = "lowercase")]
#[expect(unused)]
enum AltTextElements {
Img,
Object,
Area,
#[serde(rename = "input[type=\"image\"]")]
InputTypeImage,
}
declare_oxc_lint!(
/// ### What it does
@@ -137,7 +157,7 @@ declare_oxc_lint!(
AltText,
jsx_a11y,
correctness,
config = AltTextConfig,
config = AltTextConfigSchema,
version = "0.0.16",
);
+1 -2
View File
@@ -13,7 +13,7 @@ use crate::rules::RuleEnum;
/// These should return the DummyRule struct/schema instead of the actual rule struct/schema,
/// until we verify that the rule's schema is valid and can be generated by schemars.
#[cfg(feature = "ruledocs")]
const NO_VERIFIED_VALID_SCHEMA: [&str; 28] = [
const NO_VERIFIED_VALID_SCHEMA: [&str; 27] = [
"eslint/func-name-matching", // second config can be on first position like [AllowWarnDeny, Config1, Config2] | [AllowWarnDeny, Config1] | [AllowWarnDeny, Config2]
"eslint/no-restricted-globals", // uses spread syntax like [AllowWarnDeny, ...Config]
"eslint/no-restricted-imports", // uses spread syntax like [AllowWarnDeny, ...Config]
@@ -26,7 +26,6 @@ const NO_VERIFIED_VALID_SCHEMA: [&str; 28] = [
"vitest/prefer-lowercase-title", // has options from other rule
"vitest/valid-title", // has options from other rule
"jsdoc/require-param",
"jsx_a11y/alt-text",
"jsx_a11y/anchor-is-valid",
"jsx_a11y/control-has-associated-label",
"jsx_a11y/img-redundant-alt",
+77 -1
View File
@@ -561,6 +561,65 @@
"disallow-in-func"
]
},
"AltTextConfigSchema": {
"type": "object",
"properties": {
"area": {
"description": "Custom components to check for alt text on `area` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `area` elements."
},
"elements": {
"description": "Custom components to check for alt text on any of the supported elements.",
"type": "array",
"items": {
"$ref": "#/definitions/AltTextElements"
},
"markdownDescription": "Custom components to check for alt text on any of the supported elements."
},
"img": {
"description": "Custom components to check for alt text on `img` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `img` elements."
},
"input[type=\"image\"]": {
"description": "Custom components to check for alt text on `input[type=\"image\"]` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `input[type=\"image\"]` elements."
},
"object": {
"description": "Custom components to check for alt text on `object` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `object` elements."
}
},
"additionalProperties": false
},
"AltTextElements": {
"type": "string",
"enum": [
"img",
"object",
"area",
"input[type=\"image\"]"
]
},
"AlwaysNever": {
"type": "string",
"enum": [
@@ -3251,7 +3310,24 @@
"$ref": "#/definitions/RuleNoConfig"
},
"jsx-a11y/alt-text": {
"$ref": "#/definitions/DummyRule"
"anyOf": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"type": "array",
"items": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"$ref": "#/definitions/AltTextConfigSchema"
}
],
"maxItems": 2,
"minItems": 1
}
]
},
"jsx-a11y/anchor-ambiguous-text": {
"anyOf": [
@@ -565,6 +565,65 @@ expression: json
"disallow-in-func"
]
},
"AltTextConfigSchema": {
"type": "object",
"properties": {
"area": {
"description": "Custom components to check for alt text on `area` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `area` elements."
},
"elements": {
"description": "Custom components to check for alt text on any of the supported elements.",
"type": "array",
"items": {
"$ref": "#/definitions/AltTextElements"
},
"markdownDescription": "Custom components to check for alt text on any of the supported elements."
},
"img": {
"description": "Custom components to check for alt text on `img` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `img` elements."
},
"input[type=\"image\"]": {
"description": "Custom components to check for alt text on `input[type=\"image\"]` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `input[type=\"image\"]` elements."
},
"object": {
"description": "Custom components to check for alt text on `object` elements.",
"default": [],
"type": "array",
"items": {
"type": "string"
},
"markdownDescription": "Custom components to check for alt text on `object` elements."
}
},
"additionalProperties": false
},
"AltTextElements": {
"type": "string",
"enum": [
"img",
"object",
"area",
"input[type=\"image\"]"
]
},
"AlwaysNever": {
"type": "string",
"enum": [
@@ -3255,7 +3314,24 @@ expression: json
"$ref": "#/definitions/RuleNoConfig"
},
"jsx-a11y/alt-text": {
"$ref": "#/definitions/DummyRule"
"anyOf": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"type": "array",
"items": [
{
"$ref": "#/definitions/AllowWarnDeny"
},
{
"$ref": "#/definitions/AltTextConfigSchema"
}
],
"maxItems": 2,
"minItems": 1
}
]
},
"jsx-a11y/anchor-ambiguous-text": {
"anyOf": [