From a2c198e61f3032bfb7feea1519cbcd5f9dec9d38 Mon Sep 17 00:00:00 2001 From: Vividha Date: Fri, 1 Jul 2022 08:34:02 +0000 Subject: [PATCH] added specific condition --- src/rules/no-static-element-interactions.js | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/rules/no-static-element-interactions.js b/src/rules/no-static-element-interactions.js index 431454789..57f67ab71 100644 --- a/src/rules/no-static-element-interactions.js +++ b/src/rules/no-static-element-interactions.js @@ -59,8 +59,6 @@ export default ({ const { attributes } = node; const type = elementType(node); - const roleProp = getPropValue(getProp(attributes, 'role')); - const { allowExpressionValues, handlers = defaultInteractiveProps, @@ -102,18 +100,19 @@ export default ({ allowExpressionValues === true && isNonLiteralProperty(attributes, 'role') ) { - // This rule has no opinion about non-literal roles. - return; - } - - if ( - roleProp === 'ConditionalExpression' - ) { - // if ( - // roleProp.consequent.type === 'Literal' && role.Prop.alternate.type === 'Literal' - // ) { - // return; - // } + //Special Case if role assignment is done using ternary operator + //with literals on both side + const rolePropVal = getPropValue(getProp(attributes, 'role')); + if (rolePropVal && rolePropVal.type === 'JSXExpressionContainer') { + if (rolePropVal.expression.type === 'ConditionalExpression') { + if ( + rolePropVal.expression.consequent.type === 'Literal' + && rolePropVal.expression.alternate.type === 'Literal' + ) { + return; + } + } + } return; }