|
| 1 | +function isActionHelper(node) { |
| 2 | + if (!node.path || node.path.type !== 'GlimmerPathExpression') { |
| 3 | + return false; |
| 4 | + } |
| 5 | + |
| 6 | + // Check if it's the action helper (not this.action or @action) |
| 7 | + const path = node.path; |
| 8 | + if (path.original === 'action') { |
| 9 | + // Check head.type to avoid deprecated data/this properties |
| 10 | + const head = path.head; |
| 11 | + if (head && (head.type === 'AtHead' || head.type === 'ThisHead')) { |
| 12 | + return false; |
| 13 | + } |
| 14 | + return true; |
| 15 | + } |
| 16 | + |
| 17 | + return false; |
| 18 | +} |
| 19 | + |
| 20 | +/** @type {import('eslint').Rule.RuleModule} */ |
| 21 | +module.exports = { |
| 22 | + meta: { |
| 23 | + type: 'suggestion', |
| 24 | + docs: { |
| 25 | + description: 'disallow {{action}} helper', |
| 26 | + category: 'Deprecations', |
| 27 | + strictGjs: true, |
| 28 | + strictGts: true, |
| 29 | + url: 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-no-action.md', |
| 30 | + }, |
| 31 | + fixable: null, |
| 32 | + schema: [], |
| 33 | + messages: { |
| 34 | + subExpression: |
| 35 | + 'Do not use `action` as (action ...). Instead, use the `on` modifier and `fn` helper.', |
| 36 | + mustache: 'Do not use `action` in templates. Instead, use the `on` modifier and `fn` helper.', |
| 37 | + }, |
| 38 | + }, |
| 39 | + |
| 40 | + create(context) { |
| 41 | + return { |
| 42 | + GlimmerSubExpression(node) { |
| 43 | + if (isActionHelper(node)) { |
| 44 | + context.report({ |
| 45 | + node, |
| 46 | + messageId: 'subExpression', |
| 47 | + }); |
| 48 | + } |
| 49 | + }, |
| 50 | + |
| 51 | + GlimmerMustacheStatement(node) { |
| 52 | + // Skip if inside an attribute |
| 53 | + let parent = node.parent; |
| 54 | + while (parent) { |
| 55 | + if (parent.type === 'GlimmerAttrNode') { |
| 56 | + return; |
| 57 | + } |
| 58 | + parent = parent.parent; |
| 59 | + } |
| 60 | + |
| 61 | + if (isActionHelper(node)) { |
| 62 | + context.report({ |
| 63 | + node, |
| 64 | + messageId: 'mustache', |
| 65 | + }); |
| 66 | + } |
| 67 | + }, |
| 68 | + }; |
| 69 | + }, |
| 70 | +}; |
0 commit comments