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
62 lines (56 loc) · 1.57 KB
/
template-simple-modifiers.js
File metadata and controls
62 lines (56 loc) · 1.57 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
function isModifierHelper(node) {
return node.path?.original === 'modifier';
}
function isValidFirstParam(node) {
return (
node.type === 'GlimmerStringLiteral' || (node.type === 'GlimmerPathExpression' && node.original)
);
}
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: 'suggestion',
docs: {
description: 'require simple modifier syntax',
category: 'Best Practices',
url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-simple-modifiers.md',
templateMode: 'both',
},
fixable: null,
schema: [],
messages: {
invalidFirstArgument:
'The modifier helper should have a string or a variable name containing the modifier name as a first argument.',
},
originallyFrom: {
name: 'ember-template-lint',
rule: 'lib/rules/simple-modifiers.js',
docs: 'docs/rule/simple-modifiers.md',
tests: 'test/unit/rules/simple-modifiers-test.js',
},
},
create(context) {
return {
// This catches {{(modifier ...)}} expressions
GlimmerSubExpression(node) {
if (!isModifierHelper(node)) {
return;
}
const firstParam = node.params?.[0];
if (!firstParam) {
context.report({
node,
messageId: 'invalidFirstArgument',
});
return;
}
if (!isValidFirstParam(firstParam)) {
context.report({
node: firstParam,
messageId: 'invalidFirstArgument',
});
}
},
};
},
};