UNPKG

@jsxtools/eslint-plugin-jsx-a11y

Version:

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

33 lines (30 loc) 966 B
const jsxAstUtils = require('../util/module/jsx-ast-utils.cjs'); const schemas = require('../util/schemas.cjs'); const errorMessage = "Avoid positive integer values for tabIndex."; const schema = schemas.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 = jsxAstUtils.propName(attribute).toUpperCase(); if (name !== "TABINDEX") { return; } const value = Number(jsxAstUtils.getLiteralPropValue(attribute)); if (isNaN(value) || value <= 0) { return; } context.report({ node: attribute, message: errorMessage }); } }) }; module.exports = ruleOfTabindexNoPositive;