main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
"use strict";
module.exports = {
languageOptions: {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
}
};

View File

@@ -0,0 +1,9 @@
"use strict";
module.exports = {
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
};

208
node_modules/eslint-plugin-jsx-a11y/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,208 @@
"use strict";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
/* eslint-disable global-require */
var flatConfigBase = require('./configs/flat-config-base');
var legacyConfigBase = require('./configs/legacy-config-base');
var _require = require('../package.json'),
name = _require.name,
version = _require.version;
var allRules = {
'accessible-emoji': require('./rules/accessible-emoji'),
'alt-text': require('./rules/alt-text'),
'anchor-ambiguous-text': require('./rules/anchor-ambiguous-text'),
'anchor-has-content': require('./rules/anchor-has-content'),
'anchor-is-valid': require('./rules/anchor-is-valid'),
'aria-activedescendant-has-tabindex': require('./rules/aria-activedescendant-has-tabindex'),
'aria-props': require('./rules/aria-props'),
'aria-proptypes': require('./rules/aria-proptypes'),
'aria-role': require('./rules/aria-role'),
'aria-unsupported-elements': require('./rules/aria-unsupported-elements'),
'autocomplete-valid': require('./rules/autocomplete-valid'),
'click-events-have-key-events': require('./rules/click-events-have-key-events'),
'control-has-associated-label': require('./rules/control-has-associated-label'),
'heading-has-content': require('./rules/heading-has-content'),
'html-has-lang': require('./rules/html-has-lang'),
'iframe-has-title': require('./rules/iframe-has-title'),
'img-redundant-alt': require('./rules/img-redundant-alt'),
'interactive-supports-focus': require('./rules/interactive-supports-focus'),
'label-has-associated-control': require('./rules/label-has-associated-control'),
'label-has-for': require('./rules/label-has-for'),
lang: require('./rules/lang'),
'media-has-caption': require('./rules/media-has-caption'),
'mouse-events-have-key-events': require('./rules/mouse-events-have-key-events'),
'no-access-key': require('./rules/no-access-key'),
'no-aria-hidden-on-focusable': require('./rules/no-aria-hidden-on-focusable'),
'no-autofocus': require('./rules/no-autofocus'),
'no-distracting-elements': require('./rules/no-distracting-elements'),
'no-interactive-element-to-noninteractive-role': require('./rules/no-interactive-element-to-noninteractive-role'),
'no-noninteractive-element-interactions': require('./rules/no-noninteractive-element-interactions'),
'no-noninteractive-element-to-interactive-role': require('./rules/no-noninteractive-element-to-interactive-role'),
'no-noninteractive-tabindex': require('./rules/no-noninteractive-tabindex'),
'no-onchange': require('./rules/no-onchange'),
'no-redundant-roles': require('./rules/no-redundant-roles'),
'no-static-element-interactions': require('./rules/no-static-element-interactions'),
'prefer-tag-over-role': require('./rules/prefer-tag-over-role'),
'role-has-required-aria-props': require('./rules/role-has-required-aria-props'),
'role-supports-aria-props': require('./rules/role-supports-aria-props'),
scope: require('./rules/scope'),
'tabindex-no-positive': require('./rules/tabindex-no-positive')
};
var recommendedRules = {
'jsx-a11y/alt-text': 'error',
'jsx-a11y/anchor-ambiguous-text': 'off',
// TODO: error
'jsx-a11y/anchor-has-content': 'error',
'jsx-a11y/anchor-is-valid': 'error',
'jsx-a11y/aria-activedescendant-has-tabindex': 'error',
'jsx-a11y/aria-props': 'error',
'jsx-a11y/aria-proptypes': 'error',
'jsx-a11y/aria-role': 'error',
'jsx-a11y/aria-unsupported-elements': 'error',
'jsx-a11y/autocomplete-valid': 'error',
'jsx-a11y/click-events-have-key-events': 'error',
'jsx-a11y/control-has-associated-label': ['off', {
ignoreElements: ['audio', 'canvas', 'embed', 'input', 'textarea', 'tr', 'video'],
ignoreRoles: ['grid', 'listbox', 'menu', 'menubar', 'radiogroup', 'row', 'tablist', 'toolbar', 'tree', 'treegrid'],
includeRoles: ['alert', 'dialog']
}],
'jsx-a11y/heading-has-content': 'error',
'jsx-a11y/html-has-lang': 'error',
'jsx-a11y/iframe-has-title': 'error',
'jsx-a11y/img-redundant-alt': 'error',
'jsx-a11y/interactive-supports-focus': ['error', {
tabbable: ['button', 'checkbox', 'link', 'searchbox', 'spinbutton', 'switch', 'textbox']
}],
'jsx-a11y/label-has-associated-control': 'error',
'jsx-a11y/label-has-for': 'off',
'jsx-a11y/media-has-caption': 'error',
'jsx-a11y/mouse-events-have-key-events': 'error',
'jsx-a11y/no-access-key': 'error',
'jsx-a11y/no-autofocus': 'error',
'jsx-a11y/no-distracting-elements': 'error',
'jsx-a11y/no-interactive-element-to-noninteractive-role': ['error', {
tr: ['none', 'presentation'],
canvas: ['img']
}],
'jsx-a11y/no-noninteractive-element-interactions': ['error', {
handlers: ['onClick', 'onError', 'onLoad', 'onMouseDown', 'onMouseUp', 'onKeyPress', 'onKeyDown', 'onKeyUp'],
alert: ['onKeyUp', 'onKeyDown', 'onKeyPress'],
body: ['onError', 'onLoad'],
dialog: ['onKeyUp', 'onKeyDown', 'onKeyPress'],
iframe: ['onError', 'onLoad'],
img: ['onError', 'onLoad']
}],
'jsx-a11y/no-noninteractive-element-to-interactive-role': ['error', {
ul: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
ol: ['listbox', 'menu', 'menubar', 'radiogroup', 'tablist', 'tree', 'treegrid'],
li: ['menuitem', 'menuitemradio', 'menuitemcheckbox', 'option', 'row', 'tab', 'treeitem'],
table: ['grid'],
td: ['gridcell'],
fieldset: ['radiogroup', 'presentation']
}],
'jsx-a11y/no-noninteractive-tabindex': ['error', {
tags: [],
roles: ['tabpanel'],
allowExpressionValues: true
}],
'jsx-a11y/no-redundant-roles': 'error',
'jsx-a11y/no-static-element-interactions': ['error', {
allowExpressionValues: true,
handlers: ['onClick', 'onMouseDown', 'onMouseUp', 'onKeyPress', 'onKeyDown', 'onKeyUp']
}],
'jsx-a11y/role-has-required-aria-props': 'error',
'jsx-a11y/role-supports-aria-props': 'error',
'jsx-a11y/scope': 'error',
'jsx-a11y/tabindex-no-positive': 'error'
};
var strictRules = {
'jsx-a11y/alt-text': 'error',
'jsx-a11y/anchor-has-content': 'error',
'jsx-a11y/anchor-is-valid': 'error',
'jsx-a11y/aria-activedescendant-has-tabindex': 'error',
'jsx-a11y/aria-props': 'error',
'jsx-a11y/aria-proptypes': 'error',
'jsx-a11y/aria-role': 'error',
'jsx-a11y/aria-unsupported-elements': 'error',
'jsx-a11y/autocomplete-valid': 'error',
'jsx-a11y/click-events-have-key-events': 'error',
'jsx-a11y/control-has-associated-label': ['off', {
ignoreElements: ['audio', 'canvas', 'embed', 'input', 'textarea', 'tr', 'video'],
ignoreRoles: ['grid', 'listbox', 'menu', 'menubar', 'radiogroup', 'row', 'tablist', 'toolbar', 'tree', 'treegrid'],
includeRoles: ['alert', 'dialog']
}],
'jsx-a11y/heading-has-content': 'error',
'jsx-a11y/html-has-lang': 'error',
'jsx-a11y/iframe-has-title': 'error',
'jsx-a11y/img-redundant-alt': 'error',
'jsx-a11y/interactive-supports-focus': ['error', {
tabbable: ['button', 'checkbox', 'link', 'progressbar', 'searchbox', 'slider', 'spinbutton', 'switch', 'textbox']
}],
'jsx-a11y/label-has-for': 'off',
'jsx-a11y/label-has-associated-control': 'error',
'jsx-a11y/media-has-caption': 'error',
'jsx-a11y/mouse-events-have-key-events': 'error',
'jsx-a11y/no-access-key': 'error',
'jsx-a11y/no-autofocus': 'error',
'jsx-a11y/no-distracting-elements': 'error',
'jsx-a11y/no-interactive-element-to-noninteractive-role': 'error',
'jsx-a11y/no-noninteractive-element-interactions': ['error', {
body: ['onError', 'onLoad'],
iframe: ['onError', 'onLoad'],
img: ['onError', 'onLoad']
}],
'jsx-a11y/no-noninteractive-element-to-interactive-role': 'error',
'jsx-a11y/no-noninteractive-tabindex': 'error',
'jsx-a11y/no-redundant-roles': 'error',
'jsx-a11y/no-static-element-interactions': 'error',
'jsx-a11y/role-has-required-aria-props': 'error',
'jsx-a11y/role-supports-aria-props': 'error',
'jsx-a11y/scope': 'error',
'jsx-a11y/tabindex-no-positive': 'error'
};
/** Base plugin object */
var jsxA11y = {
meta: {
name,
version
},
rules: _objectSpread({}, allRules)
};
/**
* Given a ruleset and optionally a flat config name, generate a config.
* @param {object} rules - ruleset for this config
* @param {string} flatConfigName - name for the config if flat
* @returns Config for this set of rules.
*/
var createConfig = function createConfig(rules, flatConfigName) {
return _objectSpread(_objectSpread({}, flatConfigName ? _objectSpread(_objectSpread({}, flatConfigBase), {}, {
name: "jsx-a11y/".concat(flatConfigName),
plugins: {
'jsx-a11y': jsxA11y
}
}) : _objectSpread(_objectSpread({}, legacyConfigBase), {}, {
plugins: ['jsx-a11y']
})), {}, {
rules: _objectSpread({}, rules)
});
};
// Create configs for the plugin object
var configs = {
recommended: createConfig(recommendedRules),
strict: createConfig(strictRules)
};
var flatConfigs = {
recommended: createConfig(recommendedRules, 'recommended'),
strict: createConfig(strictRules, 'strict')
};
module.exports = _objectSpread(_objectSpread({}, jsxA11y), {}, {
configs,
flatConfigs
});

View File

@@ -0,0 +1,63 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _emojiRegex = _interopRequireDefault(require("emoji-regex"));
var _jsxAstUtils = require("jsx-ast-utils");
var _safeRegexTest = _interopRequireDefault(require("safe-regex-test"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce emojis are wrapped in <span> and provide screenreader access.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Emojis should be wrapped in <span>, have role="img", and have an accessible description with aria-label or aria-labelledby.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
description: 'Enforce emojis are wrapped in `<span>` and provide screenreader access.',
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/accessible-emoji.md'
},
deprecated: true,
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
var testEmoji = (0, _safeRegexTest["default"])((0, _emojiRegex["default"])());
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var literalChildValue = node.parent.children.find(function (child) {
return child.type === 'Literal' || child.type === 'JSXText';
});
if (literalChildValue && testEmoji(literalChildValue.value)) {
var elementIsHidden = (0, _isHiddenFromScreenReader["default"])(elementType(node), node.attributes);
if (elementIsHidden) {
return; // emoji is decorative
}
var rolePropValue = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'role'));
var ariaLabelProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-label');
var arialLabelledByProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-labelledby');
var hasLabel = ariaLabelProp !== undefined || arialLabelledByProp !== undefined;
var isSpan = elementType(node) === 'span';
if (hasLabel === false || rolePropValue !== 'img' || isSpan === false) {
context.report({
node,
message: errorMessage
});
}
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,218 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _hasAccessibleChild = _interopRequireDefault(require("../util/hasAccessibleChild"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce all elements that require alternative text have it.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var DEFAULT_ELEMENTS = ['img', 'object', 'area', 'input[type="image"]'];
var schema = (0, _schemas.generateObjSchema)({
elements: _schemas.arraySchema,
img: _schemas.arraySchema,
object: _schemas.arraySchema,
area: _schemas.arraySchema,
'input[type="image"]': _schemas.arraySchema
});
var ariaLabelHasValue = function ariaLabelHasValue(prop) {
var value = (0, _jsxAstUtils.getPropValue)(prop);
if (value === undefined) {
return false;
}
if (typeof value === 'string' && value.length === 0) {
return false;
}
return true;
};
var ruleByElement = {
img(context, node, nodeType) {
var altProp = (0, _jsxAstUtils.getProp)(node.attributes, 'alt');
// Missing alt prop error.
if (altProp === undefined) {
if ((0, _isPresentationRole["default"])(nodeType, node.attributes)) {
context.report({
node,
message: 'Prefer alt="" over a presentational role. First rule of aria is to not use aria if it can be achieved via native HTML.'
});
return;
}
// Check for `aria-label` to provide text alternative
// Don't create an error if the attribute is used correctly. But if it
// isn't, suggest that the developer use `alt` instead.
var ariaLabelProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-label');
if (ariaLabelProp !== undefined) {
if (!ariaLabelHasValue(ariaLabelProp)) {
context.report({
node,
message: 'The aria-label attribute must have a value. The alt attribute is preferred over aria-label for images.'
});
}
return;
}
// Check for `aria-labelledby` to provide text alternative
// Don't create an error if the attribute is used correctly. But if it
// isn't, suggest that the developer use `alt` instead.
var ariaLabelledbyProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-labelledby');
if (ariaLabelledbyProp !== undefined) {
if (!ariaLabelHasValue(ariaLabelledbyProp)) {
context.report({
node,
message: 'The aria-labelledby attribute must have a value. The alt attribute is preferred over aria-labelledby for images.'
});
}
return;
}
context.report({
node,
message: "".concat(nodeType, " elements must have an alt prop, either with meaningful text, or an empty string for decorative images.")
});
return;
}
// Check if alt prop is undefined.
var altValue = (0, _jsxAstUtils.getPropValue)(altProp);
var isNullValued = altProp.value === null; // <img alt />
if (altValue && !isNullValued || altValue === '') {
return;
}
// Undefined alt prop error.
context.report({
node,
message: "Invalid alt value for ".concat(nodeType, ". Use alt=\"\" for presentational images.")
});
},
object(context, node, unusedNodeType, elementType) {
var ariaLabelProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-label');
var arialLabelledByProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-labelledby');
var hasLabel = ariaLabelHasValue(ariaLabelProp) || ariaLabelHasValue(arialLabelledByProp);
var titleProp = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'title'));
var hasTitleAttr = !!titleProp;
if (hasLabel || hasTitleAttr || (0, _hasAccessibleChild["default"])(node.parent, elementType)) {
return;
}
context.report({
node,
message: 'Embedded <object> elements must have alternative text by providing inner text, aria-label or aria-labelledby props.'
});
},
area(context, node) {
var ariaLabelProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-label');
var arialLabelledByProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-labelledby');
var hasLabel = ariaLabelHasValue(ariaLabelProp) || ariaLabelHasValue(arialLabelledByProp);
if (hasLabel) {
return;
}
var altProp = (0, _jsxAstUtils.getProp)(node.attributes, 'alt');
if (altProp === undefined) {
context.report({
node,
message: 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.'
});
return;
}
var altValue = (0, _jsxAstUtils.getPropValue)(altProp);
var isNullValued = altProp.value === null; // <area alt />
if (altValue && !isNullValued || altValue === '') {
return;
}
context.report({
node,
message: 'Each area of an image map must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.'
});
},
'input[type="image"]': function inputImage(context, node, nodeType) {
// Only test input[type="image"]
if (nodeType === 'input') {
var typePropValue = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'type'));
if (typePropValue !== 'image') {
return;
}
}
var ariaLabelProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-label');
var arialLabelledByProp = (0, _jsxAstUtils.getProp)(node.attributes, 'aria-labelledby');
var hasLabel = ariaLabelHasValue(ariaLabelProp) || ariaLabelHasValue(arialLabelledByProp);
if (hasLabel) {
return;
}
var altProp = (0, _jsxAstUtils.getProp)(node.attributes, 'alt');
if (altProp === undefined) {
context.report({
node,
message: '<input> elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.'
});
return;
}
var altValue = (0, _jsxAstUtils.getPropValue)(altProp);
var isNullValued = altProp.value === null; // <area alt />
if (altValue && !isNullValued || altValue === '') {
return;
}
context.report({
node,
message: '<input> elements with type="image" must have a text alternative through the `alt`, `aria-label`, or `aria-labelledby` prop.'
});
}
};
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/alt-text.md',
description: 'Enforce all elements that require alternative text have meaningful information to relay back to end user.'
},
schema: [schema]
},
create: function create(context) {
var options = context.options[0] || {};
// Elements to validate for alt text.
var elementOptions = options.elements || DEFAULT_ELEMENTS;
// Get custom components for just the elements that will be tested.
var customComponents = (0, _arrayPrototype["default"])(elementOptions, function (element) {
return options[element];
});
var typesToValidate = new Set([].concat(customComponents, elementOptions).map(function (type) {
return type === 'input[type="image"]' ? 'input' : type;
}));
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement(node) {
var nodeType = elementType(node);
if (!typesToValidate.has(nodeType)) {
return;
}
var DOMElement = nodeType;
if (DOMElement === 'input') {
DOMElement = 'input[type="image"]';
}
// Map nodeType to the DOM element if we are running this on a custom component.
if (elementOptions.indexOf(DOMElement) === -1) {
DOMElement = elementOptions.find(function (element) {
var customComponentsForElement = options[element] || [];
return customComponentsForElement.indexOf(nodeType) > -1;
});
}
ruleByElement[DOMElement](context, node, nodeType, elementType);
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,64 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _schemas = require("../util/schemas");
var _getAccessibleChildText = _interopRequireDefault(require("../util/getAccessibleChildText"));
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce anchor text to not exactly match 'click here', 'here', 'link', 'learn more', and user-specified words.
* @author Matt Wang
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var DEFAULT_AMBIGUOUS_WORDS = ['click here', 'here', 'link', 'a link', 'learn more'];
var schema = (0, _schemas.generateObjSchema)({
words: _schemas.arraySchema
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-ambiguous-text.md',
description: 'Enforce `<a>` text to not exactly match "click here", "here", "link", or "a link".'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
var typesToValidate = ['a'];
var options = context.options[0] || {};
var _options$words = options.words,
words = _options$words === void 0 ? DEFAULT_AMBIGUOUS_WORDS : _options$words;
var ambiguousWords = new Set(words);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var nodeType = elementType(node);
// Only check anchor elements and custom types.
if (typesToValidate.indexOf(nodeType) === -1) {
return;
}
var nodeText = (0, _getAccessibleChildText["default"])(node.parent, elementType);
if (!ambiguousWords.has(nodeText)) {
// check the value
return;
}
context.report({
node,
message: 'Ambiguous text within anchor. Screenreader users rely on link text for context; the words "{{wordsList}}" are ambiguous and do not provide enough context.',
data: {
wordsList: words.join('", "')
}
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _schemas = require("../util/schemas");
var _hasAccessibleChild = _interopRequireDefault(require("../util/hasAccessibleChild"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce anchor elements to contain accessible content.
* @author Lisa Ring & Niklas Holmberg
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Anchors must have content and the content must be accessible by a screen reader.';
var schema = (0, _schemas.generateObjSchema)({
components: _schemas.arraySchema
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-has-content.md',
description: 'Enforce all anchors to contain accessible content.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var options = context.options[0] || {};
var componentOptions = options.components || [];
var typeCheck = ['a'].concat(componentOptions);
var nodeType = elementType(node);
// Only check anchor elements and custom types.
if (typeCheck.indexOf(nodeType) === -1) {
return;
}
if ((0, _hasAccessibleChild["default"])(node.parent, elementType)) {
return;
}
if ((0, _jsxAstUtils.hasAnyProp)(node.attributes, ['title', 'aria-label'])) {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,122 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _safeRegexTest = _interopRequireDefault(require("safe-regex-test"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Performs validity check on anchor hrefs. Warns when anchors are used as buttons.
* @author Almero Steyn
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var allAspects = ['noHref', 'invalidHref', 'preferButton'];
var preferButtonErrorMessage = 'Anchor used as a button. Anchors are primarily expected to navigate. Use the button element instead. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md';
var noHrefErrorMessage = 'The href attribute is required for an anchor to be keyboard accessible. Provide a valid, navigable address as the href value. If you cannot provide an href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md';
var invalidHrefErrorMessage = 'The href attribute requires a valid value to be accessible. Provide a valid, navigable address as the href value. If you cannot provide a valid href, but still need the element to resemble a link, use a button and change it with appropriate styles. Learn more: https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/HEAD/docs/rules/anchor-is-valid.md';
var schema = (0, _schemas.generateObjSchema)({
components: _schemas.arraySchema,
specialLink: _schemas.arraySchema,
aspects: (0, _schemas.enumArraySchema)(allAspects, 1)
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/anchor-is-valid.md',
description: 'Enforce all anchors are valid, navigable elements.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
var testJShref = (0, _safeRegexTest["default"])(/^\W*?javascript:/);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var attributes = node.attributes;
var options = context.options[0] || {};
var componentOptions = options.components || [];
var typeCheck = ['a'].concat(componentOptions);
var nodeType = elementType(node);
// Only check anchor elements and custom types.
if (typeCheck.indexOf(nodeType) === -1) {
return;
}
// Set up the rule aspects to check.
var aspects = options.aspects || allAspects;
// Create active aspect flag object. Failing checks will only report
// if the related flag is set to true.
var activeAspects = {};
allAspects.forEach(function (aspect) {
activeAspects[aspect] = aspects.indexOf(aspect) !== -1;
});
var propOptions = options.specialLink || [];
var propsToValidate = ['href'].concat(propOptions);
var values = propsToValidate.map(function (prop) {
return (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(node.attributes, prop));
});
// Checks if any actual or custom href prop is provided.
var hasAnyHref = values.some(function (value) {
return value != null;
});
// Need to check for spread operator as props can be spread onto the element
// leading to an incorrect validation error.
var hasSpreadOperator = attributes.some(function (prop) {
return prop.type === 'JSXSpreadAttribute';
});
var onClick = (0, _jsxAstUtils.getProp)(attributes, 'onClick');
// When there is no href at all, specific scenarios apply:
if (!hasAnyHref) {
// If no spread operator is found and no onClick event is present
// it is a link without href.
if (!hasSpreadOperator && activeAspects.noHref && (!onClick || onClick && !activeAspects.preferButton)) {
context.report({
node,
message: noHrefErrorMessage
});
}
// If no spread operator is found but an onClick is preset it should be a button.
if (!hasSpreadOperator && onClick && activeAspects.preferButton) {
context.report({
node,
message: preferButtonErrorMessage
});
}
return;
}
// Hrefs have been found, now check for validity.
var invalidHrefValues = values.filter(function (value) {
return value != null && typeof value === 'string' && (!value.length || value === '#' || testJShref(value));
});
if (invalidHrefValues.length !== 0) {
// If an onClick is found it should be a button, otherwise it is an invalid link.
if (onClick && activeAspects.preferButton) {
context.report({
node,
message: preferButtonErrorMessage
});
} else if (activeAspects.invalidHref) {
context.report({
node,
message: invalidHrefErrorMessage
});
}
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _getTabIndex = _interopRequireDefault(require("../util/getTabIndex"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce elements with aria-activedescendant are tabbable.
* @author Jesse Beach <@jessebeach>
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'An element that manages focus with `aria-activedescendant` must have a tabindex';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-activedescendant-has-tabindex.md',
description: 'Enforce elements with aria-activedescendant are tabbable.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var attributes = node.attributes;
if ((0, _jsxAstUtils.getProp)(attributes, 'aria-activedescendant') === undefined) {
return;
}
var type = elementType(node);
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
if (!_ariaQuery.dom.has(type)) {
return;
}
var tabIndex = (0, _getTabIndex["default"])((0, _jsxAstUtils.getProp)(attributes, 'tabIndex'));
// If this is an interactive element and the tabindex attribute is not specified,
// or the tabIndex property was not mutated, then the tabIndex
// property will be undefined.
if ((0, _isInteractiveElement["default"])(type, attributes) && tabIndex === undefined) {
return;
}
if (tabIndex >= -1) {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getSuggestion = _interopRequireDefault(require("../util/getSuggestion"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
* @fileoverview Enforce all aria-* properties are valid.
* @author Ethan Cohen
*/ // ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var ariaAttributes = _toConsumableArray(_ariaQuery.aria.keys());
var errorMessage = function errorMessage(name) {
var suggestions = (0, _getSuggestion["default"])(name, ariaAttributes);
var message = "".concat(name, ": This attribute is an invalid ARIA attribute.");
if (suggestions.length > 0) {
return "".concat(message, " Did you mean to use ").concat(suggestions, "?");
}
return message;
};
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-props.md',
description: 'Enforce all `aria-*` props are valid.'
},
schema: [schema]
},
create: function create(context) {
return {
JSXAttribute: function JSXAttribute(attribute) {
var name = (0, _jsxAstUtils.propName)(attribute);
// `aria` needs to be prefix of property.
if (name.indexOf('aria-') !== 0) {
return;
}
var isValid = _ariaQuery.aria.has(name);
if (isValid === false) {
context.report({
node: attribute,
message: errorMessage(name)
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,114 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
/**
* @fileoverview Enforce ARIA state and property values are valid.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = function errorMessage(name, type, permittedValues) {
switch (type) {
case 'tristate':
return "The value for ".concat(name, " must be a boolean or the string \"mixed\".");
case 'token':
return "The value for ".concat(name, " must be a single token from the following: ").concat(permittedValues, ".");
case 'tokenlist':
return "The value for ".concat(name, " must be a list of one or more tokens from the following: ").concat(permittedValues, ".");
case 'idlist':
return "The value for ".concat(name, " must be a list of strings that represent DOM element IDs (idlist)");
case 'id':
return "The value for ".concat(name, " must be a string that represents a DOM element ID");
case 'boolean':
case 'string':
case 'integer':
case 'number':
default:
return "The value for ".concat(name, " must be a ").concat(type, ".");
}
};
var _validityCheck = function validityCheck(value, expectedType, permittedValues) {
switch (expectedType) {
case 'boolean':
return typeof value === 'boolean';
case 'string':
case 'id':
return typeof value === 'string';
case 'tristate':
return typeof value === 'boolean' || value === 'mixed';
case 'integer':
case 'number':
// Booleans resolve to 0/1 values so hard check that it's not first.
// eslint-disable-next-line no-restricted-globals
return typeof value !== 'boolean' && isNaN(Number(value)) === false;
case 'token':
return permittedValues.indexOf(typeof value === 'string' ? value.toLowerCase() : value) > -1;
case 'idlist':
return typeof value === 'string' && value.split(' ').every(function (token) {
return _validityCheck(token, 'id', []);
});
case 'tokenlist':
return typeof value === 'string' && value.split(' ').every(function (token) {
return permittedValues.indexOf(token.toLowerCase()) > -1;
});
default:
return false;
}
};
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
validityCheck: _validityCheck,
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-proptypes.md',
description: 'Enforce ARIA state and property values are valid.'
},
schema: [schema]
},
create: function create(context) {
return {
JSXAttribute: function JSXAttribute(attribute) {
var name = (0, _jsxAstUtils.propName)(attribute);
var normalizedName = name.toLowerCase();
// Not a valid aria-* state or property.
if (normalizedName.indexOf('aria-') !== 0 || _ariaQuery.aria.get(normalizedName) === undefined) {
return;
}
// Ignore the attribute if its value is null or undefined.
if ((0, _jsxAstUtils.getPropValue)(attribute) == null) return;
var value = (0, _jsxAstUtils.getLiteralPropValue)(attribute);
// Ignore the attribute if its value is not a literal.
if (value === null) {
return;
}
// These are the attributes of the property/state to check against.
var attributes = _ariaQuery.aria.get(normalizedName);
var permittedType = attributes.type;
var allowUndefined = attributes.allowUndefined || false;
var permittedValues = attributes.values || [];
var isValid = _validityCheck(value, permittedType, permittedValues) || allowUndefined && value === undefined;
if (isValid) {
return;
}
context.report({
node: attribute,
message: errorMessage(name, permittedType, permittedValues)
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,91 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _Iterator = _interopRequireDefault(require("es-iterator-helpers/Iterator.from"));
var _IteratorPrototype = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.filter"));
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _schemas = require("../util/schemas");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce aria role attribute is valid.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Elements with ARIA roles must use a valid, non-abstract ARIA role.';
var schema = (0, _schemas.generateObjSchema)({
allowedInvalidRoles: {
items: {
type: 'string'
},
type: 'array',
uniqueItems: true
},
ignoreNonDOM: {
type: 'boolean',
"default": false
}
});
var validRoles = new Set((0, _IteratorPrototype["default"])((0, _Iterator["default"])(_ariaQuery.roles.keys()), function (role) {
return _ariaQuery.roles.get(role)["abstract"] === false;
}));
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-role.md',
description: 'Enforce that elements with ARIA roles must use a valid, non-abstract ARIA role.'
},
schema: [schema]
},
create: function create(context) {
var options = context.options[0] || {};
var ignoreNonDOM = !!options.ignoreNonDOM;
var allowedInvalidRoles = new Set(options.allowedInvalidRoles || []);
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(attribute) {
// If ignoreNonDOM and the parent isn't DOM, don't run rule.
if (ignoreNonDOM) {
var type = elementType(attribute.parent);
if (!_ariaQuery.dom.get(type)) {
return;
}
}
// Get prop name
var name = (0, _jsxAstUtils.propName)(attribute).toUpperCase();
if (name !== 'ROLE') {
return;
}
var value = (0, _jsxAstUtils.getLiteralPropValue)(attribute);
// If value is undefined, then the role attribute will be dropped in the DOM.
// If value is null, then getLiteralAttributeValue is telling us that the
// value isn't in the form of a literal.
if (value === undefined || value === null) {
return;
}
var values = String(value).split(' ');
var isValid = values.every(function (val) {
return allowedInvalidRoles.has(val) || validRoles.has(val);
});
if (isValid === true) {
return;
}
context.report({
node: attribute,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,66 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
* @fileoverview Enforce that elements that do not support ARIA roles,
* states and properties do not have those attributes.
* @author Ethan Cohen
*/ // ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = function errorMessage(invalidProp) {
return "This element does not support ARIA roles, states and properties. Try removing the prop '".concat(invalidProp, "'.");
};
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/aria-unsupported-elements.md',
description: 'Enforce that elements that do not support ARIA roles, states, and properties do not have those attributes.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var nodeType = elementType(node);
var nodeAttrs = _ariaQuery.dom.get(nodeType) || {};
var _nodeAttrs$reserved = nodeAttrs.reserved,
isReservedNodeType = _nodeAttrs$reserved === void 0 ? false : _nodeAttrs$reserved;
// If it's not reserved, then it can have aria-* roles, states, and properties
if (isReservedNodeType === false) {
return;
}
var invalidAttributes = new Set([].concat(_toConsumableArray(_ariaQuery.aria.keys()), ['role']));
node.attributes.forEach(function (prop) {
if (prop.type === 'JSXSpreadAttribute') {
return;
}
var name = (0, _jsxAstUtils.propName)(prop).toLowerCase();
if (invalidAttributes.has(name)) {
context.report({
node,
message: errorMessage(name)
});
}
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _axeCore = require("axe-core");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Ensure autocomplete attribute is correct.
* @author Wilco Fiers
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var schema = (0, _schemas.generateObjSchema)({
inputComponents: _schemas.arraySchema
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/autocomplete-valid.md',
description: 'Enforce that autocomplete attributes are used correctly.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var options = context.options[0] || {};
var _options$inputCompone = options.inputComponents,
inputComponents = _options$inputCompone === void 0 ? [] : _options$inputCompone;
var inputTypes = ['input'].concat(inputComponents);
var elType = elementType(node);
var autocomplete = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'autocomplete'));
if (typeof autocomplete !== 'string' || !inputTypes.includes(elType)) {
return;
}
var type = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'type'));
var _runVirtualRule = (0, _axeCore.runVirtualRule)('autocomplete-valid', {
nodeName: 'input',
attributes: {
autocomplete,
// Which autocomplete is valid depends on the input type
type: type === null ? undefined : type
}
}),
violations = _runVirtualRule.violations;
if (violations.length === 0) {
return;
}
// Since we only test one rule, with one node, return the message from first (and only) instance of each
context.report({
node,
message: violations[0].nodes[0].all[0].message
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce a clickable non-interactive element has at least 1 keyboard event listener.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Visible, non-interactive elements with click handlers must have at least one keyboard listener.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/click-events-have-key-events.md',
description: 'Enforce a clickable non-interactive element has at least one keyboard event listener.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var props = node.attributes;
if ((0, _jsxAstUtils.getProp)(props, 'onclick') === undefined) {
return;
}
var type = elementType(node);
var requiredProps = ['onkeydown', 'onkeyup', 'onkeypress'];
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
if ((0, _isHiddenFromScreenReader["default"])(type, props) || (0, _isPresentationRole["default"])(type, props)) {
return;
}
if ((0, _isInteractiveElement["default"])(type, props)) {
return;
}
if ((0, _jsxAstUtils.hasAnyProp)(props, requiredProps)) {
return;
}
// Visible, non-interactive elements with click handlers require one keyboard event listener.
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,103 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isDOMElement = _interopRequireDefault(require("../util/isDOMElement"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
var _mayHaveAccessibleLabel = _interopRequireDefault(require("../util/mayHaveAccessibleLabel"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce controls are associated with a text label.
* @author Jesse Beach
*
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'A control must be associated with a text label.';
var ignoreList = ['link'];
var schema = (0, _schemas.generateObjSchema)({
labelAttributes: _schemas.arraySchema,
controlComponents: _schemas.arraySchema,
ignoreElements: _schemas.arraySchema,
ignoreRoles: _schemas.arraySchema,
depth: {
description: 'JSX tree depth limit to check for accessible label',
type: 'integer',
minimum: 0
}
});
var _default = exports["default"] = {
meta: {
docs: {
description: 'Enforce that a control (an interactive element) has a text label.',
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/control-has-associated-label.md'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
var options = context.options[0] || {};
var _options$labelAttribu = options.labelAttributes,
labelAttributes = _options$labelAttribu === void 0 ? [] : _options$labelAttribu,
_options$controlCompo = options.controlComponents,
controlComponents = _options$controlCompo === void 0 ? [] : _options$controlCompo,
_options$ignoreElemen = options.ignoreElements,
ignoreElements = _options$ignoreElemen === void 0 ? [] : _options$ignoreElemen,
_options$ignoreRoles = options.ignoreRoles,
ignoreRoles = _options$ignoreRoles === void 0 ? [] : _options$ignoreRoles;
var newIgnoreElements = new Set([].concat(ignoreElements, ignoreList));
var rule = function rule(node) {
var tag = elementType(node.openingElement);
var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.openingElement.attributes, 'role'));
// Ignore interactive elements that might get their label from a source
// that cannot be discerned from static analysis, like
// <label><input />Save</label>
if (newIgnoreElements.has(tag)) {
return;
}
// Ignore roles that are "interactive" but should not require a label.
if ((0, _arrayIncludes["default"])(ignoreRoles, role)) {
return;
}
var props = node.openingElement.attributes;
var nodeIsDOMElement = (0, _isDOMElement["default"])(tag);
var nodeIsHiddenFromScreenReader = (0, _isHiddenFromScreenReader["default"])(tag, props);
var nodeIsInteractiveElement = (0, _isInteractiveElement["default"])(tag, props);
var nodeIsInteractiveRole = (0, _isInteractiveRole["default"])(tag, props);
var nodeIsControlComponent = controlComponents.indexOf(tag) > -1;
if (nodeIsHiddenFromScreenReader) {
return;
}
var hasAccessibleLabel = true;
if (nodeIsInteractiveElement || nodeIsDOMElement && nodeIsInteractiveRole || nodeIsControlComponent) {
// Prevent crazy recursion.
var recursionDepth = Math.min(options.depth === undefined ? 2 : options.depth, 25);
hasAccessibleLabel = (0, _mayHaveAccessibleLabel["default"])(node, recursionDepth, labelAttributes, elementType, controlComponents);
}
if (!hasAccessibleLabel) {
context.report({
node: node.openingElement,
message: errorMessage
});
}
};
// Create visitor selectors.
return {
JSXElement: rule
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _hasAccessibleChild = _interopRequireDefault(require("../util/hasAccessibleChild"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce heading (h1, h2, etc) elements contain accessible content.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Headings must have content and the content must be accessible by a screen reader.';
var headings = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
var schema = (0, _schemas.generateObjSchema)({
components: _schemas.arraySchema
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/heading-has-content.md',
description: 'Enforce heading (`h1`, `h2`, etc) elements contain accessible content.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var options = context.options[0] || {};
var componentOptions = options.components || [];
var typeCheck = headings.concat(componentOptions);
var nodeType = elementType(node);
// Only check 'h*' elements and custom types.
if (typeCheck.indexOf(nodeType) === -1) {
return;
}
if ((0, _hasAccessibleChild["default"])(node.parent, elementType)) {
return;
}
if ((0, _isHiddenFromScreenReader["default"])(nodeType, node.attributes)) {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce html element has lang prop.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = '<html> elements must have the lang prop.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
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: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var type = elementType(node);
if (type && type !== 'html') {
return;
}
var lang = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'lang'));
if (lang) {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,50 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _schemas = require("../util/schemas");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce iframe elements have a title attribute.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = '<iframe> elements must have a unique title property.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/iframe-has-title.md',
description: 'Enforce iframe elements have a title attribute.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var type = elementType(node);
if (type && type !== 'iframe') {
return;
}
var title = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'title'));
if (title && typeof title === 'string') {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,88 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _stringPrototype = _interopRequireDefault(require("string.prototype.includes"));
var _safeRegexTest = _interopRequireDefault(require("safe-regex-test"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce img alt attribute does not have the word image, picture, or photo.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var REDUNDANT_WORDS = ['image', 'photo', 'picture'];
var errorMessage = 'Redundant alt attribute. Screen-readers already announce `img` tags as an image. You dont need to use the words `image`, `photo,` or `picture` (or any specified custom words) in the alt prop.';
var schema = (0, _schemas.generateObjSchema)({
components: _schemas.arraySchema,
words: _schemas.arraySchema
});
var isASCII = (0, _safeRegexTest["default"])(/[\x20-\x7F]+/);
function containsRedundantWord(value, redundantWords) {
var lowercaseRedundantWords = redundantWords.map(function (redundantWord) {
return redundantWord.toLowerCase();
});
if (isASCII(value)) {
return value.split(/\s+/).some(function (valueWord) {
return (0, _arrayIncludes["default"])(lowercaseRedundantWords, valueWord.toLowerCase());
});
}
return lowercaseRedundantWords.some(function (redundantWord) {
return (0, _stringPrototype["default"])(value.toLowerCase(), redundantWord);
});
}
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/img-redundant-alt.md',
description: 'Enforce `<img>` alt prop does not contain the word "image", "picture", or "photo".'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var options = context.options[0] || {};
var componentOptions = options.components || [];
var typesToValidate = ['img'].concat(componentOptions);
var nodeType = elementType(node);
// Only check 'label' elements and custom types.
if (typesToValidate.indexOf(nodeType) === -1) {
return;
}
var altProp = (0, _jsxAstUtils.getProp)(node.attributes, 'alt');
// Return if alt prop is not present.
if (altProp === undefined) {
return;
}
var value = (0, _jsxAstUtils.getLiteralPropValue)(altProp);
var isVisible = (0, _isHiddenFromScreenReader["default"])(nodeType, node.attributes) === false;
var _options$words = options.words,
words = _options$words === void 0 ? [] : _options$words;
var redundantWords = REDUNDANT_WORDS.concat(words);
if (typeof value === 'string' && isVisible) {
var hasRedundancy = containsRedundantWord(value, redundantWords);
if (hasRedundancy === true) {
context.report({
node,
message: errorMessage
});
}
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,92 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isDisabledElement = _interopRequireDefault(require("../util/isDisabledElement"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
var _isNonInteractiveElement = _interopRequireDefault(require("../util/isNonInteractiveElement"));
var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
var _getTabIndex = _interopRequireDefault(require("../util/getTabIndex"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
* @fileoverview Enforce that elements with onClick handlers must be tabbable.
* @author Ethan Cohen
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var schema = (0, _schemas.generateObjSchema)({
// TODO: convert to use iterFilter and iterFrom
tabbable: (0, _schemas.enumArraySchema)(_toConsumableArray(_ariaQuery.roles.keys()).filter(function (name) {
return !_ariaQuery.roles.get(name)["abstract"] && _ariaQuery.roles.get(name).superClass.some(function (klasses) {
return (0, _arrayIncludes["default"])(klasses, 'widget');
});
}))
});
var interactiveProps = [].concat(_jsxAstUtils.eventHandlersByType.mouse, _jsxAstUtils.eventHandlersByType.keyboard);
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/interactive-supports-focus.md',
description: 'Enforce that elements with interactive handlers like `onClick` must be focusable.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var tabbable = context.options && context.options[0] && context.options[0].tabbable || [];
var attributes = node.attributes;
var type = elementType(node);
var hasInteractiveProps = (0, _jsxAstUtils.hasAnyProp)(attributes, interactiveProps);
var hasTabindex = (0, _getTabIndex["default"])((0, _jsxAstUtils.getProp)(attributes, 'tabIndex')) !== undefined;
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
if (!hasInteractiveProps || (0, _isDisabledElement["default"])(attributes) || (0, _isHiddenFromScreenReader["default"])(type, attributes) || (0, _isPresentationRole["default"])(type, attributes)) {
// Presentation is an intentional signal from the author that this
// element is not meant to be perceivable. For example, a click screen
// to close a dialog .
return;
}
if (hasInteractiveProps && (0, _isInteractiveRole["default"])(type, attributes) && !(0, _isInteractiveElement["default"])(type, attributes) && !(0, _isNonInteractiveElement["default"])(type, attributes) && !(0, _isNonInteractiveRole["default"])(type, attributes) && !hasTabindex) {
var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
if ((0, _arrayIncludes["default"])(tabbable, role)) {
// Always tabbable, tabIndex = 0
context.report({
node,
message: "Elements with the '".concat(role, "' interactive role must be tabbable.")
});
} else {
// Focusable, tabIndex = -1 or 0
context.report({
node,
message: "Elements with the '".concat(role, "' interactive role must be focusable.")
});
}
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,127 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _mayContainChildComponent = _interopRequireDefault(require("../util/mayContainChildComponent"));
var _mayHaveAccessibleLabel = _interopRequireDefault(require("../util/mayHaveAccessibleLabel"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce label tags have an associated control.
* @author Jesse Beach
*
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'A form label must be associated with a control.';
var errorMessageNoLabel = 'A form label must have accessible text.';
var schema = (0, _schemas.generateObjSchema)({
labelComponents: _schemas.arraySchema,
labelAttributes: _schemas.arraySchema,
controlComponents: _schemas.arraySchema,
assert: {
description: 'Assert that the label has htmlFor, a nested label, both or either',
type: 'string',
"enum": ['htmlFor', 'nesting', 'both', 'either']
},
depth: {
description: 'JSX tree depth limit to check for accessible label',
type: 'integer',
minimum: 0
}
});
function validateID(node, context) {
var _settings$jsxA11y$at, _settings$jsxA11y, _settings$jsxA11y$att;
var settings = context.settings;
var htmlForAttributes = (_settings$jsxA11y$at = (_settings$jsxA11y = settings['jsx-a11y']) === null || _settings$jsxA11y === void 0 ? void 0 : (_settings$jsxA11y$att = _settings$jsxA11y.attributes) === null || _settings$jsxA11y$att === void 0 ? void 0 : _settings$jsxA11y$att["for"]) !== null && _settings$jsxA11y$at !== void 0 ? _settings$jsxA11y$at : ['htmlFor'];
for (var i = 0; i < htmlForAttributes.length; i += 1) {
var attribute = htmlForAttributes[i];
if ((0, _jsxAstUtils.hasProp)(node.attributes, attribute)) {
var htmlForAttr = (0, _jsxAstUtils.getProp)(node.attributes, attribute);
var htmlForValue = (0, _jsxAstUtils.getPropValue)(htmlForAttr);
return htmlForAttr !== false && !!htmlForValue;
}
}
return false;
}
var _default = exports["default"] = {
meta: {
docs: {
description: 'Enforce that a `label` tag has a text label and an associated control.',
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/main/docs/rules/label-has-associated-control.md'
},
schema: [schema]
},
create: function create(context) {
var options = context.options[0] || {};
var labelComponents = options.labelComponents || [];
var assertType = options.assert || 'either';
var componentNames = ['label'].concat(labelComponents);
var elementType = (0, _getElementType["default"])(context);
var rule = function rule(node) {
if (componentNames.indexOf(elementType(node.openingElement)) === -1) {
return;
}
var controlComponents = ['input', 'meter', 'output', 'progress', 'select', 'textarea'].concat(options.controlComponents || []);
// Prevent crazy recursion.
var recursionDepth = Math.min(options.depth === undefined ? 2 : options.depth, 25);
var hasLabelId = validateID(node.openingElement, context);
// Check for multiple control components.
var hasNestedControl = controlComponents.some(function (name) {
return (0, _mayContainChildComponent["default"])(node, name, recursionDepth, elementType);
});
var hasAccessibleLabel = (0, _mayHaveAccessibleLabel["default"])(node, recursionDepth, options.labelAttributes, elementType, controlComponents);
if (!hasAccessibleLabel) {
context.report({
node: node.openingElement,
message: errorMessageNoLabel
});
return;
}
switch (assertType) {
case 'htmlFor':
if (hasLabelId) {
return;
}
break;
case 'nesting':
if (hasNestedControl) {
return;
}
break;
case 'both':
if (hasLabelId && hasNestedControl) {
return;
}
break;
case 'either':
if (hasLabelId || hasNestedControl) {
return;
}
break;
default:
break;
}
// htmlFor case
context.report({
node: node.openingElement,
message: errorMessage
});
};
// Create visitor selectors.
return {
JSXElement: rule
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,150 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _hasAccessibleChild = _interopRequireDefault(require("../util/hasAccessibleChild"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce label tags have htmlFor attribute.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var enumValues = ['nesting', 'id'];
var schema = {
type: 'object',
properties: {
components: _schemas.arraySchema,
required: {
oneOf: [{
type: 'string',
"enum": enumValues
}, (0, _schemas.generateObjSchema)({
some: (0, _schemas.enumArraySchema)(enumValues)
}, ['some']), (0, _schemas.generateObjSchema)({
every: (0, _schemas.enumArraySchema)(enumValues)
}, ['every'])]
},
allowChildren: {
type: 'boolean'
}
}
};
// Breadth-first search, assuming that HTML for forms is shallow.
function validateNesting(node) {
var queue = node.parent.children.slice();
var child;
var opener;
while (queue.length) {
child = queue.shift();
opener = child.openingElement;
if (child.type === 'JSXElement' && opener && (opener.name.name === 'input' || opener.name.name === 'textarea' || opener.name.name === 'select')) {
return true;
}
if (child.children) {
queue = queue.concat(child.children);
}
}
return false;
}
function validateID(_ref, context) {
var _settings$jsxA11y$at, _settings$jsxA11y, _settings$jsxA11y$att;
var attributes = _ref.attributes;
var settings = context.settings;
var htmlForAttributes = (_settings$jsxA11y$at = (_settings$jsxA11y = settings['jsx-a11y']) === null || _settings$jsxA11y === void 0 ? void 0 : (_settings$jsxA11y$att = _settings$jsxA11y.attributes) === null || _settings$jsxA11y$att === void 0 ? void 0 : _settings$jsxA11y$att["for"]) !== null && _settings$jsxA11y$at !== void 0 ? _settings$jsxA11y$at : ['htmlFor'];
for (var i = 0; i < htmlForAttributes.length; i += 1) {
var attribute = htmlForAttributes[i];
if ((0, _jsxAstUtils.hasProp)(attributes, attribute)) {
var htmlForAttr = (0, _jsxAstUtils.getProp)(attributes, attribute);
var htmlForValue = (0, _jsxAstUtils.getPropValue)(htmlForAttr);
return htmlForAttr !== false && !!htmlForValue;
}
}
return false;
}
function validate(node, required, allowChildren, elementType, context) {
if (allowChildren === true) {
return (0, _hasAccessibleChild["default"])(node.parent, elementType);
}
if (required === 'nesting') {
return validateNesting(node);
}
return validateID(node, context);
}
function getValidityStatus(node, required, allowChildren, elementType, context) {
if (Array.isArray(required.some)) {
var _isValid = required.some.some(function (rule) {
return validate(node, rule, allowChildren, elementType, context);
});
var _message = !_isValid ? "Form label must have ANY of the following types of associated control: ".concat(required.some.join(', ')) : null;
return {
isValid: _isValid,
message: _message
};
}
if (Array.isArray(required.every)) {
var _isValid2 = required.every.every(function (rule) {
return validate(node, rule, allowChildren, elementType, context);
});
var _message2 = !_isValid2 ? "Form label must have ALL of the following types of associated control: ".concat(required.every.join(', ')) : null;
return {
isValid: _isValid2,
message: _message2
};
}
var isValid = validate(node, required, allowChildren, elementType, context);
var message = !isValid ? "Form label must have the following type of associated control: ".concat(required) : null;
return {
isValid,
message
};
}
var _default = exports["default"] = {
meta: {
deprecated: true,
replacedBy: ['label-has-associated-control'],
docs: {
description: 'Enforce that `<label>` elements have the `htmlFor` prop.',
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/label-has-for.md'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement(node) {
var options = context.options[0] || {};
var componentOptions = options.components || [];
var typesToValidate = ['label'].concat(componentOptions);
var nodeType = elementType(node);
// Only check 'label' elements and custom types.
if (typesToValidate.indexOf(nodeType) === -1) {
return;
}
var required = options.required || {
every: ['nesting', 'id']
};
var allowChildren = options.allowChildren || false;
var _getValidityStatus = getValidityStatus(node, required, allowChildren, elementType, context),
isValid = _getValidityStatus.isValid,
message = _getValidityStatus.message;
if (!isValid) {
context.report({
node,
message
});
}
}
};
}
};
module.exports = exports.default;

68
node_modules/eslint-plugin-jsx-a11y/lib/rules/lang.js generated vendored Normal file
View File

@@ -0,0 +1,68 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _languageTags = _interopRequireDefault(require("language-tags"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce lang attribute has a valid value.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'lang attribute must have a valid value.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/lang.md',
description: 'Enforce lang attribute has a valid value.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(node) {
var name = (0, _jsxAstUtils.propName)(node);
if (name && name.toUpperCase() !== 'LANG') {
return;
}
var parent = node.parent;
var type = elementType(parent);
if (type && type !== 'html') {
return;
}
var value = (0, _jsxAstUtils.getLiteralPropValue)(node);
// Don't check identifiers
if (value === null) {
return;
}
if (value === undefined) {
context.report({
node,
message: errorMessage
});
return;
}
if (_languageTags["default"].check(value)) {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,96 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview <audio> and <video> elements must have a <track> for captions.
* @author Ethan Cohen
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Media elements such as <audio> and <video> must have a <track> for captions.';
var MEDIA_TYPES = ['audio', 'video'];
var schema = (0, _schemas.generateObjSchema)({
audio: _schemas.arraySchema,
video: _schemas.arraySchema,
track: _schemas.arraySchema
});
var isMediaType = function isMediaType(context, type) {
var options = context.options[0] || {};
return MEDIA_TYPES.concat((0, _arrayPrototype["default"])(MEDIA_TYPES, function (mediaType) {
return options[mediaType];
})).some(function (typeToCheck) {
return typeToCheck === type;
});
};
var isTrackType = function isTrackType(context, type) {
var options = context.options[0] || {};
return ['track'].concat(options.track || []).some(function (typeToCheck) {
return typeToCheck === type;
});
};
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/media-has-caption.md',
description: 'Enforces that `<audio>` and `<video>` elements must have a `<track>` for captions.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXElement: function JSXElement(node) {
var element = node.openingElement;
var type = elementType(element);
if (!isMediaType(context, type)) {
return;
}
var mutedProp = (0, _jsxAstUtils.getProp)(element.attributes, 'muted');
var mutedPropVal = (0, _jsxAstUtils.getLiteralPropValue)(mutedProp);
if (mutedPropVal === true) {
return;
}
// $FlowFixMe https://github.com/facebook/flow/issues/1414
var trackChildren = node.children.filter(function (child) {
if (child.type !== 'JSXElement') {
return false;
}
// $FlowFixMe https://github.com/facebook/flow/issues/1414
return isTrackType(context, elementType(child.openingElement));
});
if (trackChildren.length === 0) {
context.report({
node: element,
message: errorMessage
});
return;
}
var hasCaption = trackChildren.some(function (track) {
var kindProp = (0, _jsxAstUtils.getProp)(track.openingElement.attributes, 'kind');
var kindPropValue = (0, _jsxAstUtils.getLiteralPropValue)(kindProp) || '';
return kindPropValue.toLowerCase() === 'captions';
});
if (!hasCaption) {
context.report({
node: element,
message: errorMessage
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
* @fileoverview Enforce onmouseover/onmouseout are
* accompanied by onfocus/onblur.
* @author Ethan Cohen
*
*/ // ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var schema = (0, _schemas.generateObjSchema)({
hoverInHandlers: _objectSpread(_objectSpread({}, _schemas.arraySchema), {}, {
description: 'An array of events that need to be accompanied by `onFocus`'
}),
hoverOutHandlers: _objectSpread(_objectSpread({}, _schemas.arraySchema), {}, {
description: 'An array of events that need to be accompanied by `onBlur`'
})
});
// Use `onMouseOver` and `onMouseOut` by default if no config is
// passed in for backwards compatibility
var DEFAULT_HOVER_IN_HANDLERS = ['onMouseOver'];
var DEFAULT_HOVER_OUT_HANDLERS = ['onMouseOut'];
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/mouse-events-have-key-events.md',
description: 'Enforce that `onMouseOver`/`onMouseOut` are accompanied by `onFocus`/`onBlur` for keyboard-only users.'
},
schema: [schema]
},
create: function create(context) {
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var _options$0$hoverInHan, _options$, _options$0$hoverOutHa, _options$2;
var name = node.name.name;
if (!_ariaQuery.dom.get(name)) {
return;
}
var options = context.options;
var hoverInHandlers = (_options$0$hoverInHan = (_options$ = options[0]) === null || _options$ === void 0 ? void 0 : _options$.hoverInHandlers) !== null && _options$0$hoverInHan !== void 0 ? _options$0$hoverInHan : DEFAULT_HOVER_IN_HANDLERS;
var hoverOutHandlers = (_options$0$hoverOutHa = (_options$2 = options[0]) === null || _options$2 === void 0 ? void 0 : _options$2.hoverOutHandlers) !== null && _options$0$hoverOutHa !== void 0 ? _options$0$hoverOutHa : DEFAULT_HOVER_OUT_HANDLERS;
var attributes = node.attributes;
// Check hover in / onfocus pairing
var firstHoverInHandlerWithValue = hoverInHandlers.find(function (handler) {
var prop = (0, _jsxAstUtils.getProp)(attributes, handler);
var propValue = (0, _jsxAstUtils.getPropValue)(prop);
return propValue != null;
});
if (firstHoverInHandlerWithValue != null) {
var hasOnFocus = (0, _jsxAstUtils.getProp)(attributes, 'onFocus');
var onFocusValue = (0, _jsxAstUtils.getPropValue)(hasOnFocus);
if (hasOnFocus === false || onFocusValue === null || onFocusValue === undefined) {
context.report({
node: (0, _jsxAstUtils.getProp)(attributes, firstHoverInHandlerWithValue),
message: "".concat(firstHoverInHandlerWithValue, " must be accompanied by onFocus for accessibility.")
});
}
}
// Check hover out / onblur pairing
var firstHoverOutHandlerWithValue = hoverOutHandlers.find(function (handler) {
var prop = (0, _jsxAstUtils.getProp)(attributes, handler);
var propValue = (0, _jsxAstUtils.getPropValue)(prop);
return propValue != null;
});
if (firstHoverOutHandlerWithValue != null) {
var hasOnBlur = (0, _jsxAstUtils.getProp)(attributes, 'onBlur');
var onBlurValue = (0, _jsxAstUtils.getPropValue)(hasOnBlur);
if (hasOnBlur === false || onBlurValue === null || onBlurValue === undefined) {
context.report({
node: (0, _jsxAstUtils.getProp)(attributes, firstHoverOutHandlerWithValue),
message: "".concat(firstHoverOutHandlerWithValue, " must be accompanied by onBlur for accessibility.")
});
}
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
/**
* @fileoverview Enforce no accesskey attribute on element.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'No access key attribute allowed. Inconsistencies between keyboard shortcuts and keyboard commands used by screenreaders and keyboard-only users create a11y complications.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-access-key.md',
description: 'Enforce that the `accessKey` prop is not used on any element to avoid complications with keyboard commands used by a screenreader.'
},
schema: [schema]
},
create: function create(context) {
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var accessKey = (0, _jsxAstUtils.getProp)(node.attributes, 'accesskey');
var accessKeyValue = (0, _jsxAstUtils.getPropValue)(accessKey);
if (accessKey && accessKeyValue) {
context.report({
node,
message: errorMessage
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isFocusable = _interopRequireDefault(require("../util/isFocusable"));
var _schemas = require("../util/schemas");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce aria-hidden is not used on interactive elements or contain interactive elements.
* @author Kate Higa
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-aria-hidden-on-focusable.md',
description: 'Disallow `aria-hidden="true"` from being set on focusable elements.'
},
schema: [schema]
},
create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement(node) {
var attributes = node.attributes;
var type = elementType(node);
var isAriaHidden = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(attributes, 'aria-hidden')) === true;
if (isAriaHidden && (0, _isFocusable["default"])(type, attributes)) {
context.report({
node,
message: 'aria-hidden="true" must not be set on focusable elements.'
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,62 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _ariaQuery = require("aria-query");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce autoFocus prop is not used.
* @author Ethan Cohen <@evcohen>
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'The autoFocus prop should not be used, as it can reduce usability and accessibility for users.';
var schema = (0, _schemas.generateObjSchema)({
ignoreNonDOM: {
type: 'boolean',
"default": false
}
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-autofocus.md',
description: 'Enforce autoFocus prop is not used.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(attribute) {
// Determine if ignoreNonDOM is set to true
// If true, then do not run rule.
var options = context.options[0] || {};
var ignoreNonDOM = !!options.ignoreNonDOM;
if (ignoreNonDOM) {
var type = elementType(attribute.parent);
if (!_ariaQuery.dom.get(type)) {
return;
}
}
// Don't normalize, since React only recognizes autoFocus on low-level DOM elements.
if ((0, _jsxAstUtils.propName)(attribute) === 'autoFocus') {
context.report({
node: attribute,
message: errorMessage
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce distracting elements are not used.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = function errorMessage(element) {
return "Do not use <".concat(element, "> elements as they can create visual accessibility issues and are deprecated.");
};
var DEFAULT_ELEMENTS = ['marquee', 'blink'];
var schema = (0, _schemas.generateObjSchema)({
elements: (0, _schemas.enumArraySchema)(DEFAULT_ELEMENTS)
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-distracting-elements.md',
description: 'Enforce distracting elements are not used.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var options = context.options[0] || {};
var elementOptions = options.elements || DEFAULT_ELEMENTS;
var type = elementType(node);
var distractingElement = elementOptions.find(function (element) {
return type === element;
});
if (distractingElement) {
context.report({
node,
message: errorMessage(distractingElement)
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,81 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _hasown = _interopRequireDefault(require("hasown"));
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Disallow inherently interactive elements to be assigned
* non-interactive roles.
* @author Jesse Beach
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Interactive elements should not be assigned non-interactive roles.';
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-interactive-element-to-noninteractive-role.md',
description: 'Interactive elements should not be assigned non-interactive roles.'
},
schema: [{
type: 'object',
additionalProperties: {
type: 'array',
items: {
type: 'string'
},
uniqueItems: true
}
}]
},
create: function create(context) {
var options = context.options;
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(attribute) {
var attributeName = (0, _jsxAstUtils.propName)(attribute);
// $FlowFixMe: [TODO] Mark propName as a JSXIdentifier, not a string.
if (attributeName !== 'role') {
return;
}
var node = attribute.parent;
var attributes = node.attributes;
var type = elementType(node);
var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'role'));
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
// Allow overrides from rule configuration for specific elements and
// roles.
var allowedRoles = options[0] || {};
if ((0, _hasown["default"])(allowedRoles, type) && (0, _arrayIncludes["default"])(allowedRoles[type], role)) {
return;
}
if ((0, _isInteractiveElement["default"])(type, attributes) && ((0, _isNonInteractiveRole["default"])(type, attributes) || (0, _isPresentationRole["default"])(type, attributes))) {
// Visible, non-interactive elements should not have an interactive handler.
context.report({
node: attribute,
message: errorMessage
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,95 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _hasown = _interopRequireDefault(require("hasown"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isAbstractRole = _interopRequireDefault(require("../util/isAbstractRole"));
var _isContentEditable = _interopRequireDefault(require("../util/isContentEditable"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
var _isNonInteractiveElement = _interopRequireDefault(require("../util/isNonInteractiveElement"));
var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce non-interactive elements have no interactive handlers.
* @author Jese Beach
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Non-interactive elements should not be assigned mouse or keyboard event listeners.';
var defaultInteractiveProps = [].concat(_jsxAstUtils.eventHandlersByType.focus, _jsxAstUtils.eventHandlersByType.image, _jsxAstUtils.eventHandlersByType.keyboard, _jsxAstUtils.eventHandlersByType.mouse);
var schema = (0, _schemas.generateObjSchema)({
handlers: _schemas.arraySchema
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-noninteractive-element-interactions.md',
description: 'Non-interactive elements should not be assigned mouse or keyboard event listeners.'
},
schema: [schema]
},
create: function create(context) {
var options = context.options;
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function (_JSXOpeningElement) {
function JSXOpeningElement(_x) {
return _JSXOpeningElement.apply(this, arguments);
}
JSXOpeningElement.toString = function () {
return _JSXOpeningElement.toString();
};
return JSXOpeningElement;
}(function (node) {
var attributes = node.attributes;
var type = elementType(node);
var config = options[0] || {};
var interactiveProps = config.handlers || defaultInteractiveProps;
// Allow overrides from rule configuration for specific elements and roles.
if ((0, _hasown["default"])(config, type)) {
attributes = attributes.filter(function (attr) {
return attr.type !== 'JSXSpreadAttribute' && !(0, _arrayIncludes["default"])(config[type], (0, _jsxAstUtils.propName)(attr));
});
}
var hasInteractiveProps = interactiveProps.some(function (prop) {
return (0, _jsxAstUtils.hasProp)(attributes, prop) && (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(attributes, prop)) != null;
});
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
if (!hasInteractiveProps || (0, _isContentEditable["default"])(type, attributes) || (0, _isHiddenFromScreenReader["default"])(type, attributes) || (0, _isPresentationRole["default"])(type, attributes)) {
// Presentation is an intentional signal from the author that this
// element is not meant to be perceivable. For example, a click screen
// to close a dialog .
return;
}
if ((0, _isInteractiveElement["default"])(type, attributes) || (0, _isInteractiveRole["default"])(type, attributes) || !(0, _isNonInteractiveElement["default"])(type, attributes) && !(0, _isNonInteractiveRole["default"])(type, attributes) || (0, _isAbstractRole["default"])(type, attributes)) {
// This rule has no opinion about abtract roles.
return;
}
// Visible, non-interactive elements should not have an interactive handler.
context.report({
node,
message: errorMessage
});
})
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _hasown = _interopRequireDefault(require("hasown"));
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _getExplicitRole = _interopRequireDefault(require("../util/getExplicitRole"));
var _isNonInteractiveElement = _interopRequireDefault(require("../util/isNonInteractiveElement"));
var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Disallow inherently non-interactive elements to be assigned
* interactive roles.
* @author Jesse Beach
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Non-interactive elements should not be assigned interactive roles.';
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-noninteractive-element-to-interactive-role.md',
description: 'Non-interactive elements should not be assigned interactive roles.'
},
schema: [{
type: 'object',
additionalProperties: {
type: 'array',
items: {
type: 'string'
},
uniqueItems: true
}
}]
},
create: function create(context) {
var options = context.options;
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(attribute) {
var attributeName = (0, _jsxAstUtils.propName)(attribute);
// $FlowFixMe: [TODO] Mark propName as a JSXIdentifier, not a string.
if (attributeName !== 'role') {
return;
}
var node = attribute.parent;
var attributes = node.attributes;
var type = elementType(node);
var role = (0, _getExplicitRole["default"])(type, node.attributes);
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
// Allow overrides from rule configuration for specific elements and
// roles.
var allowedRoles = options[0] || {};
if ((0, _hasown["default"])(allowedRoles, type) && (0, _arrayIncludes["default"])(allowedRoles[type], role)) {
return;
}
if ((0, _isNonInteractiveElement["default"])(type, attributes) && (0, _isInteractiveRole["default"])(type, attributes)) {
context.report({
node: attribute,
message: errorMessage
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,108 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
var _isNonLiteralProperty = _interopRequireDefault(require("../util/isNonLiteralProperty"));
var _schemas = require("../util/schemas");
var _getTabIndex = _interopRequireDefault(require("../util/getTabIndex"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /**
* @fileoverview Disallow tabindex on static and noninteractive elements
* @author jessebeach
*
*/ // ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = '`tabIndex` should only be declared on interactive elements.';
var schema = (0, _schemas.generateObjSchema)({
roles: _objectSpread(_objectSpread({}, _schemas.arraySchema), {}, {
description: 'An array of ARIA roles'
}),
tags: _objectSpread(_objectSpread({}, _schemas.arraySchema), {}, {
description: 'An array of HTML tag names'
})
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-noninteractive-tabindex.md',
description: '`tabIndex` should only be declared on interactive elements.'
},
schema: [schema]
},
create: function create(context) {
var options = context.options;
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function (_JSXOpeningElement) {
function JSXOpeningElement(_x) {
return _JSXOpeningElement.apply(this, arguments);
}
JSXOpeningElement.toString = function () {
return _JSXOpeningElement.toString();
};
return JSXOpeningElement;
}(function (node) {
var type = elementType(node);
var attributes = node.attributes;
var tabIndexProp = (0, _jsxAstUtils.getProp)(attributes, 'tabIndex');
var tabIndex = (0, _getTabIndex["default"])(tabIndexProp);
// Early return;
if (typeof tabIndex === 'undefined') {
return;
}
var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, 'role'));
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
// Allow for configuration overrides.
var _ref = options[0] || {},
tags = _ref.tags,
roles = _ref.roles,
allowExpressionValues = _ref.allowExpressionValues;
if (tags && (0, _arrayIncludes["default"])(tags, type)) {
return;
}
if (roles && (0, _arrayIncludes["default"])(roles, role)) {
return;
}
if (allowExpressionValues === true && (0, _isNonLiteralProperty["default"])(attributes, 'role')) {
// Special case if role is assigned using ternary with literals on both side
var roleProp = (0, _jsxAstUtils.getProp)(attributes, 'role');
if (roleProp && roleProp.type === 'JSXAttribute' && roleProp.value.type === 'JSXExpressionContainer') {
if (roleProp.value.expression.type === 'ConditionalExpression') {
if (roleProp.value.expression.consequent.type === 'Literal' && roleProp.value.expression.alternate.type === 'Literal') {
return;
}
}
}
return;
}
if ((0, _isInteractiveElement["default"])(type, attributes) || (0, _isInteractiveRole["default"])(type, attributes)) {
return;
}
if (tabIndex >= 0) {
context.report({
node: tabIndexProp,
message: errorMessage
});
}
})
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,52 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce usage of onBlur over onChange for accessibility.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'onBlur must be used instead of onchange, unless absolutely necessary and it causes no negative consequences for keyboard only or screen reader users.';
var applicableTypes = ['select', 'option'];
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-onchange.md',
description: 'Enforce usage of `onBlur` over `onChange` on select menus for accessibility.'
},
deprecated: true,
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var nodeType = elementType(node);
if (applicableTypes.indexOf(nodeType) === -1) {
return;
}
var onChange = (0, _jsxAstUtils.getProp)(node.attributes, 'onChange');
var hasOnBlur = (0, _jsxAstUtils.getProp)(node.attributes, 'onBlur') !== undefined;
if (onChange && !hasOnBlur) {
context.report({
node,
message: errorMessage
});
}
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,86 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _hasown = _interopRequireDefault(require("hasown"));
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _getExplicitRole = _interopRequireDefault(require("../util/getExplicitRole"));
var _getImplicitRole = _interopRequireDefault(require("../util/getImplicitRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce explicit role property is not the
* same as implicit/default role property on element.
* @author Ethan Cohen <@evcohen>
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = function errorMessage(element, implicitRole) {
return "The element ".concat(element, " has an implicit role of ").concat(implicitRole, ". Defining this explicitly is redundant and should be avoided.");
};
var DEFAULT_ROLE_EXCEPTIONS = {
nav: ['navigation']
};
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-redundant-roles.md',
description: 'Enforce explicit role property is not the same as implicit/default role property on element.'
},
schema: [{
type: 'object',
additionalProperties: {
type: 'array',
items: {
type: 'string'
},
uniqueItems: true
}
}]
},
create: function create(context) {
var options = context.options;
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function (_JSXOpeningElement) {
function JSXOpeningElement(_x) {
return _JSXOpeningElement.apply(this, arguments);
}
JSXOpeningElement.toString = function () {
return _JSXOpeningElement.toString();
};
return JSXOpeningElement;
}(function (node) {
var type = elementType(node);
var implicitRole = (0, _getImplicitRole["default"])(type, node.attributes);
var explicitRole = (0, _getExplicitRole["default"])(type, node.attributes);
if (!implicitRole || !explicitRole) {
return;
}
if (implicitRole === explicitRole) {
var allowedRedundantRoles = options[0] || {};
var redundantRolesForElement;
if ((0, _hasown["default"])(allowedRedundantRoles, type)) {
redundantRolesForElement = allowedRedundantRoles[type];
} else {
redundantRolesForElement = DEFAULT_ROLE_EXCEPTIONS[type] || [];
}
if ((0, _arrayIncludes["default"])(redundantRolesForElement, implicitRole)) {
return;
}
context.report({
node,
message: errorMessage(type, implicitRole.toLowerCase())
});
}
})
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,102 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isAbstractRole = _interopRequireDefault(require("../util/isAbstractRole"));
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isInteractiveRole = _interopRequireDefault(require("../util/isInteractiveRole"));
var _isNonInteractiveElement = _interopRequireDefault(require("../util/isNonInteractiveElement"));
var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
var _isNonLiteralProperty = _interopRequireDefault(require("../util/isNonLiteralProperty"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce static elements have no interactive handlers.
* @author Ethan Cohen
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Avoid non-native interactive elements. If using native HTML is not possible, add an appropriate role and support for tabbing, mouse, keyboard, and touch inputs to an interactive content element.';
var defaultInteractiveProps = [].concat(_jsxAstUtils.eventHandlersByType.focus, _jsxAstUtils.eventHandlersByType.keyboard, _jsxAstUtils.eventHandlersByType.mouse);
var schema = (0, _schemas.generateObjSchema)({
handlers: _schemas.arraySchema
});
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/no-static-element-interactions.md',
description: 'Enforce that non-interactive, visible elements (such as `<div>`) that have click handlers use the role attribute.'
},
schema: [schema]
},
create: function create(context) {
var options = context.options;
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function (_JSXOpeningElement) {
function JSXOpeningElement(_x) {
return _JSXOpeningElement.apply(this, arguments);
}
JSXOpeningElement.toString = function () {
return _JSXOpeningElement.toString();
};
return JSXOpeningElement;
}(function (node) {
var attributes = node.attributes;
var type = elementType(node);
var _ref = options[0] || {},
allowExpressionValues = _ref.allowExpressionValues,
_ref$handlers = _ref.handlers,
handlers = _ref$handlers === void 0 ? defaultInteractiveProps : _ref$handlers;
var hasInteractiveProps = handlers.some(function (prop) {
return (0, _jsxAstUtils.hasProp)(attributes, prop) && (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(attributes, prop)) != null;
});
if (!_ariaQuery.dom.has(type)) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
return;
}
if (!hasInteractiveProps || (0, _isHiddenFromScreenReader["default"])(type, attributes) || (0, _isPresentationRole["default"])(type, attributes)) {
// Presentation is an intentional signal from the author that this
// element is not meant to be perceivable. For example, a click screen
// to close a dialog .
return;
}
if ((0, _isInteractiveElement["default"])(type, attributes) || (0, _isInteractiveRole["default"])(type, attributes) || (0, _isNonInteractiveElement["default"])(type, attributes) || (0, _isNonInteractiveRole["default"])(type, attributes) || (0, _isAbstractRole["default"])(type, attributes)) {
// This rule has no opinion about abstract roles.
return;
}
if (allowExpressionValues === true && (0, _isNonLiteralProperty["default"])(attributes, 'role')) {
// Special case if role is assigned using ternary with literals on both side
var roleProp = (0, _jsxAstUtils.getProp)(attributes, 'role');
if (roleProp && roleProp.type === 'JSXAttribute' && roleProp.value.type === 'JSXExpressionContainer') {
if (roleProp.value.expression.type === 'ConditionalExpression') {
if (roleProp.value.expression.consequent.type === 'Literal' && roleProp.value.expression.alternate.type === 'Literal') {
return;
}
}
}
return;
}
// Visible, non-interactive elements should not have an interactive handler.
context.report({
node,
message: errorMessage
});
})
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,75 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _schemas = require("../util/schemas");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
var errorMessage = 'Use {{tag}} instead of the "{{role}}" role to ensure accessibility across all devices.';
var schema = (0, _schemas.generateObjSchema)();
var formatTag = function formatTag(tag) {
if (!tag.attributes) {
return "<".concat(tag.name, ">");
}
var _tag$attributes = _slicedToArray(tag.attributes, 1),
attribute = _tag$attributes[0];
var value = attribute.value ? "\"".concat(attribute.value, "\"") : '...';
return "<".concat(tag.name, " ").concat(attribute.name, "=").concat(value, ">");
};
var getLastPropValue = function getLastPropValue(rawProp) {
var propValue = (0, _jsxAstUtils.getPropValue)(rawProp);
if (!propValue) {
return propValue;
}
var lastSpaceIndex = propValue.lastIndexOf(' ');
return lastSpaceIndex === -1 ? propValue : propValue.substring(lastSpaceIndex + 1);
};
var _default = exports["default"] = {
meta: {
docs: {
description: 'Enforces using semantic DOM elements over the ARIA `role` property.',
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/prefer-tag-over-role.md'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var role = getLastPropValue((0, _jsxAstUtils.getProp)(node.attributes, 'role'));
if (!role) {
return;
}
var matchedTagsSet = _ariaQuery.roleElements.get(role);
if (!matchedTagsSet) {
return;
}
var matchedTags = Array.from(matchedTagsSet);
if (matchedTags.some(function (matchedTag) {
return matchedTag.name === elementType(node);
})) {
return;
}
context.report({
data: {
tag: matchedTags.length === 1 ? formatTag(matchedTags[0]) : [matchedTags.slice(0, matchedTags.length - 1).map(formatTag).join(', '), formatTag(matchedTags[matchedTags.length - 1])].join(', or '),
role
},
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,89 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _isSemanticRoleElement = _interopRequireDefault(require("../util/isSemanticRoleElement"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } /**
* @fileoverview Enforce that elements with ARIA roles must
* have all required attributes for that role.
* @author Ethan Cohen
*/ // ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = function errorMessage(role, requiredProps) {
return "Elements with the ARIA role \"".concat(role, "\" must have the following attributes defined: ").concat(String(requiredProps).toLowerCase());
};
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/role-has-required-aria-props.md',
description: 'Enforce that elements with ARIA roles must have all required attributes for that role.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(attribute) {
var name = (0, _jsxAstUtils.propName)(attribute).toLowerCase();
if (name !== 'role') {
return;
}
var type = elementType(attribute.parent);
if (!_ariaQuery.dom.get(type)) {
return;
}
var roleAttrValue = (0, _jsxAstUtils.getLiteralPropValue)(attribute);
var attributes = attribute.parent.attributes;
// If value is undefined, then the role attribute will be dropped in the DOM.
// If value is null, then getLiteralAttributeValue is telling us
// that the value isn't in the form of a literal.
if (roleAttrValue === undefined || roleAttrValue === null) {
return;
}
var normalizedValues = String(roleAttrValue).toLowerCase().split(' ');
var validRoles = normalizedValues.filter(function (val) {
return _toConsumableArray(_ariaQuery.roles.keys()).indexOf(val) > -1;
});
// Check semantic DOM elements
// For example, <input type="checkbox" role="switch" />
if ((0, _isSemanticRoleElement["default"])(type, attributes)) {
return;
}
// Check arbitrary DOM elements
validRoles.forEach(function (role) {
var _roles$get = _ariaQuery.roles.get(role),
requiredPropKeyValues = _roles$get.requiredProps;
var requiredProps = Object.keys(requiredPropKeyValues);
if (requiredProps.length > 0) {
var hasRequiredProps = requiredProps.every(function (prop) {
return (0, _jsxAstUtils.getProp)(attributes, prop);
});
if (hasRequiredProps === false) {
context.report({
node: attribute,
message: errorMessage(role.toLowerCase(), requiredProps)
});
}
}
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,80 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _Iterator = _interopRequireDefault(require("es-iterator-helpers/Iterator.from"));
var _IteratorPrototype = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.filter"));
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
var _getImplicitRole = _interopRequireDefault(require("../util/getImplicitRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce that elements with explicit or implicit roles defined contain only
* `aria-*` properties supported by that `role`.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = function errorMessage(attr, role, tag, isImplicit) {
if (isImplicit) {
return "The attribute ".concat(attr, " is not supported by the role ").concat(role, ". This role is implicit on the element ").concat(tag, ".");
}
return "The attribute ".concat(attr, " is not supported by the role ").concat(role, ".");
};
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/role-supports-aria-props.md',
description: 'Enforce that elements with explicit or implicit roles defined contain only `aria-*` properties supported by that `role`.'
},
schema: [schema]
},
create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXOpeningElement(node) {
// If role is not explicitly defined, then try and get its implicit role.
var type = elementType(node);
var role = (0, _jsxAstUtils.getProp)(node.attributes, 'role');
var roleValue = role ? (0, _jsxAstUtils.getLiteralPropValue)(role) : (0, _getImplicitRole["default"])(type, node.attributes);
var isImplicit = roleValue && role === undefined;
// If there is no explicit or implicit role, then assume that the element
// can handle the global set of aria-* properties.
// This actually isn't true - should fix in future release.
if (typeof roleValue !== 'string' || _ariaQuery.roles.get(roleValue) === undefined) {
return;
}
// Make sure it has no aria-* properties defined outside of its property set.
var _roles$get = _ariaQuery.roles.get(roleValue),
propKeyValues = _roles$get.props;
var invalidAriaPropsForRole = new Set((0, _IteratorPrototype["default"])((0, _Iterator["default"])(_ariaQuery.aria.keys()), function (attribute) {
return !(attribute in propKeyValues);
}));
node.attributes.filter(function (prop) {
return (0, _jsxAstUtils.getPropValue)(prop) != null // Ignore the attribute if its value is null or undefined.
&& prop.type !== 'JSXSpreadAttribute' // Ignore the attribute if it's a spread.
;
}).forEach(function (prop) {
var name = (0, _jsxAstUtils.propName)(prop);
if (invalidAriaPropsForRole.has(name)) {
context.report({
node,
message: errorMessage(name, roleValue, type, isImplicit)
});
}
});
}
};
}
};
module.exports = exports.default;

58
node_modules/eslint-plugin-jsx-a11y/lib/rules/scope.js generated vendored Normal file
View File

@@ -0,0 +1,58 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
var _getElementType = _interopRequireDefault(require("../util/getElementType"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* @fileoverview Enforce scope prop is only used on <th> elements.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'The scope prop can only be used on <th> elements.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
meta: {
docs: {
url: 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/tree/HEAD/docs/rules/scope.md',
description: 'Enforce `scope` prop is only used on `<th>` elements.'
},
schema: [schema]
},
create: function create(context) {
var elementType = (0, _getElementType["default"])(context);
return {
JSXAttribute: function JSXAttribute(node) {
var name = (0, _jsxAstUtils.propName)(node);
if (name && name.toUpperCase() !== 'SCOPE') {
return;
}
var parent = node.parent;
var tagName = elementType(parent);
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
if (!_ariaQuery.dom.has(tagName)) {
return;
}
if (tagName && tagName.toUpperCase() === 'TH') {
return;
}
context.report({
node,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,53 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _schemas = require("../util/schemas");
/**
* @fileoverview Enforce tabIndex value is not greater than zero.
* @author Ethan Cohen
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Avoid positive integer values for tabIndex.';
var schema = (0, _schemas.generateObjSchema)();
var _default = exports["default"] = {
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: function create(context) {
return {
JSXAttribute: function JSXAttribute(attribute) {
var name = (0, _jsxAstUtils.propName)(attribute).toUpperCase();
// Check if tabIndex is the attribute
if (name !== 'TABINDEX') {
return;
}
// Only check literals because we can't infer values from certain expressions.
var value = Number((0, _jsxAstUtils.getLiteralPropValue)(attribute));
// eslint-disable-next-line no-restricted-globals
if (isNaN(value) || value <= 0) {
return;
}
context.report({
node: attribute,
message: errorMessage
});
}
};
}
};
module.exports = exports.default;

View File

@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns true if all items in baseAttributes are found in attributes. Always
* returns true if baseAttributes is empty.
*/
function attributesComparator() {
var baseAttributes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var attributes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
return baseAttributes.every(function (baseAttr) {
return attributes.some(function (attribute) {
// Guard against non-JSXAttribute nodes like JSXSpreadAttribute
if (attribute.type !== 'JSXAttribute') {
return false;
}
// Attribute matches.
if (baseAttr.name !== (0, _jsxAstUtils.propName)(attribute)) {
return false;
}
// Value exists and does not match.
if (baseAttr.value && baseAttr.value !== (0, _jsxAstUtils.getLiteralPropValue)(attribute)) {
return false;
}
return true;
});
});
}
var _default = exports["default"] = attributesComparator;
module.exports = exports.default;

View File

@@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getAccessibleChildText;
var _jsxAstUtils = require("jsx-ast-utils");
var _isHiddenFromScreenReader = _interopRequireDefault(require("./isHiddenFromScreenReader"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Returns a new "standardized" string: all whitespace is collapsed to one space,
* and the string is lowercase
* @param {string} input
* @returns lowercase, single-spaced, punctuation-stripped, trimmed string
*/
function standardizeSpaceAndCase(input) {
return input.trim().replace(/[,.?¿!‽¡;:]/g, '') // strip punctuation
.replace(/\s\s+/g, ' ') // collapse spaces
.toLowerCase();
}
/**
* Returns the (recursively-defined) accessible child text of a node, which (in-order) is:
* 1. The element's aria-label
* 2. If the element is a direct literal, the literal value
* 3. Otherwise, merge all of its children
* @param {JSXElement} node - node to traverse
* @returns child text as a string
*/
function getAccessibleChildText(node, elementType) {
var ariaLabel = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.openingElement.attributes, 'aria-label'));
// early escape-hatch when aria-label is applied
if (ariaLabel) return standardizeSpaceAndCase(ariaLabel);
// early-return if alt prop exists and is an image
var altTag = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.openingElement.attributes, 'alt'));
if (elementType(node.openingElement) === 'img' && altTag) return standardizeSpaceAndCase(altTag);
// skip if aria-hidden is true
if ((0, _isHiddenFromScreenReader["default"])(elementType(node.openingElement), node.openingElement.attributes)) {
return '';
}
var rawChildText = node.children.map(function (currentNode) {
// $FlowFixMe JSXText is missing in ast-types-flow
if (currentNode.type === 'Literal' || currentNode.type === 'JSXText') {
return String(currentNode.value);
}
if (currentNode.type === 'JSXElement') {
return getAccessibleChildText(currentNode, elementType);
}
return '';
}).join(' ');
return standardizeSpaceAndCase(rawChildText);
}
module.exports = exports.default;

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getComputedRole;
var _getExplicitRole = _interopRequireDefault(require("./getExplicitRole"));
var _getImplicitRole = _interopRequireDefault(require("./getImplicitRole"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Returns an element's computed role, which is
*
* 1. The valid value of its explicit role attribute; or
* 2. The implicit value of its tag.
*/
function getComputedRole(tag, attributes) {
return (0, _getExplicitRole["default"])(tag, attributes) || (0, _getImplicitRole["default"])(tag, attributes);
}
module.exports = exports.default;

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _hasown = _interopRequireDefault(require("hasown"));
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _jsxAstUtils = require("jsx-ast-utils");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var getElementType = function getElementType(context) {
var _settings$jsxA11y, _settings$jsxA11y2, _settings$jsxA11y3;
var settings = context.settings;
var polymorphicPropName = (_settings$jsxA11y = settings['jsx-a11y']) === null || _settings$jsxA11y === void 0 ? void 0 : _settings$jsxA11y.polymorphicPropName;
var polymorphicAllowList = (_settings$jsxA11y2 = settings['jsx-a11y']) === null || _settings$jsxA11y2 === void 0 ? void 0 : _settings$jsxA11y2.polymorphicAllowList;
var componentMap = (_settings$jsxA11y3 = settings['jsx-a11y']) === null || _settings$jsxA11y3 === void 0 ? void 0 : _settings$jsxA11y3.components;
return function (node) {
var polymorphicProp = polymorphicPropName ? (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(node.attributes, polymorphicPropName)) : undefined;
var rawType = (0, _jsxAstUtils.elementType)(node);
if (polymorphicProp && (!polymorphicAllowList || (0, _arrayIncludes["default"])(polymorphicAllowList, rawType))) {
rawType = polymorphicProp;
}
if (!componentMap) {
return rawType;
}
return (0, _hasown["default"])(componentMap, rawType) ? componentMap[rawType] : rawType;
};
};
var _default = exports["default"] = getElementType;
module.exports = exports.default;

View File

@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getExplicitRole;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns an element's computed role, which is
*
* 1. The valid value of its explicit role attribute; or
* 2. The implicit value of its tag.
*/
function getExplicitRole(tag, attributes) {
var explicitRole = function toLowerCase(role) {
if (typeof role === 'string') {
return role.toLowerCase();
}
return null;
}((0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role')));
if (_ariaQuery.roles.has(explicitRole)) {
return explicitRole;
}
return null;
}
module.exports = exports.default;

View File

@@ -0,0 +1,24 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRole;
var _ariaQuery = require("aria-query");
var _implicitRoles = _interopRequireDefault(require("./implicitRoles"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Returns an element's implicit role given its attributes and type.
* Some elements only have an implicit role when certain props are defined.
*/
function getImplicitRole(type, attributes) {
var implicitRole;
if (_implicitRoles["default"][type]) {
implicitRole = _implicitRoles["default"][type](attributes);
}
if (_ariaQuery.roles.has(implicitRole)) {
return implicitRole;
}
return null;
}
module.exports = exports.default;

View File

@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getSuggestion;
var _damerauLevenshtein = _interopRequireDefault(require("damerau-levenshtein"));
var _object = _interopRequireDefault(require("object.fromentries"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
// Minimum edit distance to be considered a good suggestion.
var THRESHOLD = 2;
/**
* Returns an array of suggestions given a word and a dictionary and limit of suggestions
* to return.
*/
function getSuggestion(word) {
var dictionary = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
var limit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
var distances = (0, _object["default"])(dictionary.map(function (dictionaryWord) {
var distance = (0, _damerauLevenshtein["default"])(word.toUpperCase(), dictionaryWord.toUpperCase());
var steps = distance.steps;
return [dictionaryWord, steps];
}));
return Object.keys(distances).filter(function (suggestion) {
return distances[suggestion] <= THRESHOLD;
}).sort(function (a, b) {
return distances[a] - distances[b];
}) // Sort by distance
.slice(0, limit);
}
module.exports = exports.default;

View File

@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getTabIndex;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the tabIndex value.
*/
function getTabIndex(tabIndex) {
var literalValue = (0, _jsxAstUtils.getLiteralPropValue)(tabIndex);
// String and number values.
if (['string', 'number'].indexOf(typeof literalValue) > -1) {
// Empty string will convert to zero, so check for it explicity.
if (typeof literalValue === 'string' && literalValue.length === 0) {
return undefined;
}
var value = Number(literalValue);
if (Number.isNaN(value)) {
return undefined;
}
return Number.isInteger(value) ? value : undefined;
}
// Booleans are not valid values, return undefined.
if (literalValue === true || literalValue === false) {
return undefined;
}
return (0, _jsxAstUtils.getPropValue)(tabIndex);
}
module.exports = exports.default;

View File

@@ -0,0 +1,30 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = hasAccessibleChild;
var _jsxAstUtils = require("jsx-ast-utils");
var _isHiddenFromScreenReader = _interopRequireDefault(require("./isHiddenFromScreenReader"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function hasAccessibleChild(node, elementType) {
return node.children.some(function (child) {
switch (child.type) {
case 'Literal':
return !!child.value;
// $FlowFixMe JSXText is missing in ast-types-flow
case 'JSXText':
return !!child.value;
case 'JSXElement':
return !(0, _isHiddenFromScreenReader["default"])(elementType(child.openingElement), child.openingElement.attributes);
case 'JSXExpressionContainer':
if (child.expression.type === 'Identifier') {
return child.expression.name !== 'undefined';
}
return true;
default:
return false;
}
}) || (0, _jsxAstUtils.hasAnyProp)(node.openingElement.attributes, ['dangerouslySetInnerHTML', 'children']);
}
module.exports = exports.default;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForAnchor;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for an anchor tag.
*/
function getImplicitRoleForAnchor(attributes) {
if ((0, _jsxAstUtils.getProp)(attributes, 'href')) {
return 'link';
}
return '';
}
module.exports = exports.default;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForArea;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for an area tag.
*/
function getImplicitRoleForArea(attributes) {
if ((0, _jsxAstUtils.getProp)(attributes, 'href')) {
return 'link';
}
return '';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForArticle;
/**
* Returns the implicit role for an article tag.
*/
function getImplicitRoleForArticle() {
return 'article';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForAside;
/**
* Returns the implicit role for an aside tag.
*/
function getImplicitRoleForAside() {
return 'complementary';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForBody;
/**
* Returns the implicit role for a body tag.
*/
function getImplicitRoleForBody() {
return 'document';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForButton;
/**
* Returns the implicit role for a button tag.
*/
function getImplicitRoleForButton() {
return 'button';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForDatalist;
/**
* Returns the implicit role for a datalist tag.
*/
function getImplicitRoleForDatalist() {
return 'listbox';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForDetails;
/**
* Returns the implicit role for a details tag.
*/
function getImplicitRoleForDetails() {
return 'group';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForDialog;
/**
* Returns the implicit role for a dialog tag.
*/
function getImplicitRoleForDialog() {
return 'dialog';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForForm;
/**
* Returns the implicit role for a form tag.
*/
function getImplicitRoleForForm() {
return 'form';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForH1;
/**
* Returns the implicit role for an h1 tag.
*/
function getImplicitRoleForH1() {
return 'heading';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForH2;
/**
* Returns the implicit role for an h2 tag.
*/
function getImplicitRoleForH2() {
return 'heading';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForH3;
/**
* Returns the implicit role for an h3 tag.
*/
function getImplicitRoleForH3() {
return 'heading';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForH4;
/**
* Returns the implicit role for an h4 tag.
*/
function getImplicitRoleForH4() {
return 'heading';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForH5;
/**
* Returns the implicit role for an h5 tag.
*/
function getImplicitRoleForH5() {
return 'heading';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForH6;
/**
* Returns the implicit role for an h6tag.
*/
function getImplicitRoleForH6() {
return 'heading';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForHr;
/**
* Returns the implicit role for an hr tag.
*/
function getImplicitRoleForHr() {
return 'separator';
}
module.exports = exports.default;

View File

@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForImg;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for an img tag.
*/
function getImplicitRoleForImg(attributes) {
var alt = (0, _jsxAstUtils.getProp)(attributes, 'alt');
if (alt && (0, _jsxAstUtils.getLiteralPropValue)(alt) === '') {
return '';
}
return 'img';
}
module.exports = exports.default;

View File

@@ -0,0 +1,82 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _a = _interopRequireDefault(require("./a"));
var _area = _interopRequireDefault(require("./area"));
var _article = _interopRequireDefault(require("./article"));
var _aside = _interopRequireDefault(require("./aside"));
var _body = _interopRequireDefault(require("./body"));
var _button = _interopRequireDefault(require("./button"));
var _datalist = _interopRequireDefault(require("./datalist"));
var _details = _interopRequireDefault(require("./details"));
var _dialog = _interopRequireDefault(require("./dialog"));
var _form = _interopRequireDefault(require("./form"));
var _h = _interopRequireDefault(require("./h1"));
var _h2 = _interopRequireDefault(require("./h2"));
var _h3 = _interopRequireDefault(require("./h3"));
var _h4 = _interopRequireDefault(require("./h4"));
var _h5 = _interopRequireDefault(require("./h5"));
var _h6 = _interopRequireDefault(require("./h6"));
var _hr = _interopRequireDefault(require("./hr"));
var _img = _interopRequireDefault(require("./img"));
var _input = _interopRequireDefault(require("./input"));
var _li = _interopRequireDefault(require("./li"));
var _link = _interopRequireDefault(require("./link"));
var _menu = _interopRequireDefault(require("./menu"));
var _menuitem = _interopRequireDefault(require("./menuitem"));
var _meter = _interopRequireDefault(require("./meter"));
var _nav = _interopRequireDefault(require("./nav"));
var _ol = _interopRequireDefault(require("./ol"));
var _option = _interopRequireDefault(require("./option"));
var _output = _interopRequireDefault(require("./output"));
var _progress = _interopRequireDefault(require("./progress"));
var _section = _interopRequireDefault(require("./section"));
var _select = _interopRequireDefault(require("./select"));
var _tbody = _interopRequireDefault(require("./tbody"));
var _textarea = _interopRequireDefault(require("./textarea"));
var _tfoot = _interopRequireDefault(require("./tfoot"));
var _thead = _interopRequireDefault(require("./thead"));
var _ul = _interopRequireDefault(require("./ul"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var _default = exports["default"] = {
a: _a["default"],
area: _area["default"],
article: _article["default"],
aside: _aside["default"],
body: _body["default"],
button: _button["default"],
datalist: _datalist["default"],
details: _details["default"],
dialog: _dialog["default"],
form: _form["default"],
h1: _h["default"],
h2: _h2["default"],
h3: _h3["default"],
h4: _h4["default"],
h5: _h5["default"],
h6: _h6["default"],
hr: _hr["default"],
img: _img["default"],
input: _input["default"],
li: _li["default"],
link: _link["default"],
menu: _menu["default"],
menuitem: _menuitem["default"],
meter: _meter["default"],
nav: _nav["default"],
ol: _ol["default"],
option: _option["default"],
output: _output["default"],
progress: _progress["default"],
section: _section["default"],
select: _select["default"],
tbody: _tbody["default"],
textarea: _textarea["default"],
tfoot: _tfoot["default"],
thead: _thead["default"],
ul: _ul["default"]
};
module.exports = exports.default;

View File

@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForInput;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for an input tag.
*/
function getImplicitRoleForInput(attributes) {
var type = (0, _jsxAstUtils.getProp)(attributes, 'type');
if (type) {
var value = (0, _jsxAstUtils.getLiteralPropValue)(type) || '';
switch (typeof value === 'string' && value.toUpperCase()) {
case 'BUTTON':
case 'IMAGE':
case 'RESET':
case 'SUBMIT':
return 'button';
case 'CHECKBOX':
return 'checkbox';
case 'RADIO':
return 'radio';
case 'RANGE':
return 'slider';
case 'EMAIL':
case 'PASSWORD':
case 'SEARCH': // with [list] selector it's combobox
case 'TEL': // with [list] selector it's combobox
case 'URL': // with [list] selector it's combobox
default:
return 'textbox';
}
}
return 'textbox';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForLi;
/**
* Returns the implicit role for an li tag.
*/
function getImplicitRoleForLi() {
return 'listitem';
}
module.exports = exports.default;

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForLink;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for a link tag.
*/
function getImplicitRoleForLink(attributes) {
if ((0, _jsxAstUtils.getProp)(attributes, 'href')) {
return 'link';
}
return '';
}
module.exports = exports.default;

View File

@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForMenu;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for a menu tag.
*/
function getImplicitRoleForMenu(attributes) {
var type = (0, _jsxAstUtils.getProp)(attributes, 'type');
if (type) {
var value = (0, _jsxAstUtils.getLiteralPropValue)(type);
return value && value.toUpperCase() === 'TOOLBAR' ? 'toolbar' : '';
}
return '';
}
module.exports = exports.default;

View File

@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForMenuitem;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns the implicit role for a menuitem tag.
*/
function getImplicitRoleForMenuitem(attributes) {
var type = (0, _jsxAstUtils.getProp)(attributes, 'type');
if (type) {
var value = (0, _jsxAstUtils.getLiteralPropValue)(type) || '';
switch (typeof value === 'string' && value.toUpperCase()) {
case 'COMMAND':
return 'menuitem';
case 'CHECKBOX':
return 'menuitemcheckbox';
case 'RADIO':
return 'menuitemradio';
default:
return '';
}
}
return '';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForMeter;
/**
* Returns the implicit role for a meter tag.
*/
function getImplicitRoleForMeter() {
return 'progressbar';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForNav;
/**
* Returns the implicit role for a nav tag.
*/
function getImplicitRoleForNav() {
return 'navigation';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForOl;
/**
* Returns the implicit role for an ol tag.
*/
function getImplicitRoleForOl() {
return 'list';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForOption;
/**
* Returns the implicit role for an option tag.
*/
function getImplicitRoleForOption() {
return 'option';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForOutput;
/**
* Returns the implicit role for an output tag.
*/
function getImplicitRoleForOutput() {
return 'status';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForProgress;
/**
* Returns the implicit role for a progress tag.
*/
function getImplicitRoleForProgress() {
return 'progressbar';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForSection;
/**
* Returns the implicit role for a section tag.
*/
function getImplicitRoleForSection() {
return 'region';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForSelect;
/**
* Returns the implicit role for a select tag.
*/
function getImplicitRoleForSelect() {
return 'listbox';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForTbody;
/**
* Returns the implicit role for a tbody tag.
*/
function getImplicitRoleForTbody() {
return 'rowgroup';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForTextarea;
/**
* Returns the implicit role for a textarea tag.
*/
function getImplicitRoleForTextarea() {
return 'textbox';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForTfoot;
/**
* Returns the implicit role for a tfoot tag.
*/
function getImplicitRoleForTfoot() {
return 'rowgroup';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForThead;
/**
* Returns the implicit role for a thead tag.
*/
function getImplicitRoleForThead() {
return 'rowgroup';
}
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = getImplicitRoleForUl;
/**
* Returns the implicit role for a ul tag.
*/
function getImplicitRoleForUl() {
return 'list';
}
module.exports = exports.default;

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _Iterator = _interopRequireDefault(require("es-iterator-helpers/Iterator.from"));
var _IteratorPrototype = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.filter"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
var abstractRoles = new Set((0, _IteratorPrototype["default"])((0, _Iterator["default"])(_ariaQuery.roles.keys()), function (role) {
return _ariaQuery.roles.get(role)["abstract"];
}));
var DOMElements = new Set(_ariaQuery.dom.keys());
var isAbstractRole = function isAbstractRole(tagName, attributes) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
if (!DOMElements.has(tagName)) {
return false;
}
var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
return abstractRoles.has(role);
};
var _default = exports["default"] = isAbstractRole;
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = isContentEditable;
var _jsxAstUtils = require("jsx-ast-utils");
function isContentEditable(tagName, attributes) {
var _prop$value;
var prop = (0, _jsxAstUtils.getProp)(attributes, 'contentEditable');
return (prop === null || prop === void 0 ? void 0 : (_prop$value = prop.value) === null || _prop$value === void 0 ? void 0 : _prop$value.raw) === '"true"';
}
module.exports = exports.default;

View File

@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
/**
* Returns boolean indicating whether the given element is a DOM element.
*/
var isDOMElement = function isDOMElement(tagName) {
return _ariaQuery.dom.has(tagName);
};
var _default = exports["default"] = isDOMElement;
module.exports = exports.default;

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var isDisabledElement = function isDisabledElement(attributes) {
var disabledAttr = (0, _jsxAstUtils.getProp)(attributes, 'disabled');
var disabledAttrValue = (0, _jsxAstUtils.getPropValue)(disabledAttr);
var isHTML5Disabled = disabledAttr && disabledAttrValue !== undefined;
if (isHTML5Disabled) {
return true;
}
var ariaDisabledAttr = (0, _jsxAstUtils.getProp)(attributes, 'aria-disabled');
var ariaDisabledAttrValue = (0, _jsxAstUtils.getLiteralPropValue)(ariaDisabledAttr);
if (ariaDisabledAttr && ariaDisabledAttrValue !== undefined && ariaDisabledAttrValue === true) {
return true;
}
return false;
};
var _default = exports["default"] = isDisabledElement;
module.exports = exports.default;

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var _getTabIndex = _interopRequireDefault(require("./getTabIndex"));
var _isInteractiveElement = _interopRequireDefault(require("./isInteractiveElement"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
/**
* Returns boolean indicating whether an element appears in tab focus.
* Identifies an element as focusable if it is an interactive element, or an element with a tabIndex greater than or equal to 0.
*/
function isFocusable(type, attributes) {
var tabIndex = (0, _getTabIndex["default"])((0, _jsxAstUtils.getProp)(attributes, 'tabIndex'));
if ((0, _isInteractiveElement["default"])(type, attributes)) {
return tabIndex === undefined || tabIndex >= 0;
}
return tabIndex >= 0;
}
var _default = exports["default"] = isFocusable;
module.exports = exports.default;

View File

@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns boolean indicating that the aria-hidden prop
* is present or the value is true. Will also return true if
* there is an input with type='hidden'.
*
* <div aria-hidden /> is equivalent to the DOM as <div aria-hidden=true />.
*/
var isHiddenFromScreenReader = function isHiddenFromScreenReader(type, attributes) {
if (type.toUpperCase() === 'INPUT') {
var hidden = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'type'));
if (hidden && hidden.toUpperCase() === 'HIDDEN') {
return true;
}
}
var ariaHidden = (0, _jsxAstUtils.getPropValue)((0, _jsxAstUtils.getProp)(attributes, 'aria-hidden'));
return ariaHidden === true;
};
var _default = exports["default"] = isHiddenFromScreenReader;
module.exports = exports.default;

View File

@@ -0,0 +1,130 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _axobjectQuery = require("axobject-query");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
var _Iterator = _interopRequireDefault(require("es-iterator-helpers/Iterator.from"));
var _IteratorPrototype = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.filter"));
var _IteratorPrototype2 = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.some"));
var _attributesComparator = _interopRequireDefault(require("./attributesComparator"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } // import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
var roleKeys = _toConsumableArray(_ariaQuery.roles.keys());
var elementRoleEntries = _toConsumableArray(_ariaQuery.elementRoles);
var nonInteractiveRoles = new Set(roleKeys.filter(function (name) {
var role = _ariaQuery.roles.get(name);
return !role["abstract"]
// 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
&& name !== 'toolbar' && !role.superClass.some(function (classes) {
return (0, _arrayIncludes["default"])(classes, 'widget');
});
}).concat(
// The `progressbar` is descended from `widget`, but in practice, its
// value is always `readonly`, so we treat it as a non-interactive role.
'progressbar'));
var interactiveRoles = new Set(roleKeys.filter(function (name) {
var role = _ariaQuery.roles.get(name);
return !role["abstract"]
// The `progressbar` is descended from `widget`, but in practice, its
// value is always `readonly`, so we treat it as a non-interactive role.
&& name !== 'progressbar' && role.superClass.some(function (classes) {
return (0, _arrayIncludes["default"])(classes, 'widget');
});
}).concat(
// 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
'toolbar'));
// TODO: convert to use iterFlatMap and iterFrom
var interactiveElementRoleSchemas = (0, _arrayPrototype["default"])(elementRoleEntries, function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
elementSchema = _ref2[0],
rolesArr = _ref2[1];
return rolesArr.some(function (role) {
return interactiveRoles.has(role);
}) ? [elementSchema] : [];
});
// TODO: convert to use iterFlatMap and iterFrom
var nonInteractiveElementRoleSchemas = (0, _arrayPrototype["default"])(elementRoleEntries, function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
elementSchema = _ref4[0],
rolesArr = _ref4[1];
return rolesArr.every(function (role) {
return nonInteractiveRoles.has(role);
}) ? [elementSchema] : [];
});
var interactiveAXObjects = new Set((0, _IteratorPrototype["default"])((0, _Iterator["default"])(_axobjectQuery.AXObjects.keys()), function (name) {
return _axobjectQuery.AXObjects.get(name).type === 'widget';
}));
// TODO: convert to use iterFlatMap and iterFrom
var interactiveElementAXObjectSchemas = (0, _arrayPrototype["default"])(_toConsumableArray(_axobjectQuery.elementAXObjects), function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
elementSchema = _ref6[0],
AXObjectsArr = _ref6[1];
return AXObjectsArr.every(function (role) {
return interactiveAXObjects.has(role);
}) ? [elementSchema] : [];
});
function checkIsInteractiveElement(tagName, attributes) {
function elementSchemaMatcher(elementSchema) {
return tagName === elementSchema.name && (0, _attributesComparator["default"])(elementSchema.attributes, attributes);
}
// TODO: remove this when aria-query and axobject-query are upgraded
if (tagName === 'summary') {
return false;
}
// Check in elementRoles for inherent interactive role associations for
// this element.
var isInherentInteractiveElement = (0, _IteratorPrototype2["default"])((0, _Iterator["default"])(interactiveElementRoleSchemas), elementSchemaMatcher);
if (isInherentInteractiveElement) {
return true;
}
// Check in elementRoles for inherent non-interactive role associations for
// this element.
var isInherentNonInteractiveElement = (0, _IteratorPrototype2["default"])((0, _Iterator["default"])(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
if (isInherentNonInteractiveElement) {
return false;
}
// Check in elementAXObjects for AX Tree associations for this element.
var isInteractiveAXElement = (0, _IteratorPrototype2["default"])((0, _Iterator["default"])(interactiveElementAXObjectSchemas), elementSchemaMatcher);
if (isInteractiveAXElement) {
return true;
}
return false;
}
/**
* Returns boolean indicating whether the given element is
* interactive on the DOM or not. Usually used when an element
* has a dynamic handler on it and we need to discern whether or not
* it's intention is to be interacted with on the DOM.
*/
var isInteractiveElement = function isInteractiveElement(tagName, attributes) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
if (!_ariaQuery.dom.has(tagName)) {
return false;
}
return checkIsInteractiveElement(tagName, attributes);
};
var _default = exports["default"] = isInteractiveElement;
module.exports = exports.default;

View File

@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var roles = _toConsumableArray(_ariaQuery.roles.keys());
var interactiveRoles = roles.filter(function (name) {
return !_ariaQuery.roles.get(name)["abstract"] && _ariaQuery.roles.get(name).superClass.some(function (klasses) {
return (0, _arrayIncludes["default"])(klasses, 'widget');
});
});
// 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
interactiveRoles.push('toolbar');
/**
* Returns boolean indicating whether the given element has a role
* that is associated with an interactive component. Used when an element
* has a dynamic handler on it and we need to discern whether or not
* its intention is to be interacted with in the DOM.
*
* isInteractiveRole is a Logical Disjunction:
* https://en.wikipedia.org/wiki/Logical_disjunction
* The JSX element does not have a tagName or it has a tagName and a role
* attribute with a value in the set of non-interactive roles.
*/
var isInteractiveRole = function isInteractiveRole(tagName, attributes) {
var value = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
// If value is undefined, then the role attribute will be dropped in the DOM.
// If value is null, then getLiteralAttributeValue is telling us that the
// value isn't in the form of a literal
if (value === undefined || value === null) {
return false;
}
var isInteractive = false;
var normalizedValues = String(value).toLowerCase().split(' ');
var validRoles = (0, _arrayPrototype["default"])(normalizedValues, function (name) {
return (0, _arrayIncludes["default"])(roles, name) ? [name] : [];
});
if (validRoles.length > 0) {
// The first role value is a series takes precedence.
isInteractive = (0, _arrayIncludes["default"])(interactiveRoles, validRoles[0]);
}
return isInteractive;
};
var _default = exports["default"] = isInteractiveRole;
module.exports = exports.default;

View File

@@ -0,0 +1,139 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _axobjectQuery = require("axobject-query");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
var _Iterator = _interopRequireDefault(require("es-iterator-helpers/Iterator.from"));
var _IteratorPrototype = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.filter"));
var _IteratorPrototype2 = _interopRequireDefault(require("es-iterator-helpers/Iterator.prototype.some"));
var _attributesComparator = _interopRequireDefault(require("./attributesComparator"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } // import iterFlatMap from 'es-iterator-helpers/Iterator.prototype.flatMap';
var roleKeys = _toConsumableArray(_ariaQuery.roles.keys());
var elementRoleEntries = _toConsumableArray(_ariaQuery.elementRoles);
var nonInteractiveRoles = new Set(roleKeys.filter(function (name) {
var role = _ariaQuery.roles.get(name);
return !role["abstract"]
// 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
&& name !== 'toolbar'
// This role is meant to have no semantic value.
// @see https://www.w3.org/TR/wai-aria-1.2/#generic
&& name !== 'generic' && !role.superClass.some(function (classes) {
return (0, _arrayIncludes["default"])(classes, 'widget');
});
}).concat(
// The `progressbar` is descended from `widget`, but in practice, its
// value is always `readonly`, so we treat it as a non-interactive role.
'progressbar'));
var interactiveRoles = new Set(roleKeys.filter(function (name) {
var role = _ariaQuery.roles.get(name);
return !role["abstract"]
// The `progressbar` is descended from `widget`, but in practice, its
// value is always `readonly`, so we treat it as a non-interactive role.
&& name !== 'progressbar'
// This role is meant to have no semantic value.
// @see https://www.w3.org/TR/wai-aria-1.2/#generic
&& name !== 'generic' && role.superClass.some(function (classes) {
return (0, _arrayIncludes["default"])(classes, 'widget');
});
}).concat(
// 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
'toolbar'));
// TODO: convert to use iterFlatMap and iterFrom
var interactiveElementRoleSchemas = (0, _arrayPrototype["default"])(elementRoleEntries, function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
elementSchema = _ref2[0],
rolesArr = _ref2[1];
return rolesArr.some(function (role) {
return interactiveRoles.has(role);
}) ? [elementSchema] : [];
});
// TODO: convert to use iterFlatMap and iterFrom
var nonInteractiveElementRoleSchemas = (0, _arrayPrototype["default"])(elementRoleEntries, function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
elementSchema = _ref4[0],
rolesArr = _ref4[1];
return rolesArr.every(function (role) {
return nonInteractiveRoles.has(role);
}) ? [elementSchema] : [];
});
var nonInteractiveAXObjects = new Set((0, _IteratorPrototype["default"])((0, _Iterator["default"])(_axobjectQuery.AXObjects.keys()), function (name) {
return (0, _arrayIncludes["default"])(['window', 'structure'], _axobjectQuery.AXObjects.get(name).type);
}));
// TODO: convert to use iterFlatMap and iterFrom
var nonInteractiveElementAXObjectSchemas = (0, _arrayPrototype["default"])(_toConsumableArray(_axobjectQuery.elementAXObjects), function (_ref5) {
var _ref6 = _slicedToArray(_ref5, 2),
elementSchema = _ref6[0],
AXObjectsArr = _ref6[1];
return AXObjectsArr.every(function (role) {
return nonInteractiveAXObjects.has(role);
}) ? [elementSchema] : [];
});
function checkIsNonInteractiveElement(tagName, attributes) {
function elementSchemaMatcher(elementSchema) {
return tagName === elementSchema.name && (0, _attributesComparator["default"])(elementSchema.attributes, attributes);
}
// Check in elementRoles for inherent non-interactive role associations for
// this element.
var isInherentNonInteractiveElement = (0, _IteratorPrototype2["default"])((0, _Iterator["default"])(nonInteractiveElementRoleSchemas), elementSchemaMatcher);
if (isInherentNonInteractiveElement) {
return true;
}
// Check in elementRoles for inherent interactive role associations for
// this element.
var isInherentInteractiveElement = (0, _IteratorPrototype2["default"])((0, _Iterator["default"])(interactiveElementRoleSchemas), elementSchemaMatcher);
if (isInherentInteractiveElement) {
return false;
}
// Check in elementAXObjects for AX Tree associations for this element.
var isNonInteractiveAXElement = (0, _IteratorPrototype2["default"])((0, _Iterator["default"])(nonInteractiveElementAXObjectSchemas), elementSchemaMatcher);
if (isNonInteractiveAXElement) {
return true;
}
return false;
}
/**
* Returns boolean indicating whether the given element is a non-interactive
* element. If the element has either a non-interactive role assigned or it
* is an element with an inherently non-interactive role, then this utility
* returns true. Elements that lack either an explicitly assigned role or
* an inherent role are not considered. For those, this utility returns false
* because a positive determination of interactiveness cannot be determined.
*/
var isNonInteractiveElement = function isNonInteractiveElement(tagName, attributes) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
if (!_ariaQuery.dom.has(tagName)) {
return false;
}
// <header> elements do not technically have semantics, unless the
// element is a direct descendant of <body>, and this plugin cannot
// reliably test that.
// @see https://www.w3.org/TR/wai-aria-practices/examples/landmarks/banner.html
if (tagName === 'header') {
return false;
}
return checkIsNonInteractiveElement(tagName, attributes);
};
var _default = exports["default"] = isNonInteractiveElement;
module.exports = exports.default;

View File

@@ -0,0 +1,61 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _ariaQuery = require("aria-query");
var _jsxAstUtils = require("jsx-ast-utils");
var _arrayIncludes = _interopRequireDefault(require("array-includes"));
var _arrayPrototype = _interopRequireDefault(require("array.prototype.flatmap"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
var nonInteractiveRoles = _toConsumableArray(_ariaQuery.roles.keys()).filter(function (name) {
return !_ariaQuery.roles.get(name)["abstract"] && !_ariaQuery.roles.get(name).superClass.some(function (klasses) {
return (0, _arrayIncludes["default"])(klasses, 'widget');
});
});
/**
* Returns boolean indicating whether the given element has a role
* that is associated with a non-interactive component. Non-interactive roles
* include `listitem`, `article`, or `dialog`. These are roles that indicate
* for the most part containers.
*
* Elements with these roles should not respond or handle user interactions.
* For example, an `onClick` handler should not be assigned to an element with
* the role `listitem`. An element inside the `listitem`, like a button or a
* link, should handle the click.
*
* This utility returns true for elements that are assigned a non-interactive
* role. It will return false for elements that do not have a role. So whereas
* a `div` might be considered non-interactive, for the purpose of this utility,
* it is considered neither interactive nor non-interactive -- a determination
* cannot be made in this case and false is returned.
*/
var isNonInteractiveRole = function isNonInteractiveRole(tagName, attributes) {
// Do not test higher level JSX components, as we do not know what
// low-level DOM element this maps to.
if (!_ariaQuery.dom.has(tagName)) {
return false;
}
var role = (0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role'));
var isNonInteractive = false;
var normalizedValues = String(role).toLowerCase().split(' ');
var validRoles = (0, _arrayPrototype["default"])(normalizedValues, function (name) {
return _ariaQuery.roles.has(name) ? [name] : [];
});
if (validRoles.length > 0) {
// The first role value is a series takes precedence.
isNonInteractive = (0, _arrayIncludes["default"])(nonInteractiveRoles, validRoles[0]);
}
return isNonInteractive;
};
var _default = exports["default"] = isNonInteractiveRole;
module.exports = exports.default;

View File

@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
/**
* Returns boolean indicating whether the given element has been specified with
* an AST node with a non-literal type.
*
* Returns true if the elements has a role and its value is not of a type Literal.
* Otherwise returns false.
*/
var isNonLiteralProperty = function isNonLiteralProperty(attributes, propName) {
var prop = (0, _jsxAstUtils.getProp)(attributes, propName);
if (!prop) return false;
var propValue = prop.value;
if (!propValue) return false;
if (propValue.type === 'Literal') return false;
if (propValue.type === 'JSXExpressionContainer') {
var expression = propValue.expression;
if (expression.type === 'Identifier' && expression.name === 'undefined') return false;
if (expression.type === 'JSXText') return false;
}
return true;
};
var _default = exports["default"] = isNonLiteralProperty;
module.exports = exports.default;

View File

@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _jsxAstUtils = require("jsx-ast-utils");
var presentationRoles = new Set(['presentation', 'none']);
var isPresentationRole = function isPresentationRole(tagName, attributes) {
return presentationRoles.has((0, _jsxAstUtils.getLiteralPropValue)((0, _jsxAstUtils.getProp)(attributes, 'role')));
};
var _default = exports["default"] = isPresentationRole;
module.exports = exports.default;

Some files were not shown because too many files have changed in this diff Show More