-
-
Notifications
You must be signed in to change notification settings - Fork 212
template-missing-invokable: add built-in invokables and always auto-fix from config #2556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e2747b4
c11b89a
1985afa
3eec111
cf2a5cd
68963ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "name": "has-ember-truth-helpers", | ||
| "dependencies": { | ||
| "ember-truth-helpers": "*" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,10 +65,24 @@ ruleTester.run('template-missing-invokable', rule, { | |
| <button {{on "click" doSomething}}>Go</button> | ||
| </template> | ||
| `, | ||
|
|
||
| // Built-in invokables are not reported when already imported | ||
| ` | ||
| import { fn } from '@ember/helper'; | ||
| <template> | ||
| {{fn myFunc 1}} | ||
| </template> | ||
| `, | ||
| ` | ||
| import { LinkTo } from '@ember/routing'; | ||
| <template> | ||
| <LinkTo @route="index">Home</LinkTo> | ||
| </template> | ||
| `, | ||
| ], | ||
|
|
||
| invalid: [ | ||
| // Subexpression invocations | ||
| // Subexpression invocations — always auto-fixes when invokable is configured | ||
| { | ||
| code: ` | ||
| <template> | ||
|
|
@@ -96,7 +110,7 @@ ruleTester.run('template-missing-invokable', rule, { | |
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // Mustache Invocations | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot why'd you remove these?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I dropped the |
||
| // Mustache Invocations — always auto-fixes when invokable is configured | ||
| { | ||
| code: ` | ||
| <template> | ||
|
|
@@ -142,7 +156,7 @@ ruleTester.run('template-missing-invokable', rule, { | |
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // Modifier Inovcations | ||
| // Modifier Invocations — always auto-fixes when invokable is configured | ||
| { | ||
| code: ` | ||
| function doSomething() {} | ||
|
|
@@ -243,5 +257,96 @@ ruleTester.run('template-missing-invokable', rule, { | |
|
|
||
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // Built-in: fn — auto-fixes without any user config | ||
| { | ||
| code: ` | ||
| <template> | ||
| {{fn myFunc 1}} | ||
| </template> | ||
| `, | ||
| output: `import { fn } from '@ember/helper'; | ||
|
|
||
| <template> | ||
| {{fn myFunc 1}} | ||
| </template> | ||
| `, | ||
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // Built-in: hash — auto-fixes without any user config | ||
| { | ||
| code: ` | ||
| <template> | ||
| <MyComp @opts={{hash a=1}} /> | ||
| </template> | ||
| `, | ||
| output: `import { hash } from '@ember/helper'; | ||
|
|
||
| <template> | ||
| <MyComp @opts={{hash a=1}} /> | ||
| </template> | ||
| `, | ||
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // Built-in: on modifier — auto-fixes without any user config | ||
| { | ||
| code: ` | ||
| function doSomething() {} | ||
| <template> | ||
| <button {{on "click" doSomething}}>Go</button> | ||
| </template> | ||
| `, | ||
| output: `import { on } from '@ember/modifier'; | ||
|
|
||
| function doSomething() {} | ||
| <template> | ||
| <button {{on "click" doSomething}}>Go</button> | ||
| </template> | ||
| `, | ||
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // Built-in: LinkTo — auto-fixes without any user config | ||
| { | ||
| code: ` | ||
| <template> | ||
| <LinkTo @route="index">Home</LinkTo> | ||
| </template> | ||
| `, | ||
| output: `import { LinkTo } from '@ember/routing'; | ||
|
|
||
| <template> | ||
| <LinkTo @route="index">Home</LinkTo> | ||
| </template> | ||
| `, | ||
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
|
|
||
| // User config overrides a built-in | ||
| { | ||
| code: ` | ||
| function doSomething() {} | ||
| <template> | ||
| <button {{on "click" doSomething}}>Go</button> | ||
| </template> | ||
| `, | ||
| output: `import { on } from 'my-custom-modifier-package'; | ||
|
|
||
| function doSomething() {} | ||
| <template> | ||
| <button {{on "click" doSomething}}>Go</button> | ||
| </template> | ||
| `, | ||
| options: [ | ||
| { | ||
| invokables: { | ||
| on: ['on', 'my-custom-modifier-package'], | ||
| }, | ||
| }, | ||
| ], | ||
| errors: [{ type: 'GlimmerPathExpression', message: rule.meta.messages['missing-invokable'] }], | ||
| }, | ||
| ], | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot let's git rid of the package.json reading actually -- it needs to be done very carefully, and I don't want to walk you through that right now. lets just rely on the config for the lint rule.
Also, we need a list of default importables from the template:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in cf2a5cd. All FS/package.json reading is removed —
path,fs, the cache, and all related helpers are gone. Auto-fix now runs unconditionally whenever an invokable is matched.Added
BUILTIN_INVOKABLESwith the defaults you listed:User-provided
invokablesconfig is spread on top, so any built-in can be overridden.