@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
JavaScript
import { aria } from 'aria-query';
import { propName } from '../util/module/jsx-ast-utils.js';
import { generateObjSchema } from '../util/schemas.js';
import getSuggestion from '../util/getSuggestion.js';
const ariaAttributes = [...aria.keys()];
const errorMessage = (name) => {
const suggestions = getSuggestion(name, ariaAttributes);
const message = `${name}: This attribute is an invalid ARIA attribute.`;
if (suggestions.length > 0) {
return `${message} Did you mean to use ${suggestions}?`;
}
return message;
};
const schema = generateObjSchema();
const ruleOfAriaProps = {
meta: {
docs: {
url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-props.md",
description: "Enforce all `aria-*` props are valid."
},
schema: [schema]
},
create: (context) => ({
JSXAttribute: (attribute) => {
const name = propName(attribute);
if (name.indexOf("aria-") !== 0) {
return;
}
const isValid = aria.has(name);
if (isValid === false) {
context.report({
node: attribute,
message: errorMessage(name)
});
}
}
})
};
export { ruleOfAriaProps as default };