source: frontend/node_modules/eslint-plugin-jsx-a11y/lib/rules/no-interactive-element-to-noninteractive-role.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 3.1 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7var _ariaQuery = require("aria-query");
8var _jsxAstUtils = require("jsx-ast-utils");
9var _arrayIncludes = _interopRequireDefault(require("array-includes"));
10var _hasown = _interopRequireDefault(require("hasown"));
11var _getElementType = _interopRequireDefault(require("../util/getElementType"));
12var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
13var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
14var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
15function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
16/**
17 * @fileoverview Disallow inherently interactive elements to be assigned
18 * non-interactive roles.
19 * @author Jesse Beach
20 *
21 */
22
23// ----------------------------------------------------------------------------
24// Rule Definition
25// ----------------------------------------------------------------------------
26
27var errorMessage = 'Interactive elements should not be assigned non-interactive roles.';
28var _default = exports["default"] = {
29 meta: {
30 docs: {
31 url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-interactive-element-to-noninteractive-role.md',
32 description: 'Interactive elements should not be assigned non-interactive roles.'
33 },
34 schema: [{
35 type: 'object',
36 additionalProperties: {
37 type: 'array',
38 items: {
39 type: 'string'
40 },
41 uniqueItems: true
42 }
43 }]
44 },
45 create: function create(context) {
46 var options = context.options;
47 var elementType = (0, _getElementType["default"])(context);
48 return {
49 JSXAttribute: function JSXAttribute(attribute) {
50 var attributeName = (0, _jsxAstUtils.propName)(attribute);
51 // $FlowFixMe: [TODO] Mark propName as a JSXIdentifier, not a string.
52 if (attributeName !== 'role') {
53 return;
54 }
55 var node = attribute.parent;
56 var attributes = node.attributes;
57 var type = elementType(node);
58 var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'role'));
59 if (!_ariaQuery.dom.has(type)) {
60 // Do not test higher level JSX components, as we do not know what
61 // low-level DOM element this maps to.
62 return;
63 }
64 // Allow overrides from rule configuration for specific elements and
65 // roles.
66 var allowedRoles = options[0] || {};
67 if ((0, _hasown["default"])(allowedRoles, type) && (0, _arrayIncludes["default"])(allowedRoles[type], role)) {
68 return;
69 }
70 if ((0, _isInteractiveElement["default"])(type, attributes) && ((0, _isNonInteractiveRole["default"])(type, attributes) || (0, _isPresentationRole["default"])(type, attributes))) {
71 // Visible, non-interactive elements should not have an interactive handler.
72 context.report({
73 node: attribute,
74 message: errorMessage
75 });
76 }
77 }
78 };
79 }
80};
81module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.