UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

42 lines (39 loc) 1.21 kB
const ariaQuery = require('aria-query'); const jsxAstUtils = require('../util/module/jsx-ast-utils.cjs'); const schemas = require('../util/schemas.cjs'); const getElementType = require('../util/getElementType.cjs'); const errorMessage = "The scope prop can only be used on <th> elements."; const schema = schemas.generateObjSchema(); const ruleOfScope = { meta: { docs: { url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/scope.md", description: "Enforce `scope` prop is only used on `<th>` elements." }, schema: [schema] }, create: (context) => { const elementType = getElementType(context); return { JSXAttribute: (node) => { const name = jsxAstUtils.propName(node); if (name && name.toUpperCase() !== "SCOPE") { return; } const { parent } = node; const tagName = elementType(parent); if (!ariaQuery.dom.has(tagName)) { return; } if (tagName && tagName.toUpperCase() === "TH") { return; } context.report({ node, message: errorMessage }); } }; } }; module.exports = ruleOfScope;