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-action.js
More file actions
70 lines (64 loc) · 1.73 KB
/
template-no-action.js
File metadata and controls
70 lines (64 loc) · 1.73 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
function isActionHelper(node) {
if (!node.path || node.path.type !== 'GlimmerPathExpression') {
return false;
}
// Check if it's the action helper (not this.action or @action)
const path = node.path;
if (path.original === 'action') {
// Check head.type to avoid deprecated data/this properties
const head = path.head;
if (head && (head.type === 'AtHead' || head.type === 'ThisHead')) {
return false;
}
return true;
}
return false;
}
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'disallow {{action}} helper',
category: 'Deprecations',
strictGjs: true,
strictGts: true,
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-action.md',
},
fixable: null,
schema: [],
messages: {
subExpression:
'Do not use `action` as (action ...). Instead, use the `on` modifier and `fn` helper.',
mustache: 'Do not use `action` in templates. Instead, use the `on` modifier and `fn` helper.',
},
},
create(context) {
return {
GlimmerSubExpression(node) {
if (isActionHelper(node)) {
context.report({
node,
messageId: 'subExpression',
});
}
},
GlimmerMustacheStatement(node) {
// Skip if inside an attribute
let parent = node.parent;
while (parent) {
if (parent.type === 'GlimmerAttrNode') {
return;
}
parent = parent.parent;
}
if (isActionHelper(node)) {
context.report({
node,
messageId: 'mustache',
});
}
},
};
},
};