11/** @type {import('eslint').Rule.RuleModule } */
22module . exports = {
33 meta : {
4- type : 'suggestion ' ,
4+ type : 'problem ' ,
55 docs : {
6- description : 'disallow referencing let variables in \\<template\\>' ,
6+ description :
7+ 'disallow missing helpers, modifiers, or components in \\<template\\> with auto-fix to import them' ,
78 category : 'Ember Octane' ,
8- recommendedGjs : false ,
9- recommendedGts : false ,
109 url : 'https://github.com/ember-cli/eslint-plugin-ember/tree/master/docs/rules/template-missing-invokable.md' ,
1110 } ,
1211 fixable : 'code' ,
13- schema : [ ] ,
12+ schema : [
13+ {
14+ type : 'object' ,
15+ properties : {
16+ invokables : {
17+ type : 'object' ,
18+ additionalProperties : {
19+ type : 'array' ,
20+ prefixItems : [
21+ { type : 'string' , description : 'The name to import from the module' } ,
22+ { type : 'string' , description : 'The module to import from' } ,
23+ ] ,
24+ } ,
25+ } ,
26+ } ,
27+ } ,
28+ ] ,
1429 messages : {
1530 'missing-invokable' :
1631 'Not in scope. Did you forget to import this? Auto-fix may be configured.' ,
@@ -20,25 +35,20 @@ module.exports = {
2035 create : ( context ) => {
2136 const sourceCode = context . sourceCode ;
2237
23- // TODO make real config
24- const config = {
25- eq : { name : 'eq' , module : 'ember-truth-helpers' } ,
26- on : { name : 'on' , module : '@ember/modifier' } ,
27- } ;
28-
2938 // takes a node with a `.path` property
3039 function checkInvokable ( node ) {
3140 if ( node . path . type === 'GlimmerPathExpression' && node . path . tail . length === 0 ) {
3241 if ( ! isBound ( node . path . head , sourceCode . getScope ( node . path ) ) ) {
33- const matched = config [ node . path . head . name ] ;
42+ const matched = context . options [ 0 ] ?. invokables ?. [ node . path . head . name ] ;
3443 if ( matched ) {
44+ const [ name , module ] = matched ;
3545 context . report ( {
3646 node : node . path ,
3747 messageId : 'missing-invokable' ,
3848 fix ( fixer ) {
3949 return fixer . insertTextBeforeRange (
4050 [ 0 , 0 ] ,
41- `import { ${ matched . name } } from '${ matched . module } ';\n`
51+ `import { ${ name } } from '${ module } ';\n`
4252 ) ;
4353 } ,
4454 } ) ;
@@ -64,7 +74,6 @@ module.exports = {
6474function isBound ( node , scope ) {
6575 const ref = scope . references . find ( ( v ) => v . identifier === node ) ;
6676 if ( ! ref ) {
67- // TODO: can we make a test case for this?
6877 return false ;
6978 }
7079 return Boolean ( ref . resolved ) ;
0 commit comments