From a4b8e6d1081b1e96ad574153805f86d5f7551c5e Mon Sep 17 00:00:00 2001 From: Mizoue Atsushi Date: Fri, 28 Jul 2023 14:13:57 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20a11y-heading-in-sectioning-content=20?= =?UTF-8?q?=E3=81=A7=20Heading=E7=B3=BB=E3=82=B3=E3=83=B3=E3=83=9D?= =?UTF-8?q?=E3=83=BC=E3=83=8D=E3=83=B3=E3=83=88=E3=81=AE=E6=8B=A1=E5=BC=B5?= =?UTF-8?q?=E3=82=92export=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B=E5=A0=B4?= =?UTF-8?q?=E5=90=88=E3=80=81=E6=AD=A3=E3=81=97=E3=81=8F=E9=99=A4=E5=A4=96?= =?UTF-8?q?=E3=81=95=E3=82=8C=E3=81=AA=E3=81=84=E3=83=90=E3=82=B0=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20(#67)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rules/a11y-heading-in-sectioning-content/index.js | 3 ++- test/a11y-heading-in-sectioning-content.js | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/rules/a11y-heading-in-sectioning-content/index.js b/rules/a11y-heading-in-sectioning-content/index.js index 86e770b..fe6fa3e 100644 --- a/rules/a11y-heading-in-sectioning-content/index.js +++ b/rules/a11y-heading-in-sectioning-content/index.js @@ -19,6 +19,7 @@ const bareTagRegex = /^(article|aside|nav|section)$/ const modelessDialogRegex = /ModelessDialog$/ const noHeadingTagNames = ['span', 'legend'] +const ignoreHeadingCheckParentType = ['Program', 'ExportNamedDeclaration'] const headingMessage = `smarthr-ui/Headingと紐づく内容の範囲(アウトライン)が曖昧になっています。 - smarthr-uiのArticle, Aside, Nav, SectionのいずれかでHeadingコンポーネントと内容をラップしてHeadingに対応する範囲を明確に指定してください。` @@ -48,7 +49,7 @@ const searchBubbleUp = (node) => { if ( // Headingコンポーネントの拡張なので対象外 - node.type === 'VariableDeclarator' && node.parent.parent?.type === 'Program' && node.id.name.match(declaratorHeadingRegex) || + node.type === 'VariableDeclarator' && ignoreHeadingCheckParentType.includes(node.parent.parent?.type) && node.id.name.match(declaratorHeadingRegex) || // ModelessDialogのheaderにHeadingを設定している場合も対象外 node.type === 'JSXAttribute' && node.name.name === 'header' && node.parent.name.name.match(modelessDialogRegex) ) { diff --git a/test/a11y-heading-in-sectioning-content.js b/test/a11y-heading-in-sectioning-content.js index 5250c7d..6b1d132 100644 --- a/test/a11y-heading-in-sectioning-content.js +++ b/test/a11y-heading-in-sectioning-content.js @@ -38,6 +38,7 @@ ruleTester.run('a11y-heading-in-sectioning-content', rule, { { code: '
hoge
' }, { code: '<>
hoge
fuga
' }, { code: 'const HogeHeading = () => hoge' }, + { code: 'export const HogeHeading = () => hoge' }, ], invalid: [ { code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },