eslint-plugin-smarthr 0.1.2 → 0.2.1
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/.github/CODEOWNERS +3 -0
- package/CHANGELOG.md +27 -0
- package/README.md +15 -489
- package/github/CODEOWNERS +3 -0
- package/index.js +3 -6
- package/libs/format_styled_components.js +57 -0
- package/package.json +1 -1
- package/rules/a11y-clickable-element-has-text/README.md +61 -0
- package/rules/a11y-clickable-element-has-text/index.js +71 -0
- package/rules/a11y-image-has-alt-attribute/README.md +55 -0
- package/rules/a11y-image-has-alt-attribute/index.js +48 -0
- package/rules/a11y-trigger-has-button/README.md +57 -0
- package/rules/a11y-trigger-has-button/index.js +74 -0
- package/rules/best-practice-for-date/README.md +40 -0
- package/rules/best-practice-for-date/index.js +42 -0
- package/rules/format-import-path/README.md +99 -0
- package/rules/{format-import-path.js → format-import-path/index.js} +2 -2
- package/rules/format-translate-component/README.md +58 -0
- package/rules/format-translate-component/index.js +97 -0
- package/rules/jsx-start-with-spread-attributes/README.md +31 -0
- package/rules/{jsx-start-with-spread-attributes.js → jsx-start-with-spread-attributes/index.js} +0 -0
- package/rules/no-import-other-domain/README.md +85 -0
- package/rules/{no-import-other-domain.js → no-import-other-domain/index.js} +2 -2
- package/rules/prohibit-export-array-type/README.md +28 -0
- package/rules/prohibit-export-array-type/index.js +28 -0
- package/rules/prohibit-file-name/README.md +35 -0
- package/rules/prohibit-file-name/index.js +61 -0
- package/rules/prohibit-import/README.md +44 -0
- package/rules/{prohibit-import.js → prohibit-import/index.js} +0 -0
- package/rules/redundant-name/README.md +94 -0
- package/rules/{redundant-name.js → redundant-name/index.js} +15 -5
- package/rules/require-barrel-import/README.md +39 -0
- package/rules/{require-barrel-import.js → require-barrel-import/index.js} +1 -1
- package/rules/require-export/README.md +43 -0
- package/rules/require-export/index.js +90 -0
- package/rules/require-import/README.md +51 -0
- package/rules/{require-import.js → require-import/index.js} +0 -0
- package/test/a11y-clickable-element-has-text.js +142 -0
- package/test/a11y-image-has-alt-attribute.js +44 -0
- package/test/a11y-trigger-has-button.js +50 -0
- package/test/best-practice-for-date.js +31 -0
- package/test/format-translate-component.js +37 -0
- package/test/prohibit-file-name.js +45 -0
- package/test/require-export.js +83 -0
- package/rules/a11y-icon-button-has-name.js +0 -56
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const rule = require('../rules/a11y-clickable-element-has-text')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 2018,
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
experimentalObjectRestSpread: true,
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const defaultErrorMessage = 'a, button要素にはテキストを設定してください。要素内にアイコン、画像のみを設置する場合はSmartHR UIのvisuallyHiddenText、通常のHTML要素にはaltなどの代替テキスト用属性を指定してください'
|
|
16
|
+
|
|
17
|
+
ruleTester.run('a11y-clickable-element-has-text', rule, {
|
|
18
|
+
valid: [
|
|
19
|
+
{ code: `import styled from 'styled-components'` },
|
|
20
|
+
{ code: `import styled, { css } from 'styled-components'` },
|
|
21
|
+
{ code: `import { css } from 'styled-components'` },
|
|
22
|
+
{ code: 'const HogeAnchor = styled.a``' },
|
|
23
|
+
{ code: 'const HogeLink = styled.a``' },
|
|
24
|
+
{ code: 'const HogeButton = styled.button``' },
|
|
25
|
+
{ code: 'const HogeAnchor = styled(Anchor)``' },
|
|
26
|
+
{ code: 'const HogeLink = styled(Link)``' },
|
|
27
|
+
{ code: 'const HogeButton = styled(Button)``' },
|
|
28
|
+
{ code: 'const FugaAnchor = styled(HogeAnchor)``' },
|
|
29
|
+
{
|
|
30
|
+
code: `<a>ほげ</a>`,
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
code: `<Link>ほげ</Link>`,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
code: `<HogeLink>ほげ</HogeLink>`,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
code: `<Anchor>ほげ</Anchor>`,
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
code: `<FugaAnchor>ほげ</FugaAnchor>`,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
code: `<AnchorButton>ほげ</AnchorButton>`,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
code: `<HogaAnchorButton>ほげ</HogaAnchorButton>`,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
code: `<Button>ほげ</Button>`,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
code: `<a />`,
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
code: `<button />`,
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
code: `<Anchor />`,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
code: `<Link />`,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
code: `<Button />`,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
code: `<HogeButton />`,
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
code: `<a><span>ほげ</span></a>`,
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
code: `<a><AnyComponent>ほげ</AnyComponent></a>`,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
code: `<a><img src="hoge.jpg" alt="ほげ" /></a>`,
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
code: `<a><Icon visuallyHiddenText="ほげ" /></a>`,
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
code: `<a><AnyComponent><Icon visuallyHiddenText="ほげ" /></AnyComponent></a>`,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
code: `<a>{any}</a>`,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
code: `<a><span>{any}</span></a>`,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
invalid: [
|
|
94
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: "styled-components をimportする際は、名称が`styled` となるようにしてください。例: `import styled from 'styled-components'`" } ] },
|
|
95
|
+
{ code: 'const Hoge = styled.a``', errors: [ { message: `Hogeを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
96
|
+
{ code: 'const Hoge = styled.button``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|
|
97
|
+
{ code: 'const Hoge = styled(Anchor)``', errors: [ { message: `Hogeを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
98
|
+
{ code: 'const Hoge = styled(Link)``', errors: [ { message: `Hogeを正規表現 "/Link$/" がmatchする名称に変更してください` } ] },
|
|
99
|
+
{ code: 'const Hoge = styled(Button)``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|
|
100
|
+
{ code: 'const Fuga = styled(HogeAnchor)``', errors: [ { message: `Fugaを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
101
|
+
{
|
|
102
|
+
code: `<a><img src="hoge.jpg" /></a>`,
|
|
103
|
+
errors: [{ message: defaultErrorMessage }]
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
code: `<a><Any /></a>`,
|
|
107
|
+
errors: [{ message: defaultErrorMessage }]
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
code: `<a><span><Any /></span></a>`,
|
|
111
|
+
errors: [{ message: defaultErrorMessage }]
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
code: `<a><img src="hoge.jpg" alt="" /></a>`,
|
|
115
|
+
errors: [{ message: defaultErrorMessage }]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
code: `<a><AnyComponent><Icon visuallyHiddenText="" /></AnyComponent></a>`,
|
|
119
|
+
errors: [{ message: defaultErrorMessage }]
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
code: `<button><img src="hoge.jpg" /></button>`,
|
|
123
|
+
errors: [{ message: defaultErrorMessage }]
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
code: `<button><Any /></button>`,
|
|
127
|
+
errors: [{ message: defaultErrorMessage }]
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
code: `<button><span><Any /></span></button>`,
|
|
131
|
+
errors: [{ message: defaultErrorMessage }]
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
code: `<button><img src="hoge.jpg" alt="" /></button>`,
|
|
135
|
+
errors: [{ message: defaultErrorMessage }]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
code: `<button><AnyComponent><Icon visuallyHiddenText="" /></AnyComponent></button>`,
|
|
139
|
+
errors: [{ message: defaultErrorMessage }]
|
|
140
|
+
},
|
|
141
|
+
]
|
|
142
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const rule = require('../rules/a11y-image-has-alt-attribute')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 2018,
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
experimentalObjectRestSpread: true,
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
ruleTester.run('a11y-image-has-alt-attribute', rule, {
|
|
16
|
+
valid: [
|
|
17
|
+
{ code: `import styled from 'styled-components'` },
|
|
18
|
+
{ code: `import styled, { css } from 'styled-components'` },
|
|
19
|
+
{ code: `import { css } from 'styled-components'` },
|
|
20
|
+
{ code: 'const HogeImg = styled.img``' },
|
|
21
|
+
{ code: 'const HogeImage = styled.img``' },
|
|
22
|
+
{ code: 'const HogeIcon = styled.img``' },
|
|
23
|
+
{ code: 'const HogeImg = styled.svg``' },
|
|
24
|
+
{ code: 'const HogeImage = styled.svg``' },
|
|
25
|
+
{ code: 'const HogeIcon = styled.svg``' },
|
|
26
|
+
{ code: 'const HogeImg = styled(Img)``' },
|
|
27
|
+
{ code: 'const HogeImage = styled(Image)``' },
|
|
28
|
+
{ code: 'const HogeIcon = styled(ICon)``' },
|
|
29
|
+
{ code: '<img alt="hoge" />' },
|
|
30
|
+
{ code: '<HogeImg alt="hoge" />' },
|
|
31
|
+
{ code: '<HogeImage alt="hoge" />' },
|
|
32
|
+
{ code: '<HogeIcon />' },
|
|
33
|
+
],
|
|
34
|
+
invalid: [
|
|
35
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: "styled-components をimportする際は、名称が`styled` となるようにしてください。例: `import styled from 'styled-components'`" } ] },
|
|
36
|
+
{ code: 'const Hoge = styled.img``', errors: [ { message: `Hogeを正規表現 "/(Img|Image|Icon)$/" がmatchする名称に変更してください` } ] },
|
|
37
|
+
{ code: 'const Hoge = styled.svg``', errors: [ { message: `Hogeを正規表現 "/(Img|Image|Icon)$/" がmatchする名称に変更してください` } ] },
|
|
38
|
+
{ code: 'const Hoge = styled(Icon)``', errors: [ { message: `Hogeを正規表現 "/Icon$/" がmatchする名称に変更してください` } ] },
|
|
39
|
+
{ code: 'const Hoge = styled(Img)``', errors: [ { message: `Hogeを正規表現 "/Img$/" がmatchする名称に変更してください` } ] },
|
|
40
|
+
{ code: 'const Hoge = styled(Image)``', errors: [ { message: `Hogeを正規表現 "/Image$/" がmatchする名称に変更してください` } ] },
|
|
41
|
+
{ code: '<img />', errors: [ { message: '画像にはalt属性を指定してください。SVG component の場合、altを属性として受け取れるようにした上で `<svg role="img" aria-label={alt}>` のように指定してください。画像ではない場合、img or image を末尾に持たない名称に変更してください。' } ] },
|
|
42
|
+
{ code: '<HogeImage alt="" />', errors: [ { message: '画像の情報をテキストにした代替テキスト(`alt`)を設定してください。装飾目的の画像など、alt属性に指定すべき文字がない場合は背景画像にすることを検討してください。' } ] },
|
|
43
|
+
]
|
|
44
|
+
})
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const rule = require('../rules/a11y-trigger-has-button')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 2018,
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
experimentalObjectRestSpread: true,
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
ruleTester.run('a11y-trigger-has-button', rule, {
|
|
16
|
+
valid: [
|
|
17
|
+
{ code: `import styled from 'styled-components'` },
|
|
18
|
+
{ code: `import styled, { css } from 'styled-components'` },
|
|
19
|
+
{ code: `import { css } from 'styled-components'` },
|
|
20
|
+
{ code: 'const HogeButton = styled.button``' },
|
|
21
|
+
{ code: 'const HogeAnchor = styled.a``' },
|
|
22
|
+
{ code: 'const HogeLink = styled.a``' },
|
|
23
|
+
{ code: 'const HogeButton = styled(Button)``' },
|
|
24
|
+
{ code: 'const HogeButtonAnchor = styled(ButtonAnchor)``' },
|
|
25
|
+
{ code: 'const HogeAnchorButton = styled(AnchorButton)``' },
|
|
26
|
+
{ code: 'const HogeLink = styled(FugaLink)``' },
|
|
27
|
+
{ code: 'const HogeAnchor = styled(FugaAnchor)``' },
|
|
28
|
+
{ code: 'const HogeDialogTrigger = styled(DialogTrigger)``' },
|
|
29
|
+
{ code: 'const HogeDropdownTrigger = styled(DropdownTrigger)``' },
|
|
30
|
+
{ code: '<DropdownTrigger><button>hoge</button></DropdownTrigger>' },
|
|
31
|
+
{ code: '<DialogTrigger><button>{hoge}</button></DialogTrigger>' },
|
|
32
|
+
{ code: '<DropdownTrigger>{hoge}</DropdownTrigger>' },
|
|
33
|
+
],
|
|
34
|
+
invalid: [
|
|
35
|
+
{ code: `import hoge from 'styled-components'`, errors: [ { message: "styled-components をimportする際は、名称が`styled` となるようにしてください。例: `import styled from 'styled-components'`" } ] },
|
|
36
|
+
{ code: 'const Hoge = styled.button``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|
|
37
|
+
{ code: 'const Hoge = styled.a``', errors: [ { message: `Hogeを正規表現 "/(Anchor|Link)$/" がmatchする名称に変更してください` } ] },
|
|
38
|
+
{ code: 'const Hoge = styled(Button)``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` } ] },
|
|
39
|
+
{ code: 'const Hoge = styled(AnchorButton)``', errors: [ { message: `Hogeを正規表現 "/Button$/" がmatchする名称に変更してください` },{ message: `Hogeを正規表現 "/AnchorButton$/" がmatchする名称に変更してください` } ] },
|
|
40
|
+
{ code: 'const Hoge = styled(ButtonAnchor)``', errors: [ { message: `Hogeを正規表現 "/ButtonAnchor$/" がmatchする名称に変更してください` }, { message: `Hogeを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
41
|
+
{ code: 'const Hoge = styled(Anchor)``', errors: [ { message: `Hogeを正規表現 "/Anchor$/" がmatchする名称に変更してください` } ] },
|
|
42
|
+
{ code: 'const Hoge = styled(Link)``', errors: [ { message: `Hogeを正規表現 "/Link$/" がmatchする名称に変更してください` } ] },
|
|
43
|
+
{ code: 'const Hoge = styled(DropdownTrigger)``', errors: [ { message: `Hogeを正規表現 "/DropdownTrigger$/" がmatchする名称に変更してください` } ] },
|
|
44
|
+
{ code: 'const Hoge = styled(DialogTrigger)``', errors: [ { message: `Hogeを正規表現 "/DialogTrigger$/" がmatchする名称に変更してください` } ] },
|
|
45
|
+
{ code: '<DropdownTrigger>ほげ</DropdownTrigger>', errors: [ { message: 'DropdownTrigger の直下にはbuttonコンポーネントのみ設置してください' } ] },
|
|
46
|
+
{ code: '<DialogTrigger><span><Button>ほげ</Button></span></DialogTrigger>', errors: [ { message: 'DialogTrigger の直下にはbuttonコンポーネントのみ設置してください' } ] },
|
|
47
|
+
{ code: '<DropdownTrigger><AnchorButton>ほげ</AnchorButton></DropdownTrigger>', errors: [ { message: 'DropdownTrigger の直下にはbuttonコンポーネントのみ設置してください' } ] },
|
|
48
|
+
{ code: '<DropdownTrigger><ButtonAnchor>ほげ</ButtonAnchor></DropdownTrigger>', errors: [ { message: 'DropdownTrigger の直下にはbuttonコンポーネントのみ設置してください' } ] },
|
|
49
|
+
]
|
|
50
|
+
})
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const rule = require('../rules/best-practice-for-date')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 2018,
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
experimentalObjectRestSpread: true,
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const errorNewDate = "'new Date(arg)' のように引数一つのみの指定方は実行環境により結果が変わる可能性があるため 'new Date(2022, 12 - 1, 31)' のようにparseするなど他の方法を検討してください。"
|
|
16
|
+
const errorDateParse = 'Date.parse は日付形式の解釈がブラウザによって異なるため、他の手段を検討してください'
|
|
17
|
+
|
|
18
|
+
ruleTester.run('best-practice-for-date', rule, {
|
|
19
|
+
valid: [
|
|
20
|
+
{ code: `new Date()` },
|
|
21
|
+
{ code: `new Date(2022, 11, 31)` },
|
|
22
|
+
{ code: `new Date('2022', '11', '31')` },
|
|
23
|
+
{ code: `const year = 2022; const month = 11; const date = 31; new Date(year, month, date)` },
|
|
24
|
+
],
|
|
25
|
+
invalid: [
|
|
26
|
+
{ code: 'new Date("2022/12/31")', errors: [ { message: errorNewDate } ] },
|
|
27
|
+
{ code: 'const arg = "2022/12/31"; new Date(arg)', errors: [ { message: errorNewDate } ] },
|
|
28
|
+
{ code: 'Date.parse("2022/12/31")', errors: [ { message: errorDateParse } ] },
|
|
29
|
+
{ code: 'const arg = "2022/12/31"; Date.parse(arg)', errors: [ { message: errorDateParse } ] },
|
|
30
|
+
]
|
|
31
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const rule = require('../rules/format-translate-component')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
ecmaVersion: 2018,
|
|
7
|
+
ecmaFeatures: {
|
|
8
|
+
experimentalObjectRestSpread: true,
|
|
9
|
+
jsx: true,
|
|
10
|
+
},
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const options = [
|
|
16
|
+
{
|
|
17
|
+
componentPath: '@/any/path/Translate',
|
|
18
|
+
componentName: 'Translate',
|
|
19
|
+
prohibitAttributies: ['data-translate'],
|
|
20
|
+
}
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
ruleTester.run('format-translate-component', rule, {
|
|
24
|
+
valid: [
|
|
25
|
+
{ code: '<Any data-wovn-enable="true">ほげ</Any>', options },
|
|
26
|
+
{ code: '<Translate>ほげ</Translate>', options },
|
|
27
|
+
{ code: '<Translate>ほげ<br />ふが</Translate>', options },
|
|
28
|
+
{ code: '<Translate>{any}</Translate>', options },
|
|
29
|
+
{ code: '<Translate dangerouslySetInnerHTML={{ __html: "ほげ" }} />', options },
|
|
30
|
+
],
|
|
31
|
+
invalid: [
|
|
32
|
+
{ code: '<Any data-translate="true">ほげ</Any>', options, errors: [ { message: 'data-translate 属性は使用せず、 @/any/path/Translate コンポーネントを利用してください' } ] },
|
|
33
|
+
{ code: '<Translate><Any>ほげ</Any></Translate>', options, errors: [ { message: 'Translate 内では <br /> 以外のタグは使えません' } ] },
|
|
34
|
+
{ code: '<Translate><Any /></Translate>', options, errors: [ { message: 'Translate 内では <br /> 以外のタグは使えません' } ] },
|
|
35
|
+
{ code: '<Translate></Translate>', options, errors: [ { message: 'Translate 内には必ずテキストを設置してください' } ] },
|
|
36
|
+
]
|
|
37
|
+
})
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const rule = require('../rules/prohibit-file-name')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
ecmaVersion: 2015
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
ruleTester.run('prohibit-file-name', rule, {
|
|
12
|
+
valid: [
|
|
13
|
+
{
|
|
14
|
+
code: 'const any = "code"',
|
|
15
|
+
filename: 'hoge.js',
|
|
16
|
+
options: [
|
|
17
|
+
{
|
|
18
|
+
'fuga\.js': 'any message.',
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
invalid: [
|
|
24
|
+
{
|
|
25
|
+
code: 'const any = "code"',
|
|
26
|
+
filename: 'hoge.js',
|
|
27
|
+
options: [
|
|
28
|
+
{
|
|
29
|
+
'hoge\.js': 'any message.',
|
|
30
|
+
}
|
|
31
|
+
],
|
|
32
|
+
errors: [{ message: 'any message.' }]
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
code: 'const any = "code"',
|
|
36
|
+
filename: 'hoge.js',
|
|
37
|
+
options: [
|
|
38
|
+
{
|
|
39
|
+
'(hoge|fuga)\.js': '$1.jsは作成しないで!',
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
errors: [{ message: 'hoge.jsは作成しないで!' }]
|
|
43
|
+
},
|
|
44
|
+
]
|
|
45
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const rule = require('../rules/require-export')
|
|
2
|
+
const RuleTester = require('eslint').RuleTester
|
|
3
|
+
|
|
4
|
+
const ruleTester = new RuleTester({
|
|
5
|
+
parserOptions: {
|
|
6
|
+
sourceType: 'module',
|
|
7
|
+
ecmaVersion: 2015
|
|
8
|
+
},
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
ruleTester.run('require-export', rule, {
|
|
12
|
+
valid: [
|
|
13
|
+
{
|
|
14
|
+
code: `const hoge = {}; export { hoge }`,
|
|
15
|
+
options: [
|
|
16
|
+
{
|
|
17
|
+
'^.+$': ['hoge'],
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
code: `const hoge = {}, fuga = {}; export { hoge, fuga }`,
|
|
23
|
+
options: [
|
|
24
|
+
{
|
|
25
|
+
'^.+$': ['hoge', 'fuga'],
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
code: `const hoge = {}, fuga = {}; export { hoge, fuga }`,
|
|
31
|
+
options: [
|
|
32
|
+
{
|
|
33
|
+
'^.+$': ['fuga'],
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
code: `export const hoge = {}`,
|
|
39
|
+
options: [
|
|
40
|
+
{
|
|
41
|
+
'^.+$': ['hoge'],
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
code: `const hoge = {}; export default hoge`,
|
|
47
|
+
options: [
|
|
48
|
+
{
|
|
49
|
+
'^.+$': ['default'],
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
invalid: [
|
|
55
|
+
{
|
|
56
|
+
code: `const hoge ={}; export { hoge }`,
|
|
57
|
+
options: [
|
|
58
|
+
{
|
|
59
|
+
'^.+$': ['fuga'],
|
|
60
|
+
}
|
|
61
|
+
],
|
|
62
|
+
errors: [{ message: 'fuga をexportしてください' }],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
code: `export const hoge = {}`,
|
|
66
|
+
options: [
|
|
67
|
+
{
|
|
68
|
+
'^.+$': ['fuga'],
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
errors: [{ message: 'fuga をexportしてください' }],
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
code: `const hoge = {}; export { hoge }`,
|
|
75
|
+
options: [
|
|
76
|
+
{
|
|
77
|
+
'^.+$': ['default'],
|
|
78
|
+
}
|
|
79
|
+
],
|
|
80
|
+
errors: [{ message: 'default をexportしてください' }],
|
|
81
|
+
},
|
|
82
|
+
]
|
|
83
|
+
})
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
meta: {
|
|
3
|
-
type: 'suggestion',
|
|
4
|
-
messages: {
|
|
5
|
-
'a11y-icon-button-has-name': '{{ message }}',
|
|
6
|
-
},
|
|
7
|
-
schema: [],
|
|
8
|
-
},
|
|
9
|
-
create(context) {
|
|
10
|
-
return {
|
|
11
|
-
JSXOpeningElement: (node) => {
|
|
12
|
-
if (!node.name.name || !node.name.name.match(/Button(Anchor)?$/)) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const children = node.parent.children.filter((c) => (
|
|
17
|
-
!(c.type === 'JSXText' && c.value.match(/^\s*\n+\s*$/))
|
|
18
|
-
))
|
|
19
|
-
|
|
20
|
-
if (children.length === 0) {
|
|
21
|
-
return
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
let existIcon = false
|
|
25
|
-
let existNoIcon = false
|
|
26
|
-
let targetNode = node
|
|
27
|
-
|
|
28
|
-
const child = children.find((c) => {
|
|
29
|
-
if (c.type === 'JSXElement' && c.openingElement.name.name.match(/Icon$/)) {
|
|
30
|
-
existIcon = true
|
|
31
|
-
targetNode = c
|
|
32
|
-
|
|
33
|
-
if (!existNoIcon) {
|
|
34
|
-
existNoIcon = c.openingElement.attributes.some((a) => a.name.name === 'visuallyHiddenText')
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
existNoIcon = true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return existIcon && !existNoIcon
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
if (child) {
|
|
44
|
-
context.report({
|
|
45
|
-
node: targetNode,
|
|
46
|
-
messageId: 'a11y-icon-button-has-name',
|
|
47
|
-
data: {
|
|
48
|
-
message: `Button 内に Icon のみを設置する場合、Icon に visuallyHiddenText props を指定してください`,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
}
|
|
54
|
-
},
|
|
55
|
-
}
|
|
56
|
-
module.exports.schema = []
|