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-yield-only.js
More file actions
78 lines (70 loc) · 1.79 KB
/
template-no-yield-only.js
File metadata and controls
78 lines (70 loc) · 1.79 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
const rule = require('../../../lib/rules/template-no-yield-only');
const RuleTester = require('eslint').RuleTester;
const validHbs = [
'{{yield (hash someProp=someValue)}}',
'{{field}}',
'{{#yield}}{{/yield}}',
'<Yield/>',
'<yield/>',
];
const invalidHbs = [
{
code: '{{yield}}',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: ' {{yield}}',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: '\n {{yield}}\n ',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: '\n{{! some comment }} {{yield}}\n ',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: '{{!-- long-form comment --}}{{yield}}',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
{
code: '<!-- html comment -->{{yield}}',
output: null,
errors: [{ messageId: 'noYieldOnly' }],
},
];
function wrapTemplate(entry) {
if (typeof entry === 'string') {
return `<template>${entry}</template>`;
}
return {
...entry,
code: `<template>${entry.code}</template>`,
output: entry.output ? `<template>${entry.output}</template>` : entry.output,
};
}
const gjsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
gjsRuleTester.run('template-no-yield-only', rule, {
valid: validHbs.filter((entry) => !entry.includes('template-lint-disable')).map(wrapTemplate),
invalid: invalidHbs.map(wrapTemplate),
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-no-yield-only', rule, {
valid: validHbs,
invalid: invalidHbs,
});