-
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathtemplate-no-empty-headings.js
More file actions
142 lines (138 loc) · 5.67 KB
/
template-no-empty-headings.js
File metadata and controls
142 lines (138 loc) · 5.67 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
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>',
// Custom elements (hyphenated lowercase) aren't in the html-tags / svg-tags /
// mathml-tag-names allowlists — treated as opaque, assume content. Matches
// the accepted-false-negative convention established in #2689.
'<template><h1><my-widget /></h1></template>',
'<template><h2><x-foo>text</x-foo></h2></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' }],
},
],
});