data
data copied to clipboard
feat: lint against using `<Request><:content>` without consuming the actual request result
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
- 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
pnpmfor package management
- 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
- You can extract good examples from
- 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>)
- Good examples
- Create a new rule
always-use-request-contentthat passes the tests.