forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-no-nested-landmark.js
More file actions
222 lines (212 loc) · 7.43 KB
/
template-no-nested-landmark.js
File metadata and controls
222 lines (212 loc) · 7.43 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
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const rule = require('../../../lib/rules/template-no-nested-landmark');
const RuleTester = require('eslint').RuleTester;
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-no-nested-landmark', rule, {
valid: [
`<template>
<nav>Navigation</nav>
<main>Content</main>
</template>`,
`<template>
<div>
<nav>Nav 1</nav>
<nav>Nav 2</nav>
</div>
</template>`,
`<template>
<main>
<div>Content</div>
</main>
</template>`,
`<template>
<div role="navigation">Nav</div>
<div role="main">Content</div>
</template>`,
'<template><div><main></main></div></template>',
'<template><div role="application"><div role="document"><div role="application"></div></div></div></template>',
'<template><header><nav></nav></header></template>',
'<template><div role="banner"><nav></nav></div></template>',
'<template><header><div role="navigation"></div></header></template>',
'<template><div role="banner"><div role="navigation"></div></div></template>',
// `<section>` only gets the `region` landmark role when it has an accessible name
// (aria-label/aria-labelledby/title). Without one it has the generic role — see
// https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/section.
// This rule does not inspect accessible names, so unnamed sections are excluded.
'<template><section><section>Content</section></section></template>',
// `role="region"` is the landmark role a named `<section>` gets. Nesting it is
// excluded for the same reason: the rule cannot verify an accessible name is present.
'<template><div role="region"><div role="region">Content</div></div></template>',
],
invalid: [
{
code: `<template>
<nav>
<nav>Content</nav>
</nav>
</template>`,
output: null,
errors: [
{
message: 'Landmark elements should not be nested within other landmarks.',
type: 'GlimmerElementNode',
},
],
},
{
code: `<template>
<main>
<main>Content</main>
</main>
</template>`,
output: null,
errors: [
{
message: 'Landmark elements should not be nested within other landmarks.',
type: 'GlimmerElementNode',
},
],
},
{
code: `<template>
<div role="main">
<div role="main">Nav</div>
</div>
</template>`,
output: null,
errors: [
{
message: 'Landmark elements should not be nested within other landmarks.',
type: 'GlimmerElementNode',
},
],
},
{
code: '<template><main><main></main></main></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><main><div><main></main></div></main></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><div role="main"><main></main></div></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><div role="main"><div><main></main></div></div></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><main><div role="main"></div></main></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><main><div><div role="main"></div></div></main></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><nav><nav></nav></nav></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><header><header></header></header></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><header><div role="banner"></div></header></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<template><div role="contentinfo"><footer></footer></div></template>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-no-nested-landmark', rule, {
valid: [
'<div><main></main></div>',
'<div role="application"><div role="document"><div role="application"></div></div></div>',
'<header><nav></nav></header>',
'<div role="banner"><nav></nav></div>',
'<header><div role="navigation"></div></header>',
'<div role="banner"><div role="navigation"></div></div>',
],
invalid: [
{
code: '<main><main></main></main>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<main><div><main></main></div></main>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<div role="main"><main></main></div>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<div role="main"><div><main></main></div></div>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<main><div role="main"></div></main>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<main><div><div role="main"></div></div></main>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<nav><nav></nav></nav>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<header><header></header></header>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<header><div role="banner"></div></header>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
{
code: '<div role="contentinfo"><footer></footer></div>',
output: null,
errors: [{ message: 'Landmark elements should not be nested within other landmarks.' }],
},
],
});