eslint-plugin-smarthr 0.2.19 → 0.2.21
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 +14 -0
- package/libs/format_styled_components.js +55 -52
- package/package.json +1 -1
- package/rules/a11y-input-has-name-attribute/index.js +1 -0
- package/test/a11y-clickable-element-has-text.js +8 -1
- package/test/a11y-image-has-alt-attribute.js +1 -1
- package/test/a11y-input-has-name-attribute.js +1 -1
- package/test/a11y-prohhibit-input-placeholder.js +2 -2
- package/test/a11y-trigger-has-button.js +1 -1
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.2.21](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.20...v0.2.21) (2023-01-19)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
* a11y系ruleのコンポーネント名チェックが漏れているパターンが存在したため調整 ([#56](https://github.com/kufu/eslint-plugin-smarthr/issues/56)) ([e628426](https://github.com/kufu/eslint-plugin-smarthr/commit/e628426596e97548580780632046c2154583af3e))
|
|
11
|
+
|
|
12
|
+
### [0.2.20](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.19...v0.2.20) (2023-01-18)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* a11y-input-has-name-attribute を DropZoneも対象になるように修正 ([#55](https://github.com/kufu/eslint-plugin-smarthr/issues/55)) ([73c30ce](https://github.com/kufu/eslint-plugin-smarthr/commit/73c30ce350e69c72e00112994a3cbe9cbbcfc52c))
|
|
18
|
+
|
|
5
19
|
### [0.2.19](https://github.com/kufu/eslint-plugin-smarthr/compare/v0.2.18...v0.2.19) (2023-01-17)
|
|
6
20
|
|
|
7
21
|
|
|
@@ -1,68 +1,71 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
return null
|
|
4
|
-
}
|
|
1
|
+
const STYLED_COMPONENTS_METHOD = 'styled'
|
|
2
|
+
const STYLED_COMPONENTS = `${STYLED_COMPONENTS_METHOD}-components`
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
const getBaseComponentName = (node) => {
|
|
9
|
-
if (!node) {
|
|
10
|
-
return null
|
|
11
|
-
}
|
|
4
|
+
const findInvalidImportNameNode = (s) => s.type === 'ImportDefaultSpecifier' && s.local.name !== STYLED_COMPONENTS_METHOD
|
|
12
5
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return node.arguments[0].name
|
|
16
|
-
}
|
|
17
|
-
if (node.callee.object?.name === 'styled') {
|
|
18
|
-
return node.callee.property.name
|
|
19
|
-
}
|
|
20
|
-
}
|
|
6
|
+
const generateTagFormatter = ({ context, EXPECTED_NAMES }) => {
|
|
7
|
+
const entriesesTagNames = Object.entries(EXPECTED_NAMES).map(([b, e]) => [ new RegExp(b), new RegExp(e) ])
|
|
21
8
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
9
|
+
return {
|
|
10
|
+
ImportDeclaration: (node) => {
|
|
11
|
+
if (node.source.value !== STYLED_COMPONENTS) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
}
|
|
15
|
+
const invalidNameNode = node.specifiers.find(findInvalidImportNameNode)
|
|
28
16
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
17
|
+
if (invalidNameNode) {
|
|
18
|
+
context.report({
|
|
19
|
+
node: invalidNameNode,
|
|
20
|
+
message: `${STYLED_COMPONENTS} をimportする際は、名称が"${STYLED_COMPONENTS_METHOD}" となるようにしてください。例: "import ${STYLED_COMPONENTS_METHOD} from '${STYLED_COMPONENTS}'"`,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
VariableDeclarator: (node) => {
|
|
25
|
+
if (!node.init) {
|
|
26
|
+
return
|
|
27
|
+
}
|
|
34
28
|
|
|
35
|
-
|
|
29
|
+
const tag = node.init.tag || node.init
|
|
36
30
|
|
|
37
|
-
|
|
38
|
-
context.report({
|
|
39
|
-
node: invalidNameNode,
|
|
40
|
-
message: "styled-components をimportする際は、名称が`styled` となるようにしてください。例: `import styled from 'styled-components'`",
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
TaggedTemplateExpression: (node) => {
|
|
45
|
-
const extended = getExtendedComponentName(node)
|
|
31
|
+
let base = null
|
|
46
32
|
|
|
47
|
-
|
|
48
|
-
|
|
33
|
+
if (tag.object?.name === STYLED_COMPONENTS_METHOD) {
|
|
34
|
+
base = tag.property.name
|
|
35
|
+
} else if (tag.callee) {
|
|
36
|
+
const callee = tag.callee
|
|
37
|
+
|
|
38
|
+
switch (STYLED_COMPONENTS_METHOD) {
|
|
39
|
+
case callee.name: {
|
|
40
|
+
const arg = tag.arguments[0]
|
|
41
|
+
base = arg.name || arg.value
|
|
42
|
+
break
|
|
43
|
+
}
|
|
44
|
+
case callee.callee?.name: {
|
|
45
|
+
const arg = callee.arguments[0]
|
|
46
|
+
base = arg.name || arg.value
|
|
47
|
+
break
|
|
48
|
+
}
|
|
49
|
+
case callee.object?.name:
|
|
50
|
+
base = callee.property.name
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
}
|
|
49
54
|
|
|
50
55
|
if (base) {
|
|
51
|
-
|
|
52
|
-
if (base.match(new RegExp(b))) {
|
|
53
|
-
const extendedregex = new RegExp(e)
|
|
56
|
+
const extended = node.id.name
|
|
54
57
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
}
|
|
58
|
+
entriesesTagNames.forEach(([b, e]) => {
|
|
59
|
+
if (base.match(b) && !extended.match(e)) {
|
|
60
|
+
context.report({
|
|
61
|
+
node,
|
|
62
|
+
message: `${extended}を正規表現 "${e.toString()}" がmatchする名称に変更してください`,
|
|
63
|
+
});
|
|
61
64
|
}
|
|
62
65
|
})
|
|
63
66
|
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
+
},
|
|
68
|
+
}
|
|
69
|
+
}
|
|
67
70
|
|
|
68
71
|
module.exports = { generateTagFormatter }
|
package/package.json
CHANGED
|
@@ -9,6 +9,7 @@ const EXPECTED_NAMES = {
|
|
|
9
9
|
'Check(b|B)ox$': 'CheckBox$',
|
|
10
10
|
'Combo(b|B)ox$': 'ComboBox$',
|
|
11
11
|
'DatePicker$': 'DatePicker$',
|
|
12
|
+
'DropZone$': 'DropZone$',
|
|
12
13
|
}
|
|
13
14
|
const TARGET_TAG_NAME_REGEX = new RegExp(`(${Object.keys(EXPECTED_NAMES).join('|')})`)
|
|
14
15
|
const INPUT_NAME_REGEX = /^[a-zA-Z0-9_\[\]]+$/
|
|
@@ -27,6 +27,9 @@ ruleTester.run('a11y-clickable-element-has-text', rule, {
|
|
|
27
27
|
{ code: 'const HogeButton = styled(Button)``' },
|
|
28
28
|
{ code: 'const FugaAnchor = styled(HogeAnchor)``' },
|
|
29
29
|
{ code: 'const FugaSmartHRLogo = styled(SmartHRLogo)``' },
|
|
30
|
+
{ code: 'const HogeAnchor = styled.a(() => ``)' },
|
|
31
|
+
{ code: 'const HogeAnchor = styled("a")(() => ``)' },
|
|
32
|
+
{ code: 'const HogeAnchor = styled(Anchor)(() => ``)' },
|
|
30
33
|
{
|
|
31
34
|
code: `<a>ほげ</a>`,
|
|
32
35
|
},
|
|
@@ -110,7 +113,7 @@ ruleTester.run('a11y-clickable-element-has-text', rule, {
|
|
|
110
113
|
},
|
|
111
114
|
],
|
|
112
115
|
invalid: [
|
|
113
|
-
{ code: `import hoge from 'styled-components'`, errors: [ { message:
|
|
116
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
114
117
|
{ code: 'const Hoge = styled.a``', errors: [ { message: `Hogeを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
115
118
|
{ code: 'const Hoge = styled.button``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|
|
116
119
|
{ code: 'const Hoge = styled(Anchor)``', errors: [ { message: `Hogeを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
@@ -119,6 +122,10 @@ ruleTester.run('a11y-clickable-element-has-text', rule, {
|
|
|
119
122
|
{ code: 'const Fuga = styled(HogeAnchor)``', errors: [ { message: `Fugaを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
120
123
|
{ code: 'const Fuga = styled(HogeAnchor)``', errors: [ { message: `Fugaを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
121
124
|
{ code: 'const Fuga = styled(SmartHRLogo)``', errors: [ { message: `Fugaを正規表現 "/SmartHRLogo$/" がmatchする名称に変更してください` } ] },
|
|
125
|
+
{ code: 'const Piyo = styled.a(() => ``)', errors: [ { message: `Piyoを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
126
|
+
{ code: 'const Piyo = styled("a")(() => ``)', errors: [ { message: `Piyoを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
127
|
+
{ code: 'const Piyo = styled("a")``', errors: [ { message: `Piyoを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
128
|
+
{ code: 'const Piyo = styled(Anchor)(() => ``)', errors: [ { message: `Piyoを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
122
129
|
{
|
|
123
130
|
code: `<a><img src="hoge.jpg" /></a>`,
|
|
124
131
|
errors: [{ message: defaultErrorMessage }]
|
|
@@ -33,7 +33,7 @@ ruleTester.run('a11y-image-has-alt-attribute', rule, {
|
|
|
33
33
|
{ code: '<svg><image /></svg>' },
|
|
34
34
|
],
|
|
35
35
|
invalid: [
|
|
36
|
-
{ code: `import hoge from 'styled-components'`, errors: [ { message:
|
|
36
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
37
37
|
{ code: 'const Hoge = styled.img``', errors: [ { message: `Hogeを正規表現 "/(Img|Image|Icon)$/" がmatchする名称に変更してください` } ] },
|
|
38
38
|
{ code: 'const Hoge = styled.svg``', errors: [ { message: `Hogeを正規表現 "/(Img|Image|Icon)$/" がmatchする名称に変更してください` } ] },
|
|
39
39
|
{ code: 'const Hoge = styled(Icon)``', errors: [ { message: `Hogeを正規表現 "/Icon$/" がmatchする名称に変更してください` } ] },
|
|
@@ -33,7 +33,7 @@ ruleTester.run('a11y-input-has-name-attribute', rule, {
|
|
|
33
33
|
{ code: '<Select name="hoge[0][Fuga]" />' },
|
|
34
34
|
],
|
|
35
35
|
invalid: [
|
|
36
|
-
{ code: `import hoge from 'styled-components'`, errors: [ { message:
|
|
36
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
37
37
|
{ code: 'const Hoge = styled.input``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
|
|
38
38
|
{ code: 'const Hoge = styled.Input``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
|
|
39
39
|
{ code: 'const Hoge = styled(RadioButton)``', errors: [ { message: `Hogeを正規表現 "/RadioButton$/" がmatchする名称に変更してください` } ] },
|
|
@@ -43,14 +43,14 @@ ruleTester.run('a11y-prohibit-input-placeholder', rule, {
|
|
|
43
43
|
{ code: `<ComboBox placeholder="hoge" dropdownHelpMessage="fuga" />` },
|
|
44
44
|
],
|
|
45
45
|
invalid: [
|
|
46
|
-
{ code: `import hoge from 'styled-components'`, errors: [ { message:
|
|
46
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
47
47
|
{ code: 'const Hoge = styled.input``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
|
|
48
48
|
{ code: 'const Hoge = styled(StyledInput)``', errors: [ { message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` } ] },
|
|
49
49
|
{ code: 'const Hoge = styled.textarea``', errors: [ { message: `Hogeを正規表現 "/Textarea$/" がmatchする名称に変更してください` } ] },
|
|
50
50
|
{ code: 'const Hoge = styled(StyledTextarea)``', errors: [ { message: `Hogeを正規表現 "/Textarea$/" がmatchする名称に変更してください` } ] },
|
|
51
51
|
{ code: 'const Hoge = styled(FieldSet)``', errors: [ { message: `Hogeを正規表現 "/FieldSet$/" がmatchする名称に変更してください` } ] },
|
|
52
52
|
{ code: 'const Hoge = styled(ComboBox)``', errors: [ { message: `Hogeを正規表現 "/ComboBox$/" がmatchする名称に変更してください` } ] },
|
|
53
|
-
{
|
|
53
|
+
{
|
|
54
54
|
code: 'const Hoge = styled(SearchInput)``',
|
|
55
55
|
errors: [
|
|
56
56
|
{ message: `Hogeを正規表現 "/Input$/" がmatchする名称に変更してください` },
|
|
@@ -32,7 +32,7 @@ ruleTester.run('a11y-trigger-has-button', rule, {
|
|
|
32
32
|
{ code: '<DropdownTrigger>{hoge}</DropdownTrigger>' },
|
|
33
33
|
],
|
|
34
34
|
invalid: [
|
|
35
|
-
{ code: `import hoge from 'styled-components'`, errors: [ { message:
|
|
35
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: `styled-components をimportする際は、名称が"styled" となるようにしてください。例: "import styled from 'styled-components'"` } ] },
|
|
36
36
|
{ code: 'const Hoge = styled.button``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|
|
37
37
|
{ code: 'const Hoge = styled.a``', errors: [ { message: `Hogeを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
38
38
|
{ code: 'const Hoge = styled(Button)``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|