@jsxtools/eslint-plugin-jsx-a11y
Version:
Static AST checker for accessibility rules on JSX elements for flat ESLint Config.
53 lines (50 loc) • 1.41 kB
JavaScript
import tags from 'language-tags';
import { propName, getLiteralPropValue } from '../util/module/jsx-ast-utils.js';
import { generateObjSchema } from '../util/schemas.js';
import getElementType from '../util/getElementType.js';
const errorMessage = "lang attribute must have a valid value.";
const schema = generateObjSchema();
const ruleOfLang = {
meta: {
docs: {
url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/lang.md",
description: "Enforce lang attribute has a valid value."
},
schema: [schema]
},
create: (context) => {
const elementType = getElementType(context);
return {
JSXAttribute: (node) => {
const name = propName(node);
if (name && name.toUpperCase() !== "LANG") {
return;
}
const { parent } = node;
const type = elementType(parent);
if (type && type !== "html") {
return;
}
const value = getLiteralPropValue(node);
if (value === null) {
return;
}
if (value === void 0) {
context.report({
node,
message: errorMessage
});
return;
}
if (tags.check(value)) {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
export { ruleOfLang as default };