Skip to content

Commit 0546789

Browse files
NullVoxPopuliclaude
andcommitted
Fix role-to-context mapping to match original ember-template-lint rule
Align ROLES_REQUIRING_CONTEXT with the original require-context-role rule from ember-template-lint by: - Adding missing `cell` role (requires `row` context) - Removing `directory` from `listitem` parents (not in original) - Removing `group` from `option` and `menuitemcheckbox` parents (not in original) - Adding `grid` to `rowheader` parents (present in original) - Sorting parent arrays alphabetically to match the original's sorted output Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent b41b15a commit 0546789

2 files changed

Lines changed: 53 additions & 32 deletions

File tree

lib/rules/template-require-context-role.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
const ROLES_REQUIRING_CONTEXT = {
2-
listitem: ['list', 'group', 'directory'],
3-
option: ['listbox', 'group'],
2+
cell: ['row'],
3+
listitem: ['group', 'list'],
4+
option: ['listbox'],
45
tab: ['tablist'],
5-
menuitem: ['menu', 'menubar', 'group'],
6-
menuitemcheckbox: ['menu', 'menubar', 'group'],
7-
menuitemradio: ['menu', 'menubar', 'group'],
8-
treeitem: ['tree', 'group'],
9-
row: ['table', 'grid', 'treegrid', 'rowgroup'],
6+
menuitem: ['group', 'menu', 'menubar'],
7+
menuitemcheckbox: ['menu', 'menubar'],
8+
menuitemradio: ['group', 'menu', 'menubar'],
9+
treeitem: ['group', 'tree'],
10+
row: ['grid', 'rowgroup', 'table', 'treegrid'],
1011
rowgroup: ['grid', 'table', 'treegrid'],
11-
rowheader: ['row'],
12+
rowheader: ['grid', 'row'],
1213
columnheader: ['row'],
1314
gridcell: ['row'],
1415
};

tests/lib/rules/template-require-context-role.js

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ruleTester.run('template-require-context-role', rule, {
6464
'<template><div role="list">{{#each someList as |item|}}{{list-item item=item}}{{/each}}</div></template>',
6565
'<template><div role="list">{{#each someList as |item|}}<ListItem @item={{item}} />{{/each}}</div></template>',
6666
'<template><div role="list">{{#if this.show}}{{#each someList as |item|}}<ListItem @item={{item}} />{{/each}}{{/if}}</div></template>',
67+
'<template><div role="row"><div role="cell">One</div></div></template>',
6768
'<template><div role="table"><div role="row"><div role="cell">One</div></div></div></template>',
6869
`<template><typeahead.list role="list">
6970
<:content as |items|>
@@ -87,7 +88,7 @@ ruleTester.run('template-require-context-role', rule, {
8788
errors: [
8889
{
8990
message:
90-
'Role "listitem" must be contained in an element with one of these roles: list, group, directory',
91+
'Role "listitem" must be contained in an element with one of these roles: group, list',
9192
type: 'GlimmerElementNode',
9293
},
9394
],
@@ -116,7 +117,7 @@ ruleTester.run('template-require-context-role', rule, {
116117
errors: [
117118
{
118119
message:
119-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
120+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
120121
type: 'GlimmerElementNode',
121122
},
122123
],
@@ -128,7 +129,7 @@ ruleTester.run('template-require-context-role', rule, {
128129
errors: [
129130
{
130131
message:
131-
'Role "treeitem" must be contained in an element with one of these roles: tree, group',
132+
'Role "treeitem" must be contained in an element with one of these roles: group, tree',
132133
},
133134
],
134135
},
@@ -155,7 +156,7 @@ ruleTester.run('template-require-context-role', rule, {
155156
errors: [
156157
{
157158
message:
158-
'Role "listitem" must be contained in an element with one of these roles: list, group, directory',
159+
'Role "listitem" must be contained in an element with one of these roles: group, list',
159160
},
160161
],
161162
},
@@ -165,7 +166,7 @@ ruleTester.run('template-require-context-role', rule, {
165166
errors: [
166167
{
167168
message:
168-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
169+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
169170
},
170171
],
171172
},
@@ -175,7 +176,7 @@ ruleTester.run('template-require-context-role', rule, {
175176
errors: [
176177
{
177178
message:
178-
'Role "menuitemcheckbox" must be contained in an element with one of these roles: menu, menubar, group',
179+
'Role "menuitemcheckbox" must be contained in an element with one of these roles: menu, menubar',
179180
},
180181
],
181182
},
@@ -185,7 +186,7 @@ ruleTester.run('template-require-context-role', rule, {
185186
errors: [
186187
{
187188
message:
188-
'Role "menuitemradio" must be contained in an element with one of these roles: menu, menubar, group',
189+
'Role "menuitemradio" must be contained in an element with one of these roles: group, menu, menubar',
189190
},
190191
],
191192
},
@@ -195,7 +196,7 @@ ruleTester.run('template-require-context-role', rule, {
195196
errors: [
196197
{
197198
message:
198-
'Role "option" must be contained in an element with one of these roles: listbox, group',
199+
'Role "option" must be contained in an element with one of these roles: listbox',
199200
},
200201
],
201202
},
@@ -205,7 +206,7 @@ ruleTester.run('template-require-context-role', rule, {
205206
errors: [
206207
{
207208
message:
208-
'Role "row" must be contained in an element with one of these roles: table, grid, treegrid, rowgroup',
209+
'Role "row" must be contained in an element with one of these roles: grid, rowgroup, table, treegrid',
209210
},
210211
],
211212
},
@@ -224,7 +225,7 @@ ruleTester.run('template-require-context-role', rule, {
224225
output: null,
225226
errors: [
226227
{
227-
message: 'Role "rowheader" must be contained in an element with one of these roles: row',
228+
message: 'Role "rowheader" must be contained in an element with one of these roles: grid, row',
228229
},
229230
],
230231
},
@@ -241,7 +242,16 @@ ruleTester.run('template-require-context-role', rule, {
241242
errors: [
242243
{
243244
message:
244-
'Role "treeitem" must be contained in an element with one of these roles: tree, group',
245+
'Role "treeitem" must be contained in an element with one of these roles: group, tree',
246+
},
247+
],
248+
},
249+
{
250+
code: '<template><div><div role="cell">Item One</div></div></template>',
251+
output: null,
252+
errors: [
253+
{
254+
message: 'Role "cell" must be contained in an element with one of these roles: row',
245255
},
246256
],
247257
},
@@ -251,7 +261,7 @@ ruleTester.run('template-require-context-role', rule, {
251261
errors: [
252262
{
253263
message:
254-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
264+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
255265
},
256266
],
257267
},
@@ -261,7 +271,7 @@ ruleTester.run('template-require-context-role', rule, {
261271
errors: [
262272
{
263273
message:
264-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
274+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
265275
},
266276
],
267277
},
@@ -307,6 +317,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
307317
'<div role="list">{{#each someList as |item|}}{{list-item item=item}}{{/each}}</div>',
308318
'<div role="list">{{#each someList as |item|}}<ListItem @item={{item}} />{{/each}}</div>',
309319
'<div role="list">{{#if this.show}}{{#each someList as |item|}}<ListItem @item={{item}} />{{/each}}{{/if}}</div>',
320+
'<div role="row"><div role="cell">One</div></div>',
310321
'<div role="table"><div role="row"><div role="cell">One</div></div></div>',
311322
`<typeahead.list role="list">
312323
<:content as |items|>
@@ -325,7 +336,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
325336
errors: [
326337
{
327338
message:
328-
'Role "treeitem" must be contained in an element with one of these roles: tree, group',
339+
'Role "treeitem" must be contained in an element with one of these roles: group, tree',
329340
},
330341
],
331342
},
@@ -352,7 +363,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
352363
errors: [
353364
{
354365
message:
355-
'Role "listitem" must be contained in an element with one of these roles: list, group, directory',
366+
'Role "listitem" must be contained in an element with one of these roles: group, list',
356367
},
357368
],
358369
},
@@ -362,7 +373,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
362373
errors: [
363374
{
364375
message:
365-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
376+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
366377
},
367378
],
368379
},
@@ -372,7 +383,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
372383
errors: [
373384
{
374385
message:
375-
'Role "menuitemcheckbox" must be contained in an element with one of these roles: menu, menubar, group',
386+
'Role "menuitemcheckbox" must be contained in an element with one of these roles: menu, menubar',
376387
},
377388
],
378389
},
@@ -382,7 +393,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
382393
errors: [
383394
{
384395
message:
385-
'Role "menuitemradio" must be contained in an element with one of these roles: menu, menubar, group',
396+
'Role "menuitemradio" must be contained in an element with one of these roles: group, menu, menubar',
386397
},
387398
],
388399
},
@@ -392,7 +403,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
392403
errors: [
393404
{
394405
message:
395-
'Role "option" must be contained in an element with one of these roles: listbox, group',
406+
'Role "option" must be contained in an element with one of these roles: listbox',
396407
},
397408
],
398409
},
@@ -402,7 +413,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
402413
errors: [
403414
{
404415
message:
405-
'Role "row" must be contained in an element with one of these roles: table, grid, treegrid, rowgroup',
416+
'Role "row" must be contained in an element with one of these roles: grid, rowgroup, table, treegrid',
406417
},
407418
],
408419
},
@@ -421,7 +432,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
421432
output: null,
422433
errors: [
423434
{
424-
message: 'Role "rowheader" must be contained in an element with one of these roles: row',
435+
message: 'Role "rowheader" must be contained in an element with one of these roles: grid, row',
425436
},
426437
],
427438
},
@@ -438,7 +449,16 @@ hbsRuleTester.run('template-require-context-role', rule, {
438449
errors: [
439450
{
440451
message:
441-
'Role "treeitem" must be contained in an element with one of these roles: tree, group',
452+
'Role "treeitem" must be contained in an element with one of these roles: group, tree',
453+
},
454+
],
455+
},
456+
{
457+
code: '<div><div role="cell">Item One</div></div>',
458+
output: null,
459+
errors: [
460+
{
461+
message: 'Role "cell" must be contained in an element with one of these roles: row',
442462
},
443463
],
444464
},
@@ -448,7 +468,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
448468
errors: [
449469
{
450470
message:
451-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
471+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
452472
},
453473
],
454474
},
@@ -458,7 +478,7 @@ hbsRuleTester.run('template-require-context-role', rule, {
458478
errors: [
459479
{
460480
message:
461-
'Role "menuitem" must be contained in an element with one of these roles: menu, menubar, group',
481+
'Role "menuitem" must be contained in an element with one of these roles: group, menu, menubar',
462482
},
463483
],
464484
},

0 commit comments

Comments
 (0)