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-forbidden-elements.js
More file actions
129 lines (125 loc) · 3.45 KB
/
template-no-forbidden-elements.js
File metadata and controls
129 lines (125 loc) · 3.45 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
const rule = require('../../../lib/rules/template-no-forbidden-elements');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-no-forbidden-elements', rule, {
valid: [
{ code: '<template><div></div></template>', options: [['script']] },
// Object config form
{ code: '<template><div></div></template>', options: [{ forbidden: ['script'] }] },
{ code: '<template><script></script></template>', options: [{ forbidden: ['html'] }] },
'<template><header></header></template>',
'<template><footer></footer></template>',
'<template><p></p></template>',
'<template><head><meta charset="utf-8"></head></template>',
],
invalid: [
{
code: '<template><script></script></template>',
output: null,
options: [{ forbidden: ['script'] }],
errors: [{ messageId: 'forbidden' }],
},
{
code: '<template><script></script></template>',
output: null,
options: [['script']],
errors: [{ messageId: 'forbidden' }],
},
{
code: '<template><html></html></template>',
output: null,
errors: [{ messageId: 'forbidden' }],
},
{
code: '<template><style></style></template>',
output: null,
errors: [{ messageId: 'forbidden' }],
},
{
code: '<template><meta charset="utf-8"></template>',
output: null,
errors: [{ messageId: 'forbidden' }],
},
{
code: '<template><head><html></html></head></template>',
output: null,
errors: [{ messageId: 'forbidden' }],
},
{
code: '<template><Foo /></template>',
output: null,
options: [['Foo']],
errors: [{ messageId: 'forbidden' }],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-no-forbidden-elements', rule, {
valid: [
'<header></header>',
'<div></div>',
'<footer></footer>',
'<p></p>',
'<head><meta charset="utf-8"></head>',
// Custom forbidden list (script not included).
{
code: '<script></script>',
options: [['html', 'meta', 'style']],
},
// Object config form.
{
code: '<script></script>',
options: [{ forbidden: ['html', 'meta', 'style'] }],
},
],
invalid: [
// Default config.
{
code: '<script></script>',
output: null,
errors: [{ message: 'Use of forbidden element <script>' }],
},
{
code: '<html></html>',
output: null,
errors: [{ message: 'Use of forbidden element <html>' }],
},
{
code: '<style></style>',
output: null,
errors: [{ message: 'Use of forbidden element <style>' }],
},
{
code: '<meta charset="utf-8">',
output: null,
errors: [{ message: 'Use of forbidden element <meta>' }],
},
{
code: '<head><html></html></head>',
output: null,
errors: [{ message: 'Use of forbidden element <html>' }],
},
// Custom forbidden list.
{
code: '<div></div>',
output: null,
options: [['div']],
errors: [{ message: 'Use of forbidden element <div>' }],
},
{
code: '<Foo />',
output: null,
options: [['Foo']],
errors: [{ message: 'Use of forbidden element <Foo>' }],
},
],
});