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.11 kB
const jsxAstUtils = require('../util/module/jsx-ast-utils.cjs'); const getElementType = require('../util/getElementType.cjs'); const schemas = require('../util/schemas.cjs'); const errorMessage = "<iframe> elements must have a unique title property."; const schema = schemas.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 = jsxAstUtils.getPropValue(jsxAstUtils.getProp(node.attributes, "title")); if (title && typeof title === "string") { return; } context.report({ node, message: errorMessage }); } }; } }; module.exports = ruleOfIframeHasTitle;