data icon indicating copy to clipboard operation
data copied to clipboard

feat: lint against using `<Request><:content>` without consuming the actual request result

Open runspired opened this issue 6 months ago • 0 comments

Why?

Often this indicates an anti-pattern in which the result is being indirectly consumed by accessing the resource in the store via other means.

What?

This will need to be linted against using an ember-template-lint plugin. We currently don't have an ember-template-lint-plugin-warp-drive package, so you'll need to create one. I will provide instructions for how to do so below.

Resources

  • ember-template-lint repo: https://github.com/ember-template-lint/ember-template-lint/tree/master
  • ember-template-lint plugin docs: https://github.com/ember-template-lint/ember-template-lint/blob/master/docs/plugins.md
  • Docs on how to use the <Request> component: https://github.com/emberjs/data/tree/main/warp-drive-packages/ember#request-

Instructions

  1. Create a new package at packages/ember-template-lint-plugin-warp-drive
    • Follow existing patterns for new packages (e.g. can follow patterns from packages/eslint-plugin-warp-drive)
    • Prefer TypeScript over JavaScript
    • Use pnpm for package management
  2. Write tests for a new rule: always-use-request-content. Tests should include, but not necessarily be limited to:
    • Good examples
      • You can extract good examples from <Request> component docs: https://github.com/emberjs/data/tree/main/warp-drive-packages/ember#request-
      • <Request> with no content block--as long as it uses the other blocks (<Request @request={{@request}}><:idle></:idle><:loading></:loading>...</Request>)
      • Note: It's fine for users to name the variable yielded by the content block whatever they want
      • Note: The content block yields a second "state" argument that may or may not be used; this is unrelated to this lint rule but we should test that it's allowed
    • Bad examples:
      • <Request> with no content block and not other blocks (<Request @request={{@request}}>...</Request>)
      • <Request> with content block but no yielded result (<Request @request={{@request}}><:content>...</:content></Request>)
      • <Request> with content block and yielded result, but the result isn't used (<Request @request={{@request}}><:content as |result|>...result not used...</:content></Request>)
  3. Create a new rule always-use-request-content that passes the tests.

runspired avatar Jul 10 '25 09:07 runspired