Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"VAttribute" (node) {
const options = context.options[0] || {};
const ignoreNonDOM = !!options.ignoreNonDOM;
if (ignoreNonDOM) {
const type = utils.getElementType(node.parent.parent);
if (!dom.get(type)) {
return;
}
}
const isRole = utils.isAttribute(node, 'role')
if (!isRole) { return; }
const value = utils.getAttributeValue(node);
if (value === null || typeof value !== 'string') {
return;
}
const normalizedValues = String(value).toLowerCase().split(' ');
const validRoles = [...roles.keys()].filter(role => roles.get(role).abstract === false);
const isValid = normalizedValues.every(val => validRoles.indexOf(val) > -1);
if (isValid === true) { return; }
context.report({
"VStartTag" (node) {
const element = node.parent;
const type = utils.getElementType(element);
const role = utils.getRoleValue(element)
if (!role) {
return
}
if (!dom.get(type)) {
return;
}
const normalizedRoles = String(role).toLowerCase().split(' ');
const roleArray = [...roles.keys()];
const validRoles = normalizedRoles.filter(value => roleArray.indexOf(value) > -1)
validRoles.forEach((role) => {
const { requiredProps: requiredPropKeyValues } = roles.get(role);
const requiredProps = Object.keys(requiredPropKeyValues);
if (requiredProps.length > 0) {
const hasRequiredProps = requiredProps.every(prop => utils.getAttribute(element, prop) !== undefined)
if (!hasRequiredProps) {
context.report({
node,
message: errorMessage(role.toLowerCase(), requiredProps),
});
"VAttribute" (node) {
const isAutofocus = utils.isAttribute(node, 'autofocus')
if (!isAutofocus) {
return;
}
const options = context.options[0] || {};
const ignoreNonDOM = !!options.ignoreNonDOM;
if (ignoreNonDOM) {
const type = utils.getElementType(node.parent.parent);
if (!dom.get(type)) {
return;
}
}
context.report({
node,
loc: node.loc,
message: errorMessage
});
}
}, JsxRule.create(context))