UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

Static AST checker for accessibility rules on JSX elements for flat ESLint Config.

33 lines (30 loc) 963 B
import { propName, getLiteralPropValue } from '../util/module/jsx-ast-utils.js'; import { generateObjSchema } from '../util/schemas.js'; const errorMessage = "Avoid positive integer values for tabIndex."; const schema = generateObjSchema(); const ruleOfTabindexNoPositive = { meta: { docs: { url: "https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/tabindex-no-positive.md", description: "Enforce `tabIndex` value is not greater than zero." }, schema: [schema] }, create: (context) => ({ JSXAttribute: (attribute) => { const name = propName(attribute).toUpperCase(); if (name !== "TABINDEX") { return; } const value = Number(getLiteralPropValue(attribute)); if (isNaN(value) || value <= 0) { return; } context.report({ node: attribute, message: errorMessage }); } }) }; export { ruleOfTabindexNoPositive as default };