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.05 kB
const jsxAstUtils = require('../util/module/jsx-ast-utils.cjs'); const schemas = require('../util/schemas.cjs'); const getElementType = require('../util/getElementType.cjs'); const errorMessage = "<html> elements must have the lang prop."; const schema = schemas.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 = jsxAstUtils.getPropValue(jsxAstUtils.getProp(node.attributes, "lang")); if (lang) { return; } context.report({ node, message: errorMessage }); } }; } }; module.exports = ruleOfHtmlHasLang;