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-args-paths.js
More file actions
133 lines (130 loc) · 4.16 KB
/
template-no-args-paths.js
File metadata and controls
133 lines (130 loc) · 4.16 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
const rule = require('../../../lib/rules/template-no-args-paths');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-no-args-paths', rule, {
valid: [
'<template>{{@foo}}</template>',
// @args.foo is a valid named argument, not a path violation
'<template>{{@args.foo}}</template>',
'<template><div @foo={{cleanup this.args}}></div></template>',
'<template>{{foo (name this.args)}}</template>',
'<template>{{foo name=this.args}}</template>',
'<template>{{foo name=(extract this.args)}}</template>',
'<template><Foo @params={{this.args}} /></template>',
'<template><Foo {{mod this.args}} /></template>',
'<template><Foo {{mod items=this.args}} /></template>',
'<template><Foo {{mod items=(extract this.args)}} /></template>',
// args as a block param is not flagged
'<template>{{#each items as |args|}}{{args.name}}{{/each}}</template>',
],
invalid: [
{
code: '<template>{{hello (format value=args.foo)}}</template>',
output: '<template>{{hello (format value=@foo)}}</template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template>{{hello value=args.foo}}</template>',
output: '<template>{{hello value=@foo}}</template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template>{{hello (format args.foo.bar)}}</template>',
output: '<template>{{hello (format @foo.bar)}}</template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template><br {{hello args.foo.bar}}></template>',
output: '<template><br {{hello @foo.bar}}></template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template>{{hello args.foo.bar}}</template>',
output: '<template>{{hello @foo.bar}}</template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template>{{args.foo.bar}}</template>',
output: '<template>{{@foo.bar}}</template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template>{{args.foo}}</template>',
output: '<template>{{@foo}}</template>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<template>{{this.args.foo}}</template>',
output: '<template>{{@foo}}</template>',
errors: [{ messageId: 'argsPath' }],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-no-args-paths', rule, {
valid: [
// @args.foo is a valid named argument
'{{@args.foo}}',
'<div @foo={{cleanup this.args}}></div>',
'{{foo (name this.args)}}',
'{{foo name=this.args}}',
'{{foo name=(extract this.args)}}',
'<Foo @params={{this.args}} />',
'<Foo {{mod this.args}} />',
'<Foo {{mod items=this.args}} />',
'<Foo {{mod items=(extract this.args)}} />',
// args as a block param is not flagged
'{{#each items as |args|}}{{args.name}}{{/each}}',
],
invalid: [
{
code: '{{hello (format value=args.foo)}}',
output: '{{hello (format value=@foo)}}',
errors: [{ messageId: 'argsPath' }],
},
{
code: '{{hello value=args.foo}}',
output: '{{hello value=@foo}}',
errors: [{ messageId: 'argsPath' }],
},
{
code: '{{hello (format args.foo.bar)}}',
output: '{{hello (format @foo.bar)}}',
errors: [{ messageId: 'argsPath' }],
},
{
code: '<br {{hello args.foo.bar}}>',
output: '<br {{hello @foo.bar}}>',
errors: [{ messageId: 'argsPath' }],
},
{
code: '{{hello args.foo.bar}}',
output: '{{hello @foo.bar}}',
errors: [{ messageId: 'argsPath' }],
},
{
code: '{{args.foo.bar}}',
output: '{{@foo.bar}}',
errors: [{ messageId: 'argsPath' }],
},
{
code: '{{args.foo}}',
output: '{{@foo}}',
errors: [{ messageId: 'argsPath' }],
},
{
code: '{{this.args.foo}}',
output: '{{@foo}}',
errors: [{ messageId: 'argsPath' }],
},
],
});