eslint-plugin-smarthr 0.3.2 → 0.3.3
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,13 @@
|
|
|
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.3.3](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.3.2...v0.3.3) (2023-07-10)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* a11y-heading-in-sectioning-contentのHeadingアウトライン未指定の誤検知を修正する ([#65](https://github.com/kufu/eslint-plugin-smarthr/issues/65)) ([2cbf6aa](https://github.com/kufu/eslint-plugin-smarthr/commit/2cbf6aaff61f7846a80a895ed4e5e63ff9674c87))
|
|
11
|
+
|
|
5
12
|
### [0.3.2](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.3.1...v0.3.2) (2023-07-07)
|
|
6
13
|
|
|
7
14
|
|
package/package.json
CHANGED
|
@@ -10,6 +10,7 @@ const EXPECTED_NAMES = {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const headingRegex = /((^h(1|2|3|4|5|6))|Heading)$/
|
|
13
|
+
const declaratorHeadingRegex = /Heading$/
|
|
13
14
|
const sectioningRegex = /((A(rticle|side))|Nav|Section|^SectioningFragment)$/
|
|
14
15
|
const bareTagRegex = /^(article|aside|nav|section)$/
|
|
15
16
|
const messagePrefix = 'Headingと紐づく内容の範囲(アウトライン)が曖昧になっています。'
|
|
@@ -37,6 +38,11 @@ const searchBubbleUp = (node) => {
|
|
|
37
38
|
return node
|
|
38
39
|
}
|
|
39
40
|
|
|
41
|
+
// Headingコンポーネントの拡張なので対象外
|
|
42
|
+
if (node.type === 'VariableDeclarator' && node.id.name.match(declaratorHeadingRegex)) {
|
|
43
|
+
return null
|
|
44
|
+
}
|
|
45
|
+
|
|
40
46
|
return searchBubbleUp(node.parent)
|
|
41
47
|
}
|
|
42
48
|
|
|
@@ -82,27 +88,30 @@ module.exports = {
|
|
|
82
88
|
})
|
|
83
89
|
} else if (elementName.match(headingRegex)) {
|
|
84
90
|
const result = searchBubbleUp(node.parent)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
91
|
+
|
|
92
|
+
if (result) {
|
|
93
|
+
const saved = sections.find((s) => s[0] === result)
|
|
94
|
+
|
|
95
|
+
// HINT: 最初の1つ目は通知しない()
|
|
96
|
+
if (!saved) {
|
|
97
|
+
sections.push([result, node])
|
|
98
|
+
} else {
|
|
99
|
+
// HINT: 同じファイルで同じSectioningContent or トップノードを持つ場合
|
|
100
|
+
const [section, unreport] = saved
|
|
101
|
+
const targets = unreport ? [unreport, node] : [node]
|
|
102
|
+
|
|
103
|
+
saved[1] = undefined
|
|
104
|
+
|
|
105
|
+
targets.forEach((n) => {
|
|
106
|
+
context.report({
|
|
107
|
+
node: n,
|
|
108
|
+
message:
|
|
109
|
+
section.type === 'Program'
|
|
110
|
+
? rootMessage
|
|
111
|
+
: commonMessage,
|
|
112
|
+
})
|
|
104
113
|
})
|
|
105
|
-
}
|
|
114
|
+
}
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
117
|
},
|
|
@@ -37,6 +37,7 @@ ruleTester.run('a11y-heading-in-sectioning-content', rule, {
|
|
|
37
37
|
{ code: '<><Heading>hoge</Heading><Article><Heading>hoge</Heading></Article></>' },
|
|
38
38
|
{ code: '<><Heading>hoge</Heading><Nav><Heading>hoge</Heading></Nav></>' },
|
|
39
39
|
{ code: '<><Heading>hoge</Heading><SectioningFragment><Heading>hoge</Heading></SectioningFragment></>' },
|
|
40
|
+
{ code: 'const HogeHeading = () => <FugaHeading anyArg={abc}>hoge</FugaHeading>;const FugaHeading = () => <AbcHeading anyArg={abc}>hoge</AbcHeading>' },
|
|
40
41
|
],
|
|
41
42
|
invalid: [
|
|
42
43
|
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
@@ -62,5 +63,6 @@ ruleTester.run('a11y-heading-in-sectioning-content', rule, {
|
|
|
62
63
|
{ code: '<aside>hoge</aside>', errors: [ { message: `"aside"を利用せず、smarthr-ui/Asideを拡張してください。Headingのレベルが自動計算されるようになります。` } ] },
|
|
63
64
|
{ code: '<nav>hoge</nav>', errors: [ { message: `"nav"を利用せず、smarthr-ui/Navを拡張してください。Headingのレベルが自動計算されるようになります。` } ] },
|
|
64
65
|
{ code: '<section>hoge</section>', errors: [ { message: `"section"を利用せず、smarthr-ui/Sectionを拡張してください。Headingのレベルが自動計算されるようになります。` } ] },
|
|
66
|
+
{ code: 'const Hoge = () => <FugaHeading anyArg={abc}>hoge</FugaHeading>;const Fuga = () => <AbcHeading anyArg={abc}>hoge</AbcHeading>', errors: [ { message: rootMessage }, { message: rootMessage } ] },
|
|
65
67
|
],
|
|
66
68
|
});
|