-
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathtemplate-no-empty-headings.js
More file actions
165 lines (160 loc) · 6.54 KB
/
template-no-empty-headings.js
File metadata and controls
165 lines (160 loc) · 6.54 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
const rule = require('../../../lib/rules/template-no-empty-headings');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-no-empty-headings', rule, {
valid: [
'<template><h1>Title</h1></template>',
'<template><h2>{{this.title}}</h2></template>',
'<template><h3><span>Text</span></h3></template>',
'<template><h4 hidden></h4></template>',
'<template><h1>Accessible Heading</h1></template>',
'<template><h1>Accessible Heading</h1></template>',
'<template><h1 aria-hidden="true">Valid Heading</h1></template>',
'<template><h1 aria-hidden="true"><span>Valid Heading</span></h1></template>',
'<template><h1 aria-hidden="false">Accessible Heading</h1></template>',
'<template><h1 hidden>Valid Heading</h1></template>',
'<template><h1 hidden><span>Valid Heading</span></h1></template>',
'<template><h1><span aria-hidden="true">Hidden text</span><span>Visible text</span></h1></template>',
'<template><h1><span aria-hidden="true">Hidden text</span>Visible text</h1></template>',
'<template><div role="heading" aria-level="1">Accessible Text</div></template>',
'<template><div role="heading" aria-level="1"><span>Accessible Text</span></div></template>',
'<template><div role="heading" aria-level="1"><span aria-hidden="true">Hidden text</span><span>Visible text</span></div></template>',
'<template><div role="heading" aria-level="1"><span aria-hidden="true">Hidden text</span>Visible text</div></template>',
'<template><div></div></template>',
'<template><p></p></template>',
'<template><span></span></template>',
'<template><header></header></template>',
'<template><h2><CustomComponent /></h2></template>',
'<template><h2>{{@title}}</h2></template>',
'<template><h2>{{#component}}{{/component}}</h2></template>',
'<template><h2><span>{{@title}}</span></h2></template>',
'<template><h2><div><CustomComponent /></div></h2></template>',
'<template><h2><div></div><CustomComponent /></h2></template>',
'<template><h2><div><span>{{@title}}</span></div></h2></template>',
'<template><h2><span>Some text{{@title}}</span></h2></template>',
'<template><h2><span><div></div>{{@title}}</span></h2></template>',
// Non-PascalCase component forms count as accessible content
'<template><h1><this.Heading /></h1></template>',
'<template><h2><@heading /></h2></template>',
'<template><h3><ns.Heading /></h3></template>',
// aria-hidden variants are exempt from the empty-heading check to avoid
// false positives when headings are intentionally hidden from assistive tech.
'<template><h1 aria-hidden></h1></template>',
'<template><h1 aria-hidden=""></h1></template>',
'<template><h1 aria-hidden={{true}}></h1></template>',
'<template><h1 aria-hidden="true">Visible to sighted only</h1></template>',
'<template><h1 aria-hidden="TRUE"></h1></template>',
'<template><h1 aria-hidden="True"></h1></template>',
'<template><h1 aria-hidden={{"TRUE"}}></h1></template>',
'<template><h1 aria-hidden={{"True"}}></h1></template>',
],
invalid: [
{
code: '<template><h1></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h2> </h2></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: `<template><h1>
</h1></template>`,
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span></span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: `<template><h1><span>
</span></h1></template>`,
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><div><span></span></div></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span></span><span></span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1> <div aria-hidden="true">Some hidden text</div></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span aria-hidden="true">Inaccessible text</span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span hidden>Inaccessible text</span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span hidden>{{@title}}</span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span hidden>{{#component}}Inaccessible text{{/component}}</span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span hidden><CustomComponent>Inaccessible text</CustomComponent></span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1><span aria-hidden="true">Hidden text</span><span aria-hidden="true">Hidden text</span></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><div role="heading" aria-level="1"></div></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><div role="heading" aria-level="1"><span aria-hidden="true">Inaccessible text</span></div></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><div role="heading" aria-level="1"><span hidden>Inaccessible text</span></div></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
// Explicit falsy aria-hidden does NOT exempt the empty-heading check —
// this is the unambiguous opt-out, no ecosystem position disagrees.
{
code: '<template><h1 aria-hidden="false"></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1 aria-hidden={{false}}></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
{
code: '<template><h1 aria-hidden={{"false"}}></h1></template>',
output: null,
errors: [{ messageId: 'emptyHeading' }],
},
],
});