@jsxtools/eslint-plugin-jsx-a11y
Version:
Static AST checker for accessibility rules on JSX elements for flat ESLint Config.
42 lines (39 loc) • 1.17 kB
JavaScript
import { dom } from 'aria-query';
import { propName } from '../util/module/jsx-ast-utils.js';
import { generateObjSchema } from '../util/schemas.js';
import getElementType from '../util/getElementType.js';
const errorMessage = "The scope prop can only be used on <th> elements.";
const schema = 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 = propName(node);
if (name && name.toUpperCase() !== "SCOPE") {
return;
}
const { parent } = node;
const tagName = elementType(parent);
if (!dom.has(tagName)) {
return;
}
if (tagName && tagName.toUpperCase() === "TH") {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
export { ruleOfScope as default };