diff --git a/.changeset/soft-ravens-share.md b/.changeset/soft-ravens-share.md new file mode 100644 index 00000000..a7e389e3 --- /dev/null +++ b/.changeset/soft-ravens-share.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-primer-react": patch +--- + +fix: Link to should be allowed to have tooltip diff --git a/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js b/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js index a5e0e1dc..4c289376 100644 --- a/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js +++ b/src/rules/__tests__/a11y-tooltip-interactive-trigger.test.js @@ -67,6 +67,22 @@ ruleTester.run('non-interactive-tooltip-trigger', rule, { `, + ` + import {Tooltip, Link} from '@primer/react'; + + + Product + + + `, + ` + import {Tooltip, Link} from '@primer/react'; + + + Product + + + `, ], invalid: [ { diff --git a/src/rules/a11y-tooltip-interactive-trigger.js b/src/rules/a11y-tooltip-interactive-trigger.js index f252cd91..5ed70dc7 100644 --- a/src/rules/a11y-tooltip-interactive-trigger.js +++ b/src/rules/a11y-tooltip-interactive-trigger.js @@ -23,7 +23,7 @@ const isAnchorTag = el => { } const isJSXValue = attributes => { - const node = attributes.find(attribute => propName(attribute) === 'href') + const node = attributes.find(attribute => propName(attribute) === 'href' || propName(attribute)) const isJSXExpression = node.value.type === 'JSXExpressionContainer' && node && typeof getPropValue(node) === 'string' return isJSXExpression @@ -31,8 +31,14 @@ const isJSXValue = attributes => { const isInteractiveAnchor = child => { const hasHref = getJSXOpeningElementAttribute(child.openingElement, 'href') - if (!hasHref) return false - const href = getJSXOpeningElementAttribute(child.openingElement, 'href').value.value + const hasTo = getJSXOpeningElementAttribute(child.openingElement, 'to') + + if (!hasHref && !hasTo) return false + + const href = hasHref + ? getJSXOpeningElementAttribute(child.openingElement, 'href').value.value + : getJSXOpeningElementAttribute(child.openingElement, 'to').value.value + const hasJSXValue = isJSXValue(child.openingElement.attributes) const isAnchorInteractive = (typeof href === 'string' && href !== '') || hasJSXValue