Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
JSXAttribute: function JSXAttribute(attribute) {
var name = (0, _jsxAstUtils.propName)(attribute).toLowerCase();
if (name !== 'role') {
return;
}
var type = (0, _jsxAstUtils.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 (0, _toConsumableArray2["default"])(_ariaQuery.roles.keys()).indexOf(val) > -1;
}); // Check semantic DOM elements
JSXAttribute: function JSXAttribute(attribute) {
var name = (0, _jsxAstUtils.propName)(attribute).toLowerCase();
if (name !== 'role') {
return;
}
var type = (0, _jsxAstUtils.elementType)(attribute.parent);
if (!_ariaQuery.dom.get(type)) {
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 normalizedValues = String(value).toLowerCase().split(' ');
var validRoles = normalizedValues.filter(function (val) {
return [].concat(_toConsumableArray(_ariaQuery.roles.keys())).indexOf(val) > -1;
});
var _isHiddenFromScreenReader = _interopRequireDefault(require("../util/isHiddenFromScreenReader"));
var _isInteractiveElement = _interopRequireDefault(require("../util/isInteractiveElement"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
/**
* @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 domElements = (0, _toConsumableArray2["default"])(_ariaQuery.dom.keys());
module.exports = {
meta: {
docs: {
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/click-events-have-key-events.md'
},
schema: [schema]
},
create: function create(context) {
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var props = node.attributes;
if ((0, _jsxAstUtils.getProp)(props, 'onclick') === undefined) {
return;
}
JSXAttribute: function JSXAttribute(node) {
var name = (0, _jsxAstUtils.propName)(node);
if (name && name.toUpperCase() !== 'SCOPE') {
return;
}
var parent = node.parent;
var tagName = (0, _jsxAstUtils.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
});
}
};
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 = (0, _jsxAstUtils.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) {
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 = (0, _jsxAstUtils.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.
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } /**
* @fileoverview Enforce static elements have no interactive handlers.
* @author Ethan Cohen
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Static HTML elements with event handlers require a role.';
var domElements = [].concat(_toConsumableArray(_ariaQuery.dom.keys()));
var defaultInteractiveProps = [].concat(_toConsumableArray(_jsxAstUtils.eventHandlersByType.focus), _toConsumableArray(_jsxAstUtils.eventHandlersByType.keyboard), _toConsumableArray(_jsxAstUtils.eventHandlersByType.mouse));
var schema = (0, _schemas.generateObjSchema)({
handlers: _schemas.arraySchema
});
module.exports = {
meta: {
docs: {},
schema: [schema]
},
create: function create(context) {
var options = context.options;
return {
JSXOpeningElement: function JSXOpeningElement(node) {
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 = (0, _jsxAstUtils.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.
var _axobjectQuery = require('axobject-query');
var _arrayIncludes = require('array-includes');
var _arrayIncludes2 = _interopRequireDefault(_arrayIncludes);
var _attributesComparator = require('./attributesComparator');
var _attributesComparator2 = _interopRequireDefault(_attributesComparator);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var domKeys = [].concat(_toConsumableArray(_ariaQuery.dom.keys()));
var roleKeys = [].concat(_toConsumableArray(_ariaQuery.roles.keys()));
var elementRoleEntries = [].concat(_toConsumableArray(_ariaQuery.elementRoles));
var nonInteractiveRoles = new Set(roleKeys.filter(function (name) {
var role = _ariaQuery.roles.get(name);
return !role.abstract && !role.superClass.some(function (classes) {
return (0, _arrayIncludes2.default)(classes, 'widget');
});
}));
var interactiveRoles = new Set([].concat(roleKeys,
// 'toolbar' does not descend from widget, but it does support
// aria-activedescendant, thus in practice we treat it as a widget.
'toolbar').filter(function (name) {
var role = _ariaQuery.roles.get(name);
return !role.abstract && role.superClass.some(function (classes) {
var _isNonInteractiveRole = _interopRequireDefault(require("../util/isNonInteractiveRole"));
var _isNonLiteralProperty = _interopRequireDefault(require("../util/isNonLiteralProperty"));
var _isPresentationRole = _interopRequireDefault(require("../util/isPresentationRole"));
/**
* @fileoverview Enforce static elements have no interactive handlers.
* @author Ethan Cohen
*
*/
// ----------------------------------------------------------------------------
// Rule Definition
// ----------------------------------------------------------------------------
var errorMessage = 'Static HTML elements with event handlers require a role.';
var domElements = (0, _toConsumableArray2["default"])(_ariaQuery.dom.keys());
var defaultInteractiveProps = [].concat((0, _toConsumableArray2["default"])(_jsxAstUtils.eventHandlersByType.focus), (0, _toConsumableArray2["default"])(_jsxAstUtils.eventHandlersByType.keyboard), (0, _toConsumableArray2["default"])(_jsxAstUtils.eventHandlersByType.mouse));
var schema = (0, _schemas.generateObjSchema)({
handlers: _schemas.arraySchema
});
module.exports = {
meta: {
docs: {
url: 'https://github.com/evcohen/eslint-plugin-jsx-a11y/tree/master/docs/rules/no-static-element-interactions.md'
},
schema: [schema]
},
create: function create(context) {
var options = context.options;
return {
JSXOpeningElement: function JSXOpeningElement(node) {
var attributes = node.attributes;