Skip to content
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

Rule request: [embroider-ready] #2375

Open
lifeart opened this issue Feb 9, 2022 · 1 comment
Open

Rule request: [embroider-ready] #2375

lifeart opened this issue Feb 9, 2022 · 1 comment

Comments

@lifeart
Copy link
Collaborator

lifeart commented Feb 9, 2022

Embroider could not find all possible dynamic usecases of dynamic helper, modifier and component.

In scope of this rule, we could highlight it (as warning, for example) to users to simplify migration.

Refs:

embroider-build/embroider#1120 (comment)

Cases to warn:

{{component (or @a "b" "c")}}

{{#let (component (or @a "b" "c")) as |A|}}
   <A/>
{{{/let}}

{{helper (or @a "b" "c")}}
{{#let (helper (or @a "b" "c")) as |A|}}
  {{A}}
{{{/let}}
{{modifier (or @a "b" "c")}}
{{#let (modifier (or @a "b" "c")) as |A|}}
   <div {{A}} />
{{{/let}}

Check details:

{
    PathExpression(node, path) {
      if (['modifier', 'helper', 'component'].includes(node.original)) {
        const parent = path.parent.node;
        if (!parent.params.length) {
          return;
        }
        const type = parent.params[0].type;
        const allowedArgumentTypes = ['PathExpression', 'StringLiteral'];

        if (!allowedArgumentTypes.includes(type)) {
          const source = env.syntax.print(parent);
          console.warn(`${source} is not supported with embroider, move this logic inside js class`); 
        }
      }
    }
  };

Example:

https://astexplorer.net/#/gist/2509d2732e9e5b05d31a61b2693691e5/9223800e70e87eca3c560ad232d94faa1f8ae523

@ef4
Copy link
Contributor

ef4 commented Feb 10, 2022

Only the component keyword arguably needs a lint.

Non-string-literal usage of helper and modifier keywords was never allowed and throws a hard error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants