ember-cli / ember-template-imports

Template import support in Ember!
MIT License
74 stars 39 forks source link

yielded components on a hash are linted as not defined when yielded on named blocks #186

Closed cah-brian-gantzler closed 1 year ago

cah-brian-gantzler commented 1 year ago

Not sure which addon is doing the linting, this one or https://github.com/ember-template-lint/ember-template-lint. Starting here

When a component is yielded on a named block, then used, the linter states that the component is undefined. This is in a test. Have not yet converted the actual use to a gjs.

await render(<template>
      <Stargate
        @onCancel={{(noop)}}
        @onContinue={{(noop)}}
        @noButtons={{false}}
      >
        <:default><span data-test-default>
            {{blockText}}
          </span></:default>
        <:buttons as |buttons|>
          <span data-test-buttons></span>
          <buttons.cancel /><buttons.continue /></:buttons>
        <:title><h1 data-test-title><b>{{title}}</b></h1> </:title>
      </Stargate>
    </template>);

Linting message

 Error in template: 'buttons' is not defined  no-undef

While the named block happens to be the same name as the yielded hash, I did try changing the names and the issue persisted.

I have used yielded components elsewhere with no linting issue, assuming this is specific to named blocks

NullVoxPopuli commented 1 year ago

what ember-source are you using? this is fixed in projects with sufficiently new ember-source, due to a fix landing in @glimmer/syntax's parser

cah-brian-gantzler commented 1 year ago

4.12.3. Used to be I kept ember data and ember source in sync. Working through ED deprecations, so cant update to 5 for ED. Is it ok to update to 5 for source and keep ED at 4?

NullVoxPopuli commented 1 year ago

I'm unsure -- it's worth a try! using ember-source@5.1 shows that the scenario works: https://limber.glimdown.com/edit?c=BYFxAcGcC4HpYOYEsTAK4CMB0BjA9gLawCmBGxATgLQingA2AhrVUgeHhSJCWZTXSYs2HLjySRIaYjwCMADgBsAKGUADDQgBWkAAT0kAN2LKRnELoDeu4I0jBdAX10AzCoV0ByAAKlyFWGBienBKTwBuVXwAO0gLAHEKYmIQJGiEXQBeXQAeWnYhYgA%2BZV1dAAlg%2BjwAGl14gwICSgBCZRzYfIZmYqi8WIsAIQokRmis3K7CostLAE8kYIATXQAKW3tdBCSUtIRMxOTU9IBKR0cOqZ6iyPar2hKynOHR8btdAB8ADw-Hstyvlhtkc9rpYH8Oi8xiVLoJruoNKogA&format=glimdown

So one thing we may also need to check is if your floating dep of @glimmer/syntax is up to date in your lockfile. you may want to pin it to a newer version. There have been some issues with pnpm and glimmer being pre v1 lately. I have to pin all of them: https://github.com/NullVoxPopuli/limber/blob/main/package.json#L48

cah-brian-gantzler commented 1 year ago

K, good to know, ember-code coverage looks like its bringing in 0.42 and and ember font awesome is bring in 0.27

NullVoxPopuli commented 1 year ago

Should be resolved in v4. Thanks for reporting! If this is still an issue, lemme know and we can reopen.

c0rydoras commented 1 year ago

I am currently experiencing this issue with ember-source@^5.4.0 and ember-template-imports@^4.0.0

[lint:js] /home[...]/ember-app/app/components/foo.gjs
[lint:js]   4:15  error  'card' is defined but never used  no-unused-vars

minimal reproduction: https://github.com/c0rydoras/gjs-linting-no-undef-reproduction related workflow: https://github.com/c0rydoras/gjs-linting-no-undef-reproduction/actions/runs/6798889824/job/18483951695

NullVoxPopuli commented 1 year ago

Can you try the main branch of eslint-plugin-ember?

c0rydoras commented 1 year ago

sadly that did not fix it: https://github.com/c0rydoras/gjs-linting-no-undef-reproduction/actions/runs/6799482927/job/18485892842

NullVoxPopuli commented 1 year ago

Interesting. Thanks for the reproduction! Can you open an issue on eslint plugin ember? Thanks!

c0rydoras commented 1 year ago

done: https://github.com/ember-cli/eslint-plugin-ember/issues/1991

NullVoxPopuli commented 1 year ago

thank you!!