forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-template-length.js
More file actions
116 lines (111 loc) · 2.07 KB
/
template-template-length.js
File metadata and controls
116 lines (111 loc) · 2.07 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
const rule = require('../../../lib/rules/template-template-length');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-template-length', rule, {
valid: [
{
code: `<template>
one
two
</template>`,
options: [{ max: 5 }],
},
{
code: `<template>
one
two
three
</template>`,
options: [{ min: 3 }],
},
{
code: `<template>
one
</template>`,
options: [false],
},
`<template>testing this
and
this
and his</template>`,
],
invalid: [
{
code: `<template>
one
two
</template>`,
output: null,
options: [{ min: 10 }],
errors: [{ message: 'Template length of 4 is smaller than 10' }],
},
{
code: `<template>
one
two
three
</template>`,
output: null,
options: [{ max: 3 }],
errors: [{ message: 'Template length of 5 exceeds 3' }],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-template-length', rule, {
valid: [
`testing this
and
this
and his`,
`testing
this
`,
`testing
this
and his
`,
`testing
this
andthis
`,
// Config: max option
{
code: 'testing\nthis\n',
options: [{ max: 10 }],
},
// Config: min option
{
code: 'testing\nthis\nand\this\n',
options: [{ min: 1 }],
},
// Config: min + max options
{
code: 'testing\nthis\nandthis\n',
options: [{ min: 1, max: 5 }],
},
],
invalid: [
{
code: 'testing\ntoo-short template\n',
output: null,
options: [{ min: 10 }],
errors: [{ message: 'Template length of 3 is smaller than 10' }],
},
{
code: 'test\nthis\nand\nthis\n',
output: null,
options: [{ max: 3 }],
errors: [{ message: 'Template length of 5 exceeds 3' }],
},
],
});