ember-cli / ember-cli/eslint-plugin-ember

New rule: Lint against modifier which does not use the element

Open
#1,510 0 comments 1 reaction 0 assignees View on GitHub
enhancement New Rule
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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.