forked from ember-cli/eslint-plugin-ember
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate-simple-modifiers.js
More file actions
89 lines (83 loc) · 3.42 KB
/
template-simple-modifiers.js
File metadata and controls
89 lines (83 loc) · 3.42 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
const rule = require('../../../lib/rules/template-simple-modifiers');
const RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser'),
parserOptions: { ecmaVersion: 2022, sourceType: 'module' },
});
ruleTester.run('template-simple-modifiers', rule, {
valid: [
'<template><div {{(modifier "track-interaction" @controlName)}}></div></template>',
'<template><div {{(modifier trackInteraction @controlName)}}></div></template>',
'<template><div {{(modifier this.trackInteraction @controlName)}}></div></template>',
'<template><div {{my-modifier}}></div></template>',
'<template><div {{(modifier @trackInteraction @controlName)}}></div></template>',
'<template><div {{(if @isActionVisible (modifier "track-interaction" eventName=myEventName eventBody=myEventbody))}}></div></template>',
'<template><div {{(my-modifier (unless this.hasBeenClicked "track-interaction") "click" customizeData=this.customizeClickData)}}></div></template>',
'<template><MyComponent @people={{array "Tom Dale" "Yehuda Katz" this.myOtherPerson}} /></template>',
'<template><div {{(if this.foo (modifier "foo-bar"))}}></div></template>',
],
invalid: [
{
code: '<template><div {{(modifier)}}></div></template>',
output: null,
errors: [
{
message:
'The modifier helper should have a string or a variable name containing the modifier name as a first argument.',
},
],
},
{
code: '<template><div {{(modifier (unless this.hasBeenClicked "track-interaction") "click" customizeData=this.customizeClickData)}}></div></template>',
output: null,
errors: [
{
message:
'The modifier helper should have a string or a variable name containing the modifier name as a first argument.',
},
],
},
],
});
const hbsRuleTester = new RuleTester({
parser: require.resolve('ember-eslint-parser/hbs'),
parserOptions: {
ecmaVersion: 2022,
sourceType: 'module',
},
});
hbsRuleTester.run('template-simple-modifiers', rule, {
valid: [
'<div {{(modifier "track-interaction" @controlName)}}></div>',
'<div {{(modifier trackInteraction @controlName)}}></div>',
'<div {{(modifier this.trackInteraction @controlName)}}></div>',
'<div {{(modifier @trackInteraction @controlName)}}></div>',
'<div {{(if @isActionVisible (modifier "track-interaction" eventName=myEventName eventBody=myEventbody))}}></div>',
'<div {{(my-modifier (unless this.hasBeenClicked "track-interaction") "click" customizeData=this.customizeClickData)}}></div>',
'<div {{my-modifier}}></div>',
'<MyComponent @people={{array "Tom Dale" "Yehuda Katz" this.myOtherPerson}} />',
'<div {{(if this.foo (modifier "foo-bar"))}}></div>',
],
invalid: [
{
code: '<div {{(modifier (unless this.hasBeenClicked "track-interaction") "click" customizeData=this.customizeClickData)}}></div>',
output: null,
errors: [
{
message:
'The modifier helper should have a string or a variable name containing the modifier name as a first argument.',
},
],
},
{
code: '<div {{(modifier)}}></div>',
output: null,
errors: [
{
message:
'The modifier helper should have a string or a variable name containing the modifier name as a first argument.',
},
],
},
],
});