Skip to content

Commit 9168a57

Browse files
authored
fix(eslint-plugin): [no-uncalled-signals] do not report signal sets within logical expressions (#2581)
1 parent a91597a commit 9168a57

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

packages/eslint-plugin/docs/rules/no-uncalled-signals.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,38 @@ declare function effect(fn: () => void): void;
785785
interface Signal<T> {}
786786
```
787787

788+
<br>
789+
790+
---
791+
792+
<br>
793+
794+
#### Default Config
795+
796+
```json
797+
{
798+
"rules": {
799+
"@angular-eslint/no-uncalled-signals": [
800+
"error"
801+
]
802+
}
803+
}
804+
```
805+
806+
<br>
807+
808+
#### ✅ Valid Code
809+
810+
```ts
811+
let a: Signal<string>;
812+
let b: boolean;
813+
let c = b && a.set('');
814+
815+
interface Signal<T> {
816+
set(value: T): void;
817+
}
818+
```
819+
788820
</details>
789821

790822
<br>

packages/eslint-plugin/src/rules/no-uncalled-signals.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ export default createESLintRule<Options, MessageIds>({
4040
return;
4141
}
4242

43-
// Check if this identifier is the property in a MemberExpression that's being called
43+
// Check if this identifier is the property or object in a MemberExpression that's being called.
44+
// If the identifier is a signal and it's being called, then the signal's value is being read.
45+
// If it's the object, then a method on the signal (most likely the `set` method) is being called.
4446
if (
4547
node.parent.type === AST_NODE_TYPES.MemberExpression &&
46-
node.parent.property === node &&
48+
(node.parent.object === node || node.parent.property === node) &&
4749
node.parent.parent?.type === AST_NODE_TYPES.CallExpression
4850
) {
4951
return;

packages/eslint-plugin/tests/rules/no-uncalled-signals/cases.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ export const valid: readonly (string | ValidTestCase<Options>)[] = [
127127
declare function effect(fn: () => void): void;
128128
interface Signal<T> {}
129129
`,
130+
// https://github.com/angular-eslint/angular-eslint/issues/2574
131+
`
132+
let a: Signal<string>;
133+
let b: boolean;
134+
let c = b && a.set('');
135+
136+
interface Signal<T> {
137+
set(value: T): void;
138+
}
139+
`,
130140
];
131141

132142
export const invalid: readonly InvalidTestCase<MessageIds, Options>[] = [

0 commit comments

Comments
 (0)