Skip to content

Commit ba7a105

Browse files
committed
Sync with ember-template-lint
1 parent 9b7e226 commit ba7a105

2 files changed

Lines changed: 13 additions & 48 deletions

File tree

docs/rules/template-no-redundant-fn.md

Lines changed: 12 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,29 @@
22

33
<!-- end auto-generated rule header -->
44

5-
Disallows unnecessary usage of the `{{fn}}` helper.
5+
The `fn` helper can be used to bind arguments to another function. Using it without any arguments is redundant because then the inner function could just be used directly.
66

7-
When `{{fn}}` is used with only a function reference and no arguments to curry, it's redundant. You can pass the function directly.
8-
9-
## Rule Details
10-
11-
This rule detects when `{{fn}}` is called with only one argument (the function itself) and no curried arguments.
7+
This rule is looking for `fn` helper usages that don't provide any additional arguments to the inner function and warns about them.
128

139
## Examples
1410

15-
Examples of **incorrect** code for this rule:
16-
17-
```gjs
18-
<template>
19-
<button {{on "click" (fn this.handleClick)}}>Click</button>
20-
</template>
21-
```
11+
This rule **forbids** the following:
2212

23-
```gjs
24-
<template>
25-
<Component @action={{fn this.save}} />
26-
</template>
13+
```hbs
14+
<button {{on 'click' (fn this.handleClick)}}>Click Me</button>
2715
```
2816

29-
Examples of **correct** code for this rule:
17+
This rule **allows** the following:
3018

31-
```gjs
32-
<template>
33-
<button {{on "click" this.handleClick}}>Click</button>
34-
</template>
19+
```hbs
20+
<button {{on 'click' this.handleClick}}>Click Me</button>
3521
```
3622

37-
```gjs
38-
<template>
39-
<button {{on "click" (fn this.handleClick arg)}}>Click</button>
40-
</template>
41-
```
42-
43-
```gjs
44-
<template>
45-
<Component @action={{this.save}} />
46-
</template>
47-
```
48-
49-
## Migration
50-
51-
Replace:
52-
53-
```gjs
54-
<button {{on "click" (fn this.action)}}>
55-
```
56-
57-
With:
58-
59-
```gjs
60-
<button {{on "click" this.action}}>
23+
```hbs
24+
<button {{on 'click' (fn this.handleClick 'foo')}}>Click Me</button>
6125
```
6226

6327
## References
6428

65-
- [eslint-plugin-ember template-no-redundant-fn](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/template-no-redundant-fn.md)
29+
- [Ember Guides](https://guides.emberjs.com/release/components/component-state-and-actions/#toc_passing-arguments-to-actions)
30+
- [`fn` API documentation](https://api.emberjs.com/ember/3.20/classes/Ember.Templates.helpers/methods/fn?anchor=fn)

lib/rules/template-no-redundant-fn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
}
3838
const scope = sourceCode.getScope(node);
3939
const ref = scope.references.find((r) => r.identifier === head);
40-
return ref?.resolved != null;
40+
return ref?.resolved !== null && ref?.resolved !== undefined;
4141
}
4242

4343
function checkFnUsage(node) {

0 commit comments

Comments
 (0)