ember-cli / ember-cli/eslint-plugin-ember
New rule: Lint against modifier which does not use the element
- Dominant language
- JavaScript
- Stars
- 263
- Forks
- 214
- Avg merge
- 30m
- Merged PRs (30d)
- 5
Description
Why: This is simply abusing modifiers to make them behave like observers (cc @chriskrycho)
If a class-based modifier:
- If using any method other than modify, check for use of this.element.
- If using modify, check for use of the first argument, which is always the element.
If a function-based modifier: check for use of the first argument, which is always the element.
Sample error case:
```js
import Modifier from 'ember-modifier';
export default class WrongModifier extends Modifier {
didReceiveArguments() {
if (this.args.named.shouldFire) {
this.args.named.myCallback?.();
}
}
}
```
Sample success case:
```js
import Modifier from 'ember-modifier';
export default class ScrollPositionModifier extends Modifier {
modify(element, [scrollPosition], { relative }) {
if(relative) {
element.scrollTop += scrollPosition;
} else {
element.scrollTop = scrollPosition;
}
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.