UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

Static AST checker for accessibility rules on JSX elements for flat ESLint Config.

37 lines (34 loc) 1.1 kB
import { getPropValue, getProp } from '../util/module/jsx-ast-utils.js'; import getElementType from '../util/getElementType.js'; import { generateObjSchema } from '../util/schemas.js'; const errorMessage = "<iframe> elements must have a unique title property."; const schema = generateObjSchema(); const ruleOfIframeHasTitle = { meta: { docs: { url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/iframe-has-title.md", description: "Enforce iframe elements have a title attribute." }, schema: [schema] }, create: (context) => { const elementType = getElementType(context); return { JSXOpeningElement: (node) => { const type = elementType(node); if (type && type !== "iframe") { return; } const title = getPropValue(getProp(node.attributes, "title")); if (title && typeof title === "string") { return; } context.report({ node, message: errorMessage }); } }; } }; export { ruleOfIframeHasTitle as default };