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.03 kB
import { getPropValue, getProp } from '../util/module/jsx-ast-utils.js'; import { generateObjSchema } from '../util/schemas.js'; import getElementType from '../util/getElementType.js'; const errorMessage = "<html> elements must have the lang prop."; const schema = generateObjSchema(); const ruleOfHtmlHasLang = { meta: { docs: { url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/html-has-lang.md", description: "Enforce `<html>` element has `lang` prop." }, schema: [schema] }, create: (context) => { const elementType = getElementType(context); return { JSXOpeningElement: (node) => { const type = elementType(node); if (type && type !== "html") { return; } const lang = getPropValue(getProp(node.attributes, "lang")); if (lang) { return; } context.report({ node, message: errorMessage }); } }; } }; export { ruleOfHtmlHasLang as default };