| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports["default"] = void 0;
|
|---|
| 7 | var _jsxAstUtils = require("jsx-ast-utils");
|
|---|
| 8 | var _schemas = require("../util/schemas");
|
|---|
| 9 | /**
|
|---|
| 10 | * @fileoverview Enforce tabIndex value is not greater than zero.
|
|---|
| 11 | * @author Ethan Cohen
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | // ----------------------------------------------------------------------------
|
|---|
| 15 | // Rule Definition
|
|---|
| 16 | // ----------------------------------------------------------------------------
|
|---|
| 17 |
|
|---|
| 18 | var errorMessage = 'Avoid positive integer values for tabIndex.';
|
|---|
| 19 | var schema = (0, _schemas.generateObjSchema)();
|
|---|
| 20 | var _default = exports["default"] = {
|
|---|
| 21 | meta: {
|
|---|
| 22 | docs: {
|
|---|
| 23 | url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/tabindex-no-positive.md',
|
|---|
| 24 | description: 'Enforce `tabIndex` value is not greater than zero.'
|
|---|
| 25 | },
|
|---|
| 26 | schema: [schema]
|
|---|
| 27 | },
|
|---|
| 28 | create: function create(context) {
|
|---|
| 29 | return {
|
|---|
| 30 | JSXAttribute: function JSXAttribute(attribute) {
|
|---|
| 31 | var name = (0, _jsxAstUtils.propName)(attribute).toUpperCase();
|
|---|
| 32 |
|
|---|
| 33 | // Check if tabIndex is the attribute
|
|---|
| 34 | if (name !== 'TABINDEX') {
|
|---|
| 35 | return;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | // Only check literals because we can't infer values from certain expressions.
|
|---|
| 39 | var value = Number((0, _jsxAstUtils.getLiteralPropValue)(attribute));
|
|---|
| 40 |
|
|---|
| 41 | // eslint-disable-next-line no-restricted-globals
|
|---|
| 42 | if (isNaN(value) || value <= 0) {
|
|---|
| 43 | return;
|
|---|
| 44 | }
|
|---|
| 45 | context.report({
|
|---|
| 46 | node: attribute,
|
|---|
| 47 | message: errorMessage
|
|---|
| 48 | });
|
|---|
| 49 | }
|
|---|
| 50 | };
|
|---|
| 51 | }
|
|---|
| 52 | };
|
|---|
| 53 | module.exports = exports.default; |
|---|