From b05b0cb2556300bbc3787e1a9a9811972dd6e8cf Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Mon, 17 Jul 2023 19:17:06 +0000 Subject: [PATCH 1/3] Do not look up as prop --- lib/rules/a11y-no-title-attribute.js | 2 +- lib/utils/get-element-type.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/rules/a11y-no-title-attribute.js b/lib/rules/a11y-no-title-attribute.js index 83d61719..cc3ec1d0 100644 --- a/lib/rules/a11y-no-title-attribute.js +++ b/lib/rules/a11y-no-title-attribute.js @@ -50,7 +50,7 @@ module.exports = { create(context) { return { JSXElement: node => { - const elementType = getElementType(context, node.openingElement) + const elementType = getElementType(context, node.openingElement, true) if (elementType !== `iframe` && ifSemanticElement(context, node)) { const titleProp = getPropValue(getProp(node.openingElement.attributes, `title`)) if (titleProp) { diff --git a/lib/utils/get-element-type.js b/lib/utils/get-element-type.js index 29bff36b..16d7c07f 100644 --- a/lib/utils/get-element-type.js +++ b/lib/utils/get-element-type.js @@ -7,15 +7,19 @@ If a prop determines the type, it can be specified with `props`. For now, we only support the mapping of one prop type to an element type, rather than combinations of props. */ -function getElementType(context, node, ignoreMap = false) { +function getElementType(context, node, lazyElementCheck = false) { const {settings} = context + if (lazyElementCheck) { + return elementType(node) + } + // check if the node contains a polymorphic prop const polymorphicPropName = settings?.github?.polymorphicPropName ?? 'as' const rawElement = getLiteralPropValue(getProp(node.attributes, polymorphicPropName)) ?? elementType(node) // if a component configuration does not exists, return the raw element - if (ignoreMap || !settings?.github?.components?.[rawElement]) return rawElement + if (!settings?.github?.components?.[rawElement]) return rawElement const defaultComponent = settings.github.components[rawElement] From 29ead03f37a1fec710ad42159c09d504d078e2fb Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Mon, 17 Jul 2023 19:25:23 +0000 Subject: [PATCH 2/3] add test --- tests/a11y-no-title-attribute.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/tests/a11y-no-title-attribute.js b/tests/a11y-no-title-attribute.js index 3f620ea8..07b15922 100644 --- a/tests/a11y-no-title-attribute.js +++ b/tests/a11y-no-title-attribute.js @@ -30,7 +30,6 @@ ruleTester.run('a11y-no-title-attribute', rule, { }, }, { - // Note: we are only checking semantic elements. We cannot make assumptions about how a React Components is using the title prop. code: 'Submit', settings: { github: { @@ -40,20 +39,12 @@ ruleTester.run('a11y-no-title-attribute', rule, { }, }, }, + { // Note: we are only checking semantic elements. We cannot make assumptions about how a React Components is using the title prop. + code: 'Submit', + }, ], invalid: [ {code: 'GitHub', errors: [{message: errorMessage}]}, {code: '', errors: [{message: errorMessage}]}, - { - code: 'Submit', - errors: [{message: errorMessage}], - settings: { - github: { - components: { - Component: 'iframe', - }, - }, - }, - }, ], }) From ee9e16d01c2bc5f8fcae4f55d077d7d0180df72d Mon Sep 17 00:00:00 2001 From: Kendall Gassner Date: Mon, 17 Jul 2023 19:28:07 +0000 Subject: [PATCH 3/3] lint --- tests/a11y-no-title-attribute.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/a11y-no-title-attribute.js b/tests/a11y-no-title-attribute.js index 07b15922..f87f043f 100644 --- a/tests/a11y-no-title-attribute.js +++ b/tests/a11y-no-title-attribute.js @@ -30,6 +30,7 @@ ruleTester.run('a11y-no-title-attribute', rule, { }, }, { + // Note: we are only checking semantic elements. We cannot make assumptions about how a React Components is using the title prop. code: 'Submit', settings: { github: { @@ -39,7 +40,8 @@ ruleTester.run('a11y-no-title-attribute', rule, { }, }, }, - { // Note: we are only checking semantic elements. We cannot make assumptions about how a React Components is using the title prop. + { + // Note: we are only checking semantic elements. We cannot make assumptions about how a React Components is using the title prop. code: 'Submit', }, ],