eslint-plugin-smarthr 0.5.3 → 0.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [0.5.5](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.5.4...v0.5.5) (2024-03-29)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * a11y-heading-in-sectioning-contentでHeadingコンポーネントにtag属性を変数で設定した場合、jsエラーが起きるバグを修正 ([#130](https://github.com/kufu/eslint-plugin-smarthr/issues/130)) ([f927ecd](https://github.com/kufu/eslint-plugin-smarthr/commit/f927ecd80245f6976de9b561c07229cf3038f121))
11
+
12
+ ### [0.5.4](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.5.3...v0.5.4) (2024-03-29)
13
+
14
+
15
+ ### Features
16
+
17
+ * a11y-heading-in-sectioning-contentで title, もしくはheading属性がSectioningContent系コンポーネントに設定されている場合、headingがあると判定するように修正 ([#129](https://github.com/kufu/eslint-plugin-smarthr/issues/129)) ([93bbd19](https://github.com/kufu/eslint-plugin-smarthr/commit/93bbd1907cd7f28510dde1ddc93a16d0c92a2c9b))
18
+
5
19
  ### [0.5.3](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.5.2...v0.5.3) (2024-03-26)
6
20
 
7
21
 
package/README.md CHANGED
@@ -12,7 +12,9 @@
12
12
  - [a11y-prohibit-input-placeholder](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-prohibit-input-placeholder)
13
13
  - [a11y-prohibit-useless-sectioning-fragment](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-prohibit-useless-sectioning-fragment)
14
14
  - [a11y-trigger-has-button](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/a11y-trigger-has-button)
15
+ - [best-practice-for-button-element](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-button-element)
15
16
  - [best-practice-for-date](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-date)
17
+ - [best-practice-for-layouts](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-layouts)
16
18
  - [best-practice-for-remote-trigger-dialog](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/best-practice-for-remote-trigger-dialog)
17
19
  - [format-import-path](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/format-import-path)
18
20
  - [format-translate-component](https://github.com/kufu/eslint-plugin-smarthr/tree/main/rules/format-translate-component)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-smarthr",
3
- "version": "0.5.3",
3
+ "version": "0.5.5",
4
4
  "author": "SmartHR",
5
5
  "license": "MIT",
6
6
  "description": "A sharable ESLint plugin for SmartHR",
@@ -55,8 +55,10 @@ const asRegex = /^(as|forwardedAs)$/
55
55
  const ignoreCheckParentTypeRegex = /^(Program|ExportNamedDeclaration)$/
56
56
  const noHeadingTagNamesRegex = /^(span|legend)$/
57
57
  const ignoreHeadingCheckParentTypeRegex = /^(Program|ExportNamedDeclaration)$/
58
+ const headingAttributeRegex = /^(heading|title)$/
58
59
 
59
60
  const includeSectioningAsAttr = (a) => a.name?.name.match(asRegex) && bareTagRegex.test(a.value.value)
61
+ const findHeadingAttribute = (a) => headingAttributeRegex.test(a.name?.name || '')
60
62
 
61
63
  const headingMessage = `smarthr-ui/Headingと紐づく内容の範囲(アウトライン)が曖昧になっています。
62
64
  - smarthr-uiのArticle, Aside, Nav, SectionのいずれかでHeadingコンポーネントと内容をラップしてHeadingに対応する範囲を明確に指定してください。
@@ -191,7 +193,7 @@ const searchChildren = (n) => {
191
193
  } else if (
192
194
  (
193
195
  headingRegex.test(name) &&
194
- !n.openingElement.attributes.find(findTagAttr)?.value.value.match(noHeadingTagNamesRegex)
196
+ !n.openingElement.attributes.find(findTagAttr)?.value.value?.match(noHeadingTagNamesRegex)
195
197
  ) ||
196
198
  forInSearchChildren(n.openingElement.attributes)
197
199
  ) {
@@ -251,7 +253,7 @@ module.exports = {
251
253
  } else if (headingRegex.test(elementName)) {
252
254
  const tagAttr = node.attributes.find(findTagAttr)
253
255
 
254
- if (!tagAttr?.value.value.match(noHeadingTagNamesRegex)) {
256
+ if (!tagAttr?.value.value?.match(noHeadingTagNamesRegex)) {
255
257
  const result = searchBubbleUp(node.parent)
256
258
  let hit = false
257
259
 
@@ -298,6 +300,13 @@ module.exports = {
298
300
  }
299
301
  } else if (!node.selfClosing) {
300
302
  const isSection = sectioningRegex.test(elementName)
303
+
304
+ // HINT: SectioningContent系コンポーネントの拡張の場合、title, heading属性などにHeadingのテキストが仕込まれている場合がある
305
+ // 対象属性を持っている場合はcorrectとして扱う
306
+ if (isSection && node.attributes.some(findHeadingAttribute)) {
307
+ return
308
+ }
309
+
301
310
  const layoutSectionAsAttr = !isSection && layoutComponentRegex.test(elementName) ? node.attributes.find(includeSectioningAsAttr) : null
302
311
 
303
312
  if ((isSection || layoutSectionAsAttr) && !searchBubbleUpSections(node.parent.parent) && !forInSearchChildren(node.parent.children)) {
@@ -305,6 +314,7 @@ module.exports = {
305
314
  node,
306
315
  message: `${isSection ? elementName : `<${elementName} ${layoutSectionAsAttr.name.name}="${layoutSectionAsAttr.value.value}">`} はHeading要素を含んでいません。
307
316
  - SectioningContentはHeadingを含むようにマークアップする必要があります
317
+ - ${elementName}に設定しているいずれかの属性がHeading,もしくはHeadingのテキストに該当する場合、その属性の名称を ${headingAttributeRegex.toString()} にマッチする名称に変更してください
308
318
  - Headingにするべき適切な文字列が存在しない場合、 ${isSection ? `${elementName} は削除するか、SectioningContentではない要素に差し替えてください` : `${layoutSectionAsAttr.name.name}="${layoutSectionAsAttr.value.value}"を削除、もしくは別の要素に変更してください`}`,
309
319
  })
310
320
  }
@@ -24,6 +24,7 @@ const noTagAttrMessage = `tag属性を指定せず、smarthr-uiのArticle, Aside
24
24
  - tag属性を指定することで意図しないレベルに固定されてしまう可能性があります。`
25
25
  const notHaveHeadingMessage = (elementName) => `${elementName} はHeading要素を含んでいません。
26
26
  - SectioningContentはHeadingを含むようにマークアップする必要があります
27
+ - ${elementName}に設定しているいずれかの属性がHeading,もしくはHeadingのテキストに該当する場合、その属性の名称を /^(heading|title)$/ にマッチする名称に変更してください
27
28
  - Headingにするべき適切な文字列が存在しない場合、 ${elementName} は削除するか、SectioningContentではない要素に差し替えてください`
28
29
 
29
30
  ruleTester.run('a11y-heading-in-sectioning-content', rule, {
@@ -55,6 +56,9 @@ ruleTester.run('a11y-heading-in-sectioning-content', rule, {
55
56
  { code: 'const FugaStack = styled(HogeStack)``' },
56
57
  { code: '<PageHeading>hoge</PageHeading>' },
57
58
  { code: '<Section><Heading>hoge</Heading></Section>' },
59
+ { code: '<FugaSection heading={<Heading>hoge</Heading>}>abc</FugaSection>' },
60
+ { code: '<FugaSection heading="hoge">abc</FugaSection>' },
61
+ { code: '<FugaSection title="hoge">abc</FugaSection>' },
58
62
  { code: '<><Section><Heading>hoge</Heading></Section><Section><Heading>fuga</Heading></Section></>' },
59
63
  { code: 'const HogeHeading = () => <FugaHeading anyArg={abc}>hoge</FugaHeading>' },
60
64
  { code: 'export const HogeHeading = () => <FugaHeading anyArg={abc}>hoge</FugaHeading>' },
@@ -142,6 +146,6 @@ ruleTester.run('a11y-heading-in-sectioning-content', rule, {
142
146
  { code: '<Section><Heading tag="h2">hoge</Heading></Section>', errors: [ { message: noTagAttrMessage } ] },
143
147
  { code: '<Section></Section>', errors: [ { message: notHaveHeadingMessage('Section') } ] },
144
148
  { code: '<Aside><HogeSection></HogeSection></Aside>', errors: [ { message: notHaveHeadingMessage('Aside') }, { message: notHaveHeadingMessage('HogeSection') } ] },
145
- { code: '<Aside><HogeSection><Heading /></HogeSection></Aside>', errors: [ { message: notHaveHeadingMessage('Aside') } ] },
149
+ { code: '<Aside any="hoge"><HogeSection><Heading /></HogeSection></Aside>', errors: [ { message: notHaveHeadingMessage('Aside') } ] },
146
150
  ],
147
151
  });