17
17
* under the License.
18
18
*/
19
19
20
- import dedent from 'dedent' ;
21
20
import { RuleTester } from '@typescript-eslint/rule-tester' ;
22
21
import { NoUnnamedInteractiveElement } from './no_unnamed_interactive_element' ;
23
22
24
- const ruleTester = new RuleTester ( { } ) ;
25
- // Set the parser for RuleTester
26
- // @ts -ignore
27
- ruleTester . parser = require . resolve ( '@typescript-eslint/parser' ) ;
23
+ const ruleTester = new RuleTester ( ) ;
24
+
25
+ // Enable JSX for each snippet
26
+ const languageOptions = {
27
+ parserOptions : {
28
+ ecmaFeatures : {
29
+ jsx : true ,
30
+ } ,
31
+ } ,
32
+ } ;
28
33
29
34
ruleTester . run ( 'NoUnnamedInteractiveElement' , NoUnnamedInteractiveElement , {
30
35
valid : [
31
36
// Components with allowed a11y props
32
- { code : '<EuiBetaBadge aria-label="Beta badge" />' } ,
33
- { code : '<EuiButtonEmpty aria-labelledby="btnLabel" />' } ,
34
- { code : '<EuiButtonIcon aria-label="Icon" />' } ,
35
- { code : '<EuiComboBox label="Combo label" />' } ,
36
- { code : '<EuiSelect aria-label="Select label" />' } ,
37
- { code : '<EuiSelectWithWidth label="SelectWithWidth label" />' } ,
38
- { code : '<EuiSuperSelect aria-labelledby="superLabel" />' } ,
39
- { code : '<EuiPagination label="Pagination label" />' } ,
40
- { code : '<EuiTreeView label="TreeView label" />' } ,
41
- { code : '<EuiBreadcrumbs aria-label="Breadcrumbs label" />' } ,
37
+ { code : '<EuiBetaBadge aria-label="Beta badge" />' , languageOptions } ,
38
+ { code : '<EuiButtonEmpty aria-labelledby="btnLabel" />' , languageOptions } ,
39
+ { code : '<EuiButtonIcon aria-label="Icon" />' , languageOptions } ,
40
+ { code : '<EuiComboBox aria-label="Combo label" />' , languageOptions } ,
41
+ { code : '<EuiSelect aria-label="Select label" />' , languageOptions } ,
42
+ {
43
+ code : '<EuiSelectWithWidth aria-label="SelectWithWidth label" />' ,
44
+ languageOptions,
45
+ } ,
46
+ {
47
+ code : '<EuiSuperSelect aria-labelledby="superLabel" />' ,
48
+ languageOptions,
49
+ } ,
50
+ {
51
+ code : '<EuiPagination aria-label="Pagination label" />' ,
52
+ languageOptions,
53
+ } ,
54
+ { code : '<EuiTreeView aria-label="TreeView label" />' , languageOptions } ,
55
+ {
56
+ code : '<EuiBreadcrumbs aria-label="Breadcrumbs label" />' ,
57
+ languageOptions,
58
+ } ,
42
59
// Wrapped in EuiFormRow with label
43
- { code : '<EuiFormRow label="Row label"><EuiComboBox /></EuiFormRow>' } ,
44
- { code : '<EuiFormRow label="Row label"><EuiSelect /></EuiFormRow>' } ,
60
+ {
61
+ code : '<EuiFormRow label="Row label"><EuiComboBox /></EuiFormRow>' ,
62
+ languageOptions,
63
+ } ,
64
+ {
65
+ code : '<EuiFormRow label="Row label"><EuiSelect /></EuiFormRow>' ,
66
+ languageOptions,
67
+ } ,
45
68
] ,
46
69
invalid : [
47
70
// Missing a11y prop for interactive components
48
71
{
49
72
code : '<EuiBetaBadge />' ,
73
+ languageOptions,
50
74
errors : [ { messageId : 'missingA11y' } ] ,
51
75
} ,
52
76
{
53
77
code : '<EuiButtonEmpty />' ,
78
+ languageOptions,
54
79
errors : [ { messageId : 'missingA11y' } ] ,
55
80
} ,
56
81
{
57
82
code : '<EuiButtonIcon />' ,
83
+ languageOptions,
58
84
errors : [ { messageId : 'missingA11y' } ] ,
59
85
} ,
60
86
{
61
87
code : '<EuiComboBox />' ,
88
+ languageOptions,
62
89
errors : [ { messageId : 'missingA11y' } ] ,
63
90
} ,
64
91
{
65
92
code : '<EuiSelect />' ,
93
+ languageOptions,
66
94
errors : [ { messageId : 'missingA11y' } ] ,
67
95
} ,
68
96
{
69
97
code : '<EuiSelectWithWidth />' ,
98
+ languageOptions,
70
99
errors : [ { messageId : 'missingA11y' } ] ,
71
100
} ,
72
101
{
73
102
code : '<EuiSuperSelect />' ,
103
+ languageOptions,
74
104
errors : [ { messageId : 'missingA11y' } ] ,
75
105
} ,
76
106
{
77
107
code : '<EuiPagination />' ,
108
+ languageOptions,
78
109
errors : [ { messageId : 'missingA11y' } ] ,
79
110
} ,
80
111
{
81
112
code : '<EuiTreeView />' ,
113
+ languageOptions,
82
114
errors : [ { messageId : 'missingA11y' } ] ,
83
115
} ,
84
116
{
85
117
code : '<EuiBreadcrumbs />' ,
118
+ languageOptions,
86
119
errors : [ { messageId : 'missingA11y' } ] ,
87
120
} ,
88
121
// Wrapped but missing label
89
122
{
90
123
code : '<EuiFormRow><EuiComboBox /></EuiFormRow>' ,
124
+ languageOptions,
91
125
errors : [ { messageId : 'missingA11y' } ] ,
92
126
} ,
93
127
{
94
128
code : '<EuiFormRow><EuiSelect /></EuiFormRow>' ,
129
+ languageOptions,
95
130
errors : [ { messageId : 'missingA11y' } ] ,
96
131
} ,
97
132
] ,
98
- } ) ;
133
+ } ) ;
0 commit comments