@angular-eslint/eslint-plugin 22.2.1-alpha.13 → 22.2.1-alpha.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/rules/reactive-context-must-read-signal.d.ts +16 -0
- package/dist/rules/reactive-context-must-read-signal.d.ts.map +1 -0
- package/dist/rules/reactive-context-must-read-signal.js +316 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -29,6 +29,7 @@ The premade flat configs that combine these rules are provided by the umbrella [
|
|
|
29
29
|
| [`no-developer-preview`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/no-developer-preview.md) | Disallow using code which is marked as developer preview | | | |
|
|
30
30
|
| [`no-experimental`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/no-experimental.md) | Disallow using code which is marked as experimental | | | |
|
|
31
31
|
| [`no-implicit-take-until-destroyed`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/no-implicit-take-until-destroyed.md) | Ensures that `takeUntilDestroyed()` is called with an explicit `DestroyRef` when used outside of an injection context | | | |
|
|
32
|
+
| [`reactive-context-must-read-signal`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/reactive-context-must-read-signal.md) | Ensures that reactive contexts such as computed(), linkedSignal() and effect() read at least one reactive value (a signal). A reactive context with no reactive dependencies never re-runs, which is almost always a mistake. | | | |
|
|
32
33
|
| [`require-lifecycle-on-prototype`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/require-lifecycle-on-prototype.md) | Ensures that lifecycle methods are defined on the object's prototype instead of on an instance. | | | |
|
|
33
34
|
| [`sort-lifecycle-methods`](https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/docs/rules/sort-lifecycle-methods.md) | Ensures that lifecycle methods are declared in order of execution | | | |
|
|
34
35
|
<!-- prettier-ignore-end -->
|
package/dist/index.d.ts
CHANGED
|
@@ -125,6 +125,9 @@ declare const _default: {
|
|
|
125
125
|
"prefer-standalone": import("@typescript-eslint/utils/ts-eslint").RuleModule<import("./rules/prefer-standalone").MessageIds, [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
126
126
|
name: string;
|
|
127
127
|
};
|
|
128
|
+
"reactive-context-must-read-signal": import("@typescript-eslint/utils/ts-eslint").RuleModule<"mustReadSignal", import("./rules/reactive-context-must-read-signal").Options, import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
129
|
+
name: string;
|
|
130
|
+
};
|
|
128
131
|
"relative-url-prefix": import("@typescript-eslint/utils/ts-eslint").RuleModule<"relativeUrlPrefix", [], import("./utils/create-eslint-rule").RuleDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener> & {
|
|
129
132
|
name: string;
|
|
130
133
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,kBAuDE"}
|
package/dist/index.js
CHANGED
|
@@ -82,6 +82,7 @@ const no_developer_preview_1 = __importStar(require("./rules/no-developer-previe
|
|
|
82
82
|
const no_implicit_take_until_destroyed_1 = __importStar(require("./rules/no-implicit-take-until-destroyed"));
|
|
83
83
|
const computed_must_return_1 = __importStar(require("./rules/computed-must-return"));
|
|
84
84
|
const inject_at_top_1 = __importStar(require("./rules/inject-at-top"));
|
|
85
|
+
const reactive_context_must_read_signal_1 = __importStar(require("./rules/reactive-context-must-read-signal"));
|
|
85
86
|
module.exports = {
|
|
86
87
|
rules: {
|
|
87
88
|
[component_class_suffix_1.RULE_NAME]: component_class_suffix_1.default,
|
|
@@ -123,6 +124,7 @@ module.exports = {
|
|
|
123
124
|
[prefer_signal_model_1.RULE_NAME]: prefer_signal_model_1.default,
|
|
124
125
|
[prefer_signals_1.RULE_NAME]: prefer_signals_1.default,
|
|
125
126
|
[prefer_standalone_1.RULE_NAME]: prefer_standalone_1.default,
|
|
127
|
+
[reactive_context_must_read_signal_1.RULE_NAME]: reactive_context_must_read_signal_1.default,
|
|
126
128
|
[relative_url_prefix_1.RULE_NAME]: relative_url_prefix_1.default,
|
|
127
129
|
[require_lifecycle_on_prototype_1.RULE_NAME]: require_lifecycle_on_prototype_1.default,
|
|
128
130
|
[require_localize_metadata_1.RULE_NAME]: require_localize_metadata_1.default,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
2
|
+
export type Options = [
|
|
3
|
+
{
|
|
4
|
+
readonly checkResources?: boolean;
|
|
5
|
+
}
|
|
6
|
+
];
|
|
7
|
+
export type MessageIds = 'mustReadSignal';
|
|
8
|
+
export declare const RULE_NAME = "reactive-context-must-read-signal";
|
|
9
|
+
declare const _default: ESLintUtils.RuleModule<"mustReadSignal", Options, import("../utils/create-eslint-rule").RuleDocs, ESLintUtils.RuleListener> & {
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
13
|
+
export declare const RULE_DOCS_EXTENSION: {
|
|
14
|
+
rationale: string;
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=reactive-context-must-read-signal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reactive-context-must-read-signal.d.ts","sourceRoot":"","sources":["../../src/rules/reactive-context-must-read-signal.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EAGZ,MAAM,0BAA0B,CAAC;AAMlC,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;KACnC;CACF,CAAC;AACF,MAAM,MAAM,UAAU,GAAG,gBAAgB,CAAC;AAC1C,eAAO,MAAM,SAAS,sCAAsC,CAAC;;;;AA8D7D,wBA2SG;AAEH,eAAO,MAAM,mBAAmB;;CAG/B,CAAC"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.RULE_DOCS_EXTENSION = exports.RULE_NAME = void 0;
|
|
40
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
41
|
+
const tsutils = __importStar(require("ts-api-utils"));
|
|
42
|
+
const typescript_1 = __importDefault(require("typescript"));
|
|
43
|
+
const create_eslint_rule_1 = require("../utils/create-eslint-rule");
|
|
44
|
+
const signals_1 = require("../utils/signals");
|
|
45
|
+
exports.RULE_NAME = 'reactive-context-must-read-signal';
|
|
46
|
+
/**
|
|
47
|
+
* Reactive contexts that should depend on at least one signal. The tracked
|
|
48
|
+
* function is the one whose signal reads define the context's dependencies:
|
|
49
|
+
* - `computed`/`effect`: the first argument.
|
|
50
|
+
* - `linkedSignal`: the first argument (shorthand) or the `source`/`computation`
|
|
51
|
+
* functions of the options object.
|
|
52
|
+
* - `afterRenderEffect`: the first argument (shorthand) or the phase functions
|
|
53
|
+
* of the options object.
|
|
54
|
+
*/
|
|
55
|
+
const DEFAULT_PRIMITIVES = {
|
|
56
|
+
afterRenderEffect: {
|
|
57
|
+
args: [0],
|
|
58
|
+
optionKeys: ['earlyRead', 'write', 'mixedReadWrite', 'read'],
|
|
59
|
+
},
|
|
60
|
+
computed: { args: [0], optionKeys: [] },
|
|
61
|
+
effect: { args: [0], optionKeys: [] },
|
|
62
|
+
linkedSignal: { args: [0], optionKeys: ['source', 'computation'] },
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* For resources, only the `params` (formerly `request`) function defines the
|
|
66
|
+
* reactive dependencies; reading a signal in the `loader`/`stream` does not make
|
|
67
|
+
* the resource reload. These are opt-in via the `checkResources` option.
|
|
68
|
+
*/
|
|
69
|
+
const RESOURCE_PRIMITIVES = {
|
|
70
|
+
resource: { args: [0], optionKeys: ['params', 'request'] },
|
|
71
|
+
rxResource: { args: [0], optionKeys: ['params', 'request'] },
|
|
72
|
+
};
|
|
73
|
+
function isFunction(node) {
|
|
74
|
+
return (node?.type === utils_1.AST_NODE_TYPES.FunctionExpression ||
|
|
75
|
+
node?.type === utils_1.AST_NODE_TYPES.ArrowFunctionExpression);
|
|
76
|
+
}
|
|
77
|
+
exports.default = (0, create_eslint_rule_1.createESLintRule)({
|
|
78
|
+
name: exports.RULE_NAME,
|
|
79
|
+
meta: {
|
|
80
|
+
type: 'problem',
|
|
81
|
+
docs: {
|
|
82
|
+
description: 'Ensures that reactive contexts such as computed(), linkedSignal() and effect() read at least one reactive value (a signal). A reactive context with no reactive dependencies never re-runs, which is almost always a mistake.',
|
|
83
|
+
},
|
|
84
|
+
schema: [
|
|
85
|
+
{
|
|
86
|
+
type: 'object',
|
|
87
|
+
properties: {
|
|
88
|
+
checkResources: {
|
|
89
|
+
type: 'boolean',
|
|
90
|
+
description: 'Also check that the `params` function of `resource()` and `rxResource()` reads a signal.',
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
additionalProperties: false,
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
messages: {
|
|
97
|
+
mustReadSignal: '{{primitive}}() must read at least one signal, otherwise it will never re-run when state changes.',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
defaultOptions: [{ checkResources: false }],
|
|
101
|
+
create(context, [{ checkResources = false }]) {
|
|
102
|
+
const services = utils_1.ESLintUtils.getParserServices(context);
|
|
103
|
+
const checker = services.program.getTypeChecker();
|
|
104
|
+
const primitives = checkResources
|
|
105
|
+
? { ...DEFAULT_PRIMITIVES, ...RESOURCE_PRIMITIVES }
|
|
106
|
+
: DEFAULT_PRIMITIVES;
|
|
107
|
+
const analyses = new Map();
|
|
108
|
+
const trackedFnToCall = new Map();
|
|
109
|
+
const frameStack = [];
|
|
110
|
+
/**
|
|
111
|
+
* Returns true if calling `callee` reads a signal, i.e. `callee` has one of
|
|
112
|
+
* the known signal types. This mirrors the detection used by
|
|
113
|
+
* `no-uncalled-signals`.
|
|
114
|
+
*/
|
|
115
|
+
function isSignalRead(callee) {
|
|
116
|
+
const type = services.getTypeAtLocation(callee);
|
|
117
|
+
const symbol = type.getSymbol();
|
|
118
|
+
if (symbol && signals_1.KNOWN_SIGNAL_TYPES.has(symbol.name)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
// The `Signal` type is a type alias, so it is only reachable via the
|
|
122
|
+
// alias symbol. Other signal types (e.g. `InputSignal`) are interfaces
|
|
123
|
+
// and are found through `getSymbol()` above.
|
|
124
|
+
if (type.aliasSymbol && signals_1.KNOWN_SIGNAL_TYPES.has(type.aliasSymbol.name)) {
|
|
125
|
+
return true;
|
|
126
|
+
}
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns true if the symbol is only declared in TypeScript's default
|
|
131
|
+
* library files. Those declarations (arrays, strings, `Math`, `JSON`,
|
|
132
|
+
* `Object`, `console`, DOM APIs, ...) cannot read an Angular signal.
|
|
133
|
+
*/
|
|
134
|
+
function isDeclaredInDefaultLib(symbol) {
|
|
135
|
+
const declarations = symbol.getDeclarations();
|
|
136
|
+
return (!!declarations?.length &&
|
|
137
|
+
declarations.every((declaration) => services.program.isSourceFileDefaultLibrary(declaration.getSourceFile())));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns true if the node is a function-typed value that we cannot look
|
|
141
|
+
* inside, e.g. `this.transform` in `this.items.map(this.transform)`. The
|
|
142
|
+
* callee could invoke it, and it could read a signal.
|
|
143
|
+
*/
|
|
144
|
+
function isOpaqueFunctionValue(node) {
|
|
145
|
+
if (isFunction(node)) {
|
|
146
|
+
// Inline functions are visited by this rule, so any signal they read is
|
|
147
|
+
// attributed to the enclosing reactive context.
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
if (node.type === utils_1.AST_NODE_TYPES.SpreadElement) {
|
|
151
|
+
// We cannot tell what a spread expands to, so assume the worst.
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return services.getTypeAtLocation(node).getCallSignatures().length > 0;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Records what a call, `new` expression or tagged template tells us about
|
|
158
|
+
* the reactive context we are currently inside. It is only known not to
|
|
159
|
+
* read a signal when the callee resolves to a declaration in a TypeScript
|
|
160
|
+
* default library and no argument is an opaque function value.
|
|
161
|
+
*/
|
|
162
|
+
function analyseCallLike(callee, args, analysis) {
|
|
163
|
+
let symbol = services.getSymbolAtLocation(callee);
|
|
164
|
+
if (symbol && tsutils.isSymbolFlagSet(symbol, typescript_1.default.SymbolFlags.Alias)) {
|
|
165
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
166
|
+
}
|
|
167
|
+
if (!symbol ||
|
|
168
|
+
!isDeclaredInDefaultLib(symbol) ||
|
|
169
|
+
args.some(isOpaqueFunctionValue)) {
|
|
170
|
+
analysis.hasUnknown = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/** The analysis of the reactive context we are currently inside, if any. */
|
|
174
|
+
function currentAnalysis() {
|
|
175
|
+
const top = frameStack[frameStack.length - 1];
|
|
176
|
+
return top && analyses.get(top.call);
|
|
177
|
+
}
|
|
178
|
+
function registerTrackedFunction(node, call, analysis) {
|
|
179
|
+
if (isFunction(node)) {
|
|
180
|
+
trackedFnToCall.set(node, call);
|
|
181
|
+
analysis.hasTrackedFn = true;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// The tracked slot holds something we cannot look inside, such as a
|
|
185
|
+
// signal passed directly as `source`, or a reference to a function
|
|
186
|
+
// declared elsewhere. It may well be reactive, so stay silent.
|
|
187
|
+
analysis.hasUnknown = true;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function registerTrackedOptions(options, call, config, analysis) {
|
|
191
|
+
for (const property of options.properties) {
|
|
192
|
+
if (property.type === utils_1.AST_NODE_TYPES.SpreadElement) {
|
|
193
|
+
// The spread could provide any of the tracked options.
|
|
194
|
+
analysis.hasUnknown = true;
|
|
195
|
+
}
|
|
196
|
+
else if (!property.computed &&
|
|
197
|
+
property.key.type === utils_1.AST_NODE_TYPES.Identifier &&
|
|
198
|
+
config.optionKeys.includes(property.key.name)) {
|
|
199
|
+
registerTrackedFunction(property.value, call, analysis);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function registerTrackedFunctions(call, config, analysis) {
|
|
204
|
+
for (const index of config.args) {
|
|
205
|
+
const arg = call.arguments[index];
|
|
206
|
+
if (arg === undefined) {
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (config.optionKeys.length > 0 &&
|
|
210
|
+
arg.type === utils_1.AST_NODE_TYPES.ObjectExpression) {
|
|
211
|
+
registerTrackedOptions(arg, call, config, analysis);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
registerTrackedFunction(arg, call, analysis);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
function enterFunction(node) {
|
|
219
|
+
const call = trackedFnToCall.get(node);
|
|
220
|
+
if (call) {
|
|
221
|
+
frameStack.push({ fn: node, call });
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
function exitFunction(node) {
|
|
225
|
+
const top = frameStack[frameStack.length - 1];
|
|
226
|
+
if (top?.fn === node) {
|
|
227
|
+
frameStack.pop();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
ArrowFunctionExpression: enterFunction,
|
|
232
|
+
'ArrowFunctionExpression:exit': exitFunction,
|
|
233
|
+
FunctionExpression: enterFunction,
|
|
234
|
+
'FunctionExpression:exit': exitFunction,
|
|
235
|
+
MemberExpression(node) {
|
|
236
|
+
const analysis = currentAnalysis();
|
|
237
|
+
if (!analysis) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
// A getter runs arbitrary code, so `this.name` can read a signal even
|
|
241
|
+
// though it does not look like a call.
|
|
242
|
+
const symbol = services.getSymbolAtLocation(node);
|
|
243
|
+
if (symbol &&
|
|
244
|
+
tsutils.isSymbolFlagSet(symbol, typescript_1.default.SymbolFlags.GetAccessor)) {
|
|
245
|
+
analysis.hasUnknown = true;
|
|
246
|
+
}
|
|
247
|
+
},
|
|
248
|
+
NewExpression(node) {
|
|
249
|
+
const analysis = currentAnalysis();
|
|
250
|
+
if (analysis) {
|
|
251
|
+
analyseCallLike(node.callee, node.arguments, analysis);
|
|
252
|
+
}
|
|
253
|
+
},
|
|
254
|
+
TaggedTemplateExpression(node) {
|
|
255
|
+
const analysis = currentAnalysis();
|
|
256
|
+
if (analysis) {
|
|
257
|
+
analyseCallLike(node.tag, node.quasi.expressions, analysis);
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
CallExpression(node) {
|
|
261
|
+
// Attribute this call to the tracked function we are currently inside,
|
|
262
|
+
// if any. This runs before registration below, so a reactive context
|
|
263
|
+
// nested inside another tracked function is correctly treated as an
|
|
264
|
+
// (unknown) call of the outer function.
|
|
265
|
+
const analysis = currentAnalysis();
|
|
266
|
+
if (analysis) {
|
|
267
|
+
if (isSignalRead(node.callee)) {
|
|
268
|
+
analysis.hasReactiveRead = true;
|
|
269
|
+
}
|
|
270
|
+
else {
|
|
271
|
+
analyseCallLike(node.callee, node.arguments, analysis);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
// Register this call if it is one of the reactive contexts.
|
|
275
|
+
if (node.callee.type !== utils_1.AST_NODE_TYPES.Identifier) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const config = primitives[node.callee.name];
|
|
279
|
+
if (!config) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
const newAnalysis = {
|
|
283
|
+
call: node,
|
|
284
|
+
primitiveName: node.callee.name,
|
|
285
|
+
hasTrackedFn: false,
|
|
286
|
+
hasReactiveRead: false,
|
|
287
|
+
hasUnknown: false,
|
|
288
|
+
};
|
|
289
|
+
registerTrackedFunctions(node, config, newAnalysis);
|
|
290
|
+
analyses.set(node, newAnalysis);
|
|
291
|
+
},
|
|
292
|
+
'CallExpression:exit'(node) {
|
|
293
|
+
const analysis = analyses.get(node);
|
|
294
|
+
if (!analysis) {
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
analyses.delete(node);
|
|
298
|
+
// Only report when we are certain there is no reactivity: there is a
|
|
299
|
+
// tracked function, no signal was read, and there was nothing that
|
|
300
|
+
// might have read a signal on our behalf.
|
|
301
|
+
if (analysis.hasTrackedFn &&
|
|
302
|
+
!analysis.hasReactiveRead &&
|
|
303
|
+
!analysis.hasUnknown) {
|
|
304
|
+
context.report({
|
|
305
|
+
node: analysis.call,
|
|
306
|
+
messageId: 'mustReadSignal',
|
|
307
|
+
data: { primitive: analysis.primitiveName },
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
exports.RULE_DOCS_EXTENSION = {
|
|
315
|
+
rationale: 'Reactive contexts like `computed()`, `linkedSignal()`, `effect()` and `afterRenderEffect()` re-run whenever a signal they read changes. If the relevant function never reads a signal, the context runs once and can never react to anything, so it adds overhead without providing reactivity. This is usually a mistake: either the developer forgot to call a signal (e.g. wrote `firstName` instead of `firstName()`), or the value is actually static and should be a plain constant, a `signal()`, or an `afterNextRender()` in the case of `afterRenderEffect()`. To avoid false positives, the rule only reports when everything the tracked function does is known not to read a signal. Calls into the TypeScript standard library (arrays, strings, `Math`, `JSON`, `console`, DOM APIs, etc.) are known to be safe; anything else keeps the rule silent, including a helper function, a service method, a getter, an unresolved symbol, and any Angular API such as `untracked()`. For `resource()`/`rxResource()` only the `params` function defines the dependencies, and these are opt-in via the `checkResources` option.',
|
|
316
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-eslint/eslint-plugin",
|
|
3
|
-
"version": "22.2.1-alpha.
|
|
3
|
+
"version": "22.2.1-alpha.14",
|
|
4
4
|
"description": "ESLint plugin for Angular applications, following https://angular.dev/style-guide",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"LICENSE"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@angular-eslint/bundled-angular-compiler": "22.2.1-alpha.
|
|
23
|
-
"@angular-eslint/utils": "22.2.1-alpha.
|
|
22
|
+
"@angular-eslint/bundled-angular-compiler": "22.2.1-alpha.14",
|
|
23
|
+
"@angular-eslint/utils": "22.2.1-alpha.14",
|
|
24
24
|
"ts-api-utils": "^2.1.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@angular-eslint/test-utils": "22.2.1-alpha.
|
|
27
|
+
"@angular-eslint/test-utils": "22.2.1-alpha.14"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@typescript-eslint/utils": "^8.0.0",
|