-
-
Notifications
You must be signed in to change notification settings - Fork 211
Expand file tree
/
Copy pathtemplate-no-redundant-role.js
More file actions
303 lines (298 loc) · 11 KB
/
template-no-redundant-role.js
File metadata and controls
303 lines (298 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
const rule = require('../../../lib/rules/template-no-redundant-role');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-no-redundant-role', rule, {
valid: [
'<template><a role="link" aria-disabled="true">valid</a></template>',
'<template><form role="search"></form></template>',
'<template><footer role={{this.foo}}></footer></template>',
'<template><footer role="{{this.stuff}}{{this.foo}}"></footer></template>',
'<template><nav role="navigation"></nav></template>',
'<template><ol role="list"></ol></template>',
'<template><ul role="list"></ul></template>',
{
code: '<template><body role="document"></body></template>',
options: [{ checkAllHTMLElements: false }],
},
{
code: '<template><footer role={{this.bar}}></footer></template>',
options: [{ checkAllHTMLElements: true }],
},
{
code: '<template><nav class="navigation" role="navigation"></nav></template>',
options: [{ checkAllHTMLElements: true }],
},
{
code: '<template><button role="link"></button></template>',
options: [{ checkAllHTMLElements: true }],
},
{
code: '<template><input type="checkbox" value="yes" checked /></template>',
options: [{ checkAllHTMLElements: true }],
},
{
code: '<template><input type="range" /></template>',
options: [{ checkAllHTMLElements: false }],
},
{
code: '<template><dialog role="dialog" /></template>',
options: [{ checkAllHTMLElements: false }],
},
{
code: '<template><ul class="list" role="combobox"></ul></template>',
options: [{ checkAllHTMLElements: false }],
},
'<template><input role="combobox"></template>',
// <select multiple> has implicit role listbox, so combobox is not redundant.
'<template><select role="combobox" multiple></select></template>',
// <select size="5"> (size > 1) has implicit role listbox.
'<template><select role="combobox" size="5"></select></template>',
],
invalid: [
{
code: '<template><dialog role="dialog" /></template>',
output: '<template><dialog /></template>',
errors: [
{
message: 'Use of redundant or invalid role: dialog on <dialog> detected.',
},
],
},
{
code: '<template><header role="banner"></header></template>',
output: '<template><header></header></template>',
errors: [
{
message:
'Use of redundant or invalid role: banner on <header> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<template><main role="main"></main></template>',
output: '<template><main></main></template>',
errors: [
{
message:
'Use of redundant or invalid role: main on <main> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<template><aside role="complementary"></aside></template>',
output: '<template><aside></aside></template>',
errors: [
{
message:
'Use of redundant or invalid role: complementary on <aside> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<template><footer role="contentinfo"></footer></template>',
output: '<template><footer></footer></template>',
errors: [
{
message:
'Use of redundant or invalid role: contentinfo on <footer> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<template><form role="form"></form></template>',
output: '<template><form></form></template>',
errors: [
{
message:
'Use of redundant or invalid role: form on <form> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<template><header role="banner" class="page-header"></header></template>',
output: '<template><header class="page-header"></header></template>',
errors: [
{
message:
'Use of redundant or invalid role: banner on <header> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-no-redundant-role', rule, {
valid: [
'<a role="link" aria-disabled="true">valid</a>',
'<form role="search"></form>',
'<footer role={{this.foo}}></footer>',
'<footer role="{{this.stuff}}{{this.foo}}"></footer>',
'<nav role="navigation"></nav>',
'<ol role="list"></ol>',
'<ul role="list"></ul>',
'<input role="combobox">',
'<footer role={{this.bar}}></footer>',
'<nav class="navigation" role="navigation"></nav>',
'<button role="link"></button>',
'<input type="checkbox" value="yes" checked />',
'<input type="range" />',
{
code: '<body role="document"></body>',
options: [{ checkAllHTMLElements: false }],
},
{
code: '<dialog role="dialog" />',
options: [{ checkAllHTMLElements: false }],
},
'<ul class="list" role="combobox"></ul>',
// <select> with `multiple` has implicit role "listbox", so role="combobox"
// is not redundant (it disagrees with the implicit role, but that is for
// other rules to catch — this rule only flags redundancy).
'<select role="combobox" multiple></select>',
// <select size="5"> (size > 1) has implicit role "listbox", same reasoning.
'<select role="combobox" size="5"></select>',
],
invalid: [
{
code: '<header role="banner"></header>',
output: '<header></header>',
errors: [
{
message:
'Use of redundant or invalid role: banner on <header> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<footer role="contentinfo"></footer>',
output: '<footer></footer>',
errors: [
{
message:
'Use of redundant or invalid role: contentinfo on <footer> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<main role="main"></main>',
output: '<main></main>',
errors: [
{
message:
'Use of redundant or invalid role: main on <main> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<aside role="complementary"></aside>',
output: '<aside></aside>',
errors: [
{
message:
'Use of redundant or invalid role: complementary on <aside> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<form role="form"></form>',
output: '<form></form>',
errors: [
{
message:
'Use of redundant or invalid role: form on <form> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<header role="banner" class="page-header"></header>',
output: '<header class="page-header"></header>',
errors: [
{
message:
'Use of redundant or invalid role: banner on <header> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<dialog role="dialog" />',
output: '<dialog />',
errors: [{ message: 'Use of redundant or invalid role: dialog on <dialog> detected.' }],
},
{
code: '<button role="button"></button>',
output: '<button></button>',
errors: [{ message: 'Use of redundant or invalid role: button on <button> detected.' }],
},
{
code: '<input type="checkbox" name="agree" value="checkbox1" role="checkbox" />',
output: '<input type="checkbox" name="agree" value="checkbox1" />',
errors: [{ message: 'Use of redundant or invalid role: checkbox on <input> detected.' }],
},
{
code: '<table><th role="columnheader">Some heading</th><td>cell1</td></table>',
output: '<table><th>Some heading</th><td>cell1</td></table>',
errors: [{ message: 'Use of redundant or invalid role: columnheader on <th> detected.' }],
},
{
code: '<select name="color" id="color" role="listbox" multiple><option value="default-color">black</option></select>',
output:
'<select name="color" id="color" multiple><option value="default-color">black</option></select>',
errors: [{ message: 'Use of redundant or invalid role: listbox on <select> detected.' }],
},
{
// <select> without `multiple` or `size` defaults to role "combobox".
code: '<select role="combobox"></select>',
output: '<select></select>',
errors: [{ message: 'Use of redundant or invalid role: combobox on <select> detected.' }],
},
{
// size="1" still defaults to combobox (only size > 1 flips to listbox).
code: '<select role="combobox" size="1"></select>',
output: '<select size="1"></select>',
errors: [{ message: 'Use of redundant or invalid role: combobox on <select> detected.' }],
},
{
// Case-insensitive match on <select>, combined with the implicit-role check.
code: '<select role="COMBOBOX"></select>',
output: '<select></select>',
errors: [{ message: 'Use of redundant or invalid role: combobox on <select> detected.' }],
},
{
// Case-insensitive matching — ARIA role tokens compare as ASCII-case-insensitive.
code: '<body role="DOCUMENT"></body>',
output: '<body></body>',
errors: [{ message: 'Use of redundant or invalid role: document on <body> detected.' }],
},
{
code: '<main role="main"></main>',
output: '<main></main>',
options: [{ checkAllHTMLElements: false }],
errors: [
{
message:
'Use of redundant or invalid role: main on <main> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
{
code: '<aside role="complementary"></aside>',
output: '<aside></aside>',
options: [{ checkAllHTMLElements: false }],
errors: [
{
message:
'Use of redundant or invalid role: complementary on <aside> detected. If a landmark element is used, any role provided will either be redundant or incorrect.',
},
],
},
],
});