forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-require-iframe-title.js
More file actions
225 lines (218 loc) · 7.67 KB
/
template-require-iframe-title.js
File metadata and controls
225 lines (218 loc) · 7.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
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
const rule = require('../../../lib/rules/template-require-iframe-title');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-require-iframe-title', rule, {
valid: [
'<template><iframe title="Video"></iframe></template>',
'<template><iframe title="Map" src="/map"></iframe></template>',
'<template><iframe aria-hidden="true"></iframe></template>',
'<template><iframe hidden></iframe></template>',
'<template><iframe title="Welcome to the Matrix!" /></template>',
'<template><iframe title={{someValue}} /></template>',
'<template><iframe title="" aria-hidden /></template>',
'<template><iframe title="" hidden /></template>',
'<template><iframe title="foo" /><iframe title="bar" /></template>',
],
invalid: [
{
code: '<template><iframe src="/content"></iframe></template>',
output: null,
errors: [{ messageId: 'missingTitle' }],
},
{
code: '<template><iframe title=""></iframe></template>',
output: null,
errors: [{ messageId: 'emptyTitle' }],
},
{
// Both occurrences are reported with a shared `#N` index.
code: '<template><iframe title="foo" /><iframe title="foo" /></template>',
output: null,
errors: [
{ message: 'This title is not unique. #1' },
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
],
},
{
// Three duplicates → the first occurrence is re-reported on every
// collision, so iframe #1 is flagged twice (once per later collision)
// and iframes #2 and #3 are each flagged once. ESLint sorts by source
// location, so the two first-occurrence reports (same location) come
// before the two later occurrences.
code: '<template><iframe title="foo" /><iframe title="foo" /><iframe title="foo" /></template>',
output: null,
errors: [
{ message: 'This title is not unique. #1' },
{ message: 'This title is not unique. #1' },
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
],
},
{
// Two distinct duplicate groups → 4 reports, indices #1 and #2.
// ESLint sorts errors by source location; the two "first-occurrence"
// reports attach to the first two iframes and so precede the two
// "other-occurrence" reports attached to the later iframes.
code: '<template><iframe title="foo" /><iframe title="boo" /><iframe title="foo" /><iframe title="boo" /></template>',
output: null,
errors: [
{ message: 'This title is not unique. #1' },
{ message: 'This title is not unique. #2' },
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
{
message:
'<iframe> elements must have a unique title property. Value title="boo" already used for different iframe. #2',
},
],
},
{
code: '<template><iframe src="12" /></template>',
output: null,
errors: [{ messageId: 'missingTitle' }],
},
{
code: '<template><iframe src="12" title={{false}} /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe src="12" title="{{false}}" /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe src="12" title="" /></template>',
output: null,
errors: [{ messageId: 'emptyTitle' }],
},
// Mustache literals that don't coerce to a useful accessible name.
{
code: '<template><iframe title={{null}} /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe title={{undefined}} /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe title={{42}} /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe title="{{null}}" /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe title="{{undefined}}" /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
{
code: '<template><iframe title="{{42}}" /></template>',
output: null,
errors: [{ messageId: 'dynamicFalseTitle' }],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-require-iframe-title', rule, {
valid: [
'<iframe title="Welcome to the Matrix!" />',
'<iframe title={{someValue}} />',
'<iframe title="" aria-hidden />',
'<iframe title="" hidden />',
'<iframe title="foo" /><iframe title="bar" />',
],
invalid: [
{
code: '<iframe title="foo" /><iframe title="foo" />',
output: null,
errors: [
{ message: 'This title is not unique. #1' },
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
],
},
{
// Three duplicates: the first occurrence is re-reported on every
// collision, so iframe #1 is flagged twice and each later iframe once.
code: '<iframe title="foo" /><iframe title="foo" /><iframe title="foo" />',
output: null,
errors: [
{ message: 'This title is not unique. #1' },
{ message: 'This title is not unique. #1' },
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
],
},
{
code: '<iframe title="foo" /><iframe title="boo" /><iframe title="foo" /><iframe title="boo" />',
output: null,
errors: [
{ message: 'This title is not unique. #1' },
{ message: 'This title is not unique. #2' },
{
message:
'<iframe> elements must have a unique title property. Value title="foo" already used for different iframe. #1',
},
{
message:
'<iframe> elements must have a unique title property. Value title="boo" already used for different iframe. #2',
},
],
},
{
code: '<iframe src="12" />',
output: null,
errors: [{ message: '<iframe> elements must have a unique title property.' }],
},
{
code: '<iframe src="12" title={{false}} />',
output: null,
errors: [{ message: '<iframe> elements must have a unique title property.' }],
},
{
code: '<iframe src="12" title="{{false}}" />',
output: null,
errors: [{ message: '<iframe> elements must have a unique title property.' }],
},
{
code: '<iframe src="12" title="" />',
output: null,
errors: [{ message: '<iframe> elements must have a unique title property.' }],
},
],
});