@ethlete/eslint-plugin 1.0.0-next.23 → 1.0.0-next.24

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.json +2 -2
  3. package/src/configs/recommended.js +3 -0
  4. package/src/index.js +2 -0
  5. package/src/rules/angular-decorator-property-order.js +20 -20
  6. package/src/rules/class-constant-property.js +8 -14
  7. package/src/rules/class-member-order.js +77 -46
  8. package/src/rules/inject-member-accessibility.js +5 -3
  9. package/src/rules/internals/angular-io.js +12 -13
  10. package/src/rules/internals/angular-member-visibility.js +11 -7
  11. package/src/rules/internals/import-resolution.js +191 -0
  12. package/src/rules/no-angular-router-api.js +23 -29
  13. package/src/rules/no-angular-seo-services.js +14 -9
  14. package/src/rules/no-cdk-import.js +7 -14
  15. package/src/rules/no-document-cookie.js +3 -0
  16. package/src/rules/no-effect-cleanup-return.js +7 -3
  17. package/src/rules/no-empty-angular-metadata-arrays.js +3 -17
  18. package/src/rules/no-inject-chain.js +3 -1
  19. package/src/rules/no-leading-underscore-class-member.js +26 -3
  20. package/src/rules/no-legacy-angular-decorators.js +9 -21
  21. package/src/rules/no-legacy-query-import.js +6 -15
  22. package/src/rules/no-locale-id.js +4 -4
  23. package/src/rules/no-member-alias.js +11 -7
  24. package/src/rules/no-native-html-input-name.js +1 -1
  25. package/src/rules/no-pipe-logic.js +10 -17
  26. package/src/rules/no-redundant-on-push-change-detection.js +9 -23
  27. package/src/rules/no-rxjs-in-effect.js +12 -8
  28. package/src/rules/no-screaming-case-local.js +1 -0
  29. package/src/rules/no-standalone-flag.js +3 -17
  30. package/src/rules/no-subscribe-in-pipe.js +3 -2
  31. package/src/rules/no-template-literal-before-inline-template.js +3 -14
  32. package/src/rules/no-trivial-return-type.js +1 -0
  33. package/src/rules/no-trivial-wrapper-method.js +10 -16
  34. package/src/rules/no-typed-injected-element-ref.js +14 -17
  35. package/src/rules/no-unused-class-member.js +6 -9
  36. package/src/rules/prefer-clone-equal.js +8 -6
  37. package/src/rules/prefer-concise-angular-host-directives.js +23 -29
  38. package/src/rules/prefer-concise-angular-style-metadata.js +8 -16
  39. package/src/rules/prefer-element-dimensions.js +9 -10
  40. package/src/rules/prefer-linked-signal.js +7 -4
  41. package/src/rules/prefer-match-media.js +10 -14
  42. package/src/rules/prefer-present-tense-output.js +1 -1
  43. package/src/rules/prefer-rxjs-timer.js +3 -1
  44. package/src/rules/require-dollar-suffix.js +7 -4
  45. package/src/rules/require-on-push-change-detection.js +17 -25
  46. package/src/rules/require-view-encapsulation-none.js +17 -25
  47. package/src/rules/take-until-destroyed-last.js +64 -0
  48. package/src/rules/template-member-accessibility.js +8 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.0-next.24
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `take-until-destroyed-last` to the recommended config: `takeUntilDestroyed()` must be the last operator in a `.pipe()`, since an operator after it can keep the subscription alive.
8
+
9
+ ### Patch Changes
10
+
11
+ - `class-member-order` now fixes classes with `static` members or index signatures and keeps a trailing comment with its member, and `prefer-concise-angular-host-directives` no longer drops or misplaces comments.
12
+ - Angular and RxJS rules now resolve `Component`, `inject`, `input`, `effect` and friends through their imports, `document` and `setTimeout` match only the globals, and import bans also report re-exports and dynamic imports.
13
+ - Several fixers no longer emit broken code (a dangling `other._value`, a duplicate `styleUrl`, a dropped `host` spread), `no-trivial-return-type` checks function declarations, `no-screaming-case-local` reports a function once, and `standalone` sorts after `selector`.
14
+
3
15
  ## 1.0.0-next.23
4
16
 
5
17
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethlete/eslint-plugin",
3
- "version": "1.0.0-next.23",
3
+ "version": "1.0.0-next.24",
4
4
  "license": "MIT",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -11,4 +11,4 @@
11
11
  "eslint": ">=9.0.0",
12
12
  "typescript": ">=5.9.0"
13
13
  }
14
- }
14
+ }
@@ -239,6 +239,9 @@ const recommendedTs = {
239
239
  // No .subscribe() inside a .pipe() callback
240
240
  'ethlete/no-subscribe-in-pipe': 'error',
241
241
 
242
+ // takeUntilDestroyed() is the last operator in a .pipe()
243
+ 'ethlete/take-until-destroyed-last': 'error',
244
+
242
245
  // No async/await — asynchronous work is modelled as cold Observables
243
246
  'ethlete/no-async-await': 'error',
244
247
 
package/src/index.js CHANGED
@@ -60,6 +60,7 @@ const noCdkImport = require('./rules/no-cdk-import');
60
60
  const noLegacyQueryImport = require('./rules/no-legacy-query-import');
61
61
  const noAsyncAwait = require('./rules/no-async-await');
62
62
  const noEnum = require('./rules/no-enum');
63
+ const takeUntilDestroyedLast = require('./rules/take-until-destroyed-last');
63
64
  const { recommendedTs, recommendedTemplate, recommendedSpec } = require('./configs/recommended');
64
65
  const { version } = require('../package.json');
65
66
 
@@ -74,6 +75,7 @@ const plugin = {
74
75
  'no-legacy-prepare-without-injector': noLegacyPrepareWithoutInjector,
75
76
  'no-trivial-return-type': noTrivialReturnType,
76
77
  'no-subscribe-in-pipe': noSubscribeInPipe,
78
+ 'take-until-destroyed-last': takeUntilDestroyedLast,
77
79
  'no-rxjs-in-effect': noRxjsInEffect,
78
80
  'no-effect-cleanup-return': noEffectCleanupReturn,
79
81
  'no-readonly-signal': noReadonlySignal,
@@ -1,6 +1,8 @@
1
1
  // @ts-check
2
2
  'use strict';
3
3
 
4
+ const { getAngularDecoratorName } = require('./internals/import-resolution');
5
+
4
6
  /** @typedef {'Component' | 'Directive'} TDecoratorName */
5
7
  /** @typedef {{ order: string[]; orderText: string }} TDecoratorConfig */
6
8
  /** @typedef {{ range: [number, number] }} TNodeWithRange */
@@ -14,11 +16,13 @@ const DECORATOR_CONFIG = {
14
16
  Component: {
15
17
  order: [
16
18
  'selector',
19
+ 'standalone',
17
20
  'template',
18
21
  'styleUrl',
19
22
  'encapsulation',
20
23
  'changeDetection',
21
24
  'imports',
25
+ 'deferredImports',
22
26
  'providers',
23
27
  'viewProviders',
24
28
  'animations',
@@ -29,16 +33,28 @@ const DECORATOR_CONFIG = {
29
33
  'outputs',
30
34
  'queries',
31
35
  'preserveWhitespaces',
36
+ 'interpolation',
32
37
  'schemas',
33
38
  'jit',
34
39
  'exportAs',
35
40
  ],
36
41
  orderText:
37
- 'selector, template/templateUrl, styleUrl/styleUrls, encapsulation, changeDetection, imports, providers, viewProviders, animations, hostDirectives, host, styles, inputs, outputs, queries, preserveWhitespaces, schemas, jit, exportAs',
42
+ 'selector, standalone, template/templateUrl, styleUrl/styleUrls, encapsulation, changeDetection, imports, deferredImports, providers, viewProviders, animations, hostDirectives, host, styles, inputs, outputs, queries, preserveWhitespaces, interpolation, schemas, jit, exportAs',
38
43
  },
39
44
  Directive: {
40
- order: ['selector', 'exportAs', 'providers', 'inputs', 'outputs', 'queries', 'hostDirectives', 'host', 'jit'],
41
- orderText: 'selector, exportAs, providers, inputs, outputs, queries, hostDirectives, host, jit',
45
+ order: [
46
+ 'selector',
47
+ 'standalone',
48
+ 'exportAs',
49
+ 'providers',
50
+ 'inputs',
51
+ 'outputs',
52
+ 'queries',
53
+ 'hostDirectives',
54
+ 'host',
55
+ 'jit',
56
+ ],
57
+ orderText: 'selector, standalone, exportAs, providers, inputs, outputs, queries, hostDirectives, host, jit',
42
58
  },
43
59
  };
44
60
 
@@ -66,22 +82,6 @@ const getOrderKey = (decoratorName, propertyName) => {
66
82
  return propertyName;
67
83
  };
68
84
 
69
- /**
70
- * @param {import('eslint').Rule.Node} node
71
- * @returns {TDecoratorName | null}
72
- */
73
- const getDecoratorName = (node) => {
74
- const decorator = /** @type {any} */ (node);
75
- if (decorator.type !== 'Decorator') return null;
76
-
77
- const expression = decorator.expression;
78
- if (expression.type === 'CallExpression') {
79
- return expression.callee.type === 'Identifier' ? expression.callee.name : null;
80
- }
81
-
82
- return expression.type === 'Identifier' ? expression.name : null;
83
- };
84
-
85
85
  /** @type {import('eslint').Rule.RuleModule} */
86
86
  const angularDecoratorPropertyOrder = {
87
87
  meta: {
@@ -101,7 +101,7 @@ const angularDecoratorPropertyOrder = {
101
101
  return {
102
102
  /** @param {import('eslint').Rule.Node} node */
103
103
  Decorator(node) {
104
- const decoratorName = getDecoratorName(node);
104
+ const decoratorName = getAngularDecoratorName(context.sourceCode, node);
105
105
  if (decoratorName !== 'Component' && decoratorName !== 'Directive') return;
106
106
 
107
107
  const decorator = /** @type {any} */ (node);
@@ -1,24 +1,18 @@
1
1
  // @ts-check
2
2
  'use strict';
3
3
 
4
+ const { getAngularDecoratorName } = require('./internals/import-resolution');
5
+
4
6
  const SCREAMING_CASE_RE = /^[A-Z][A-Z0-9_]*$/;
5
7
 
6
8
  /**
9
+ * @param {import('eslint').SourceCode} sourceCode
7
10
  * @param {any} classNode
8
11
  */
9
- const hasPipeDecorator = (classNode) => {
10
- const decorators = classNode.decorators ?? [];
11
- return decorators.some((/** @type {any} */ dec) => {
12
- const expr = dec.expression;
13
- if (expr.type === 'CallExpression') {
14
- return expr.callee.type === 'Identifier' && expr.callee.name === 'Pipe';
15
- }
16
- if (expr.type === 'Identifier') {
17
- return expr.name === 'Pipe';
18
- }
19
- return false;
20
- });
21
- };
12
+ const hasPipeDecorator = (sourceCode, classNode) =>
13
+ (classNode.decorators ?? []).some(
14
+ (/** @type {any} */ decorator) => getAngularDecoratorName(sourceCode, decorator) === 'Pipe',
15
+ );
22
16
 
23
17
  const REACTIVE_APIS = new Set([
24
18
  'signal',
@@ -353,7 +347,7 @@ const classConstantProperty = {
353
347
  continue;
354
348
  }
355
349
 
356
- if (memberName === 'transform' && hasPipeDecorator(node.parent)) {
350
+ if (memberName === 'transform' && hasPipeDecorator(context.sourceCode, node.parent)) {
357
351
  continue;
358
352
  }
359
353
 
@@ -1,13 +1,15 @@
1
1
  // @ts-check
2
2
  'use strict';
3
3
 
4
+ const { ANGULAR_CORE, getImportedName } = require('./internals/import-resolution');
5
+
4
6
  /** @typedef {'inject' | 'input' | 'output' | 'query' | 'property' | 'constructor' | 'method' | 'private-method'} TMemberGroup */
5
7
  /** @typedef {{ dependencies: Set<string>; group: TMemberGroup; groupIndex: number; name: string; node: any; originalIndex: number }} TMemberEntry */
6
- /** @typedef {TMemberEntry & { segmentText: string }} TSegmentEntry */
7
8
 
8
9
  const INPUT_APIS = new Set(['input', 'model']);
9
10
  const OUTPUT_APIS = new Set(['output', 'outputFromObservable']);
10
11
  const QUERY_APIS = new Set(['viewChild', 'viewChildren', 'contentChild', 'contentChildren']);
12
+ const ANGULAR_API_SOURCES = [ANGULAR_CORE, '@angular/core/rxjs-interop'];
11
13
 
12
14
  /** @type {TMemberGroup[]} */
13
15
  const MEMBER_GROUP_ORDER = [
@@ -71,49 +73,70 @@ const getCallRootName = (value) => {
71
73
  };
72
74
 
73
75
  /**
76
+ * @param {import('eslint').SourceCode} sourceCode
77
+ * @param {any} value
78
+ */
79
+ const getAngularCallName = (sourceCode, value) => {
80
+ if (!value || value.type !== 'CallExpression') return null;
81
+
82
+ const { callee } = value;
83
+ const isRequired =
84
+ callee.type === 'MemberExpression' &&
85
+ !callee.computed &&
86
+ callee.property.type === 'Identifier' &&
87
+ callee.property.name === 'required';
88
+
89
+ return getImportedName(sourceCode, isRequired ? callee.object : callee, ANGULAR_API_SOURCES);
90
+ };
91
+
92
+ /**
93
+ * @param {import('eslint').SourceCode} sourceCode
74
94
  * @param {any} node
75
95
  * @param {Set<string>} apiNames
76
96
  */
77
- const isPropertyInitializedWith = (node, apiNames) => {
97
+ const isPropertyInitializedWith = (sourceCode, node, apiNames) => {
78
98
  if (node.type !== 'PropertyDefinition') return false;
79
99
 
80
- const apiName = getCallRootName(node.value);
100
+ const apiName = getAngularCallName(sourceCode, node.value);
81
101
  return apiName !== null && apiNames.has(apiName);
82
102
  };
83
103
 
84
104
  const INJECT_HELPER_NAME_PATTERN = /^inject[A-Z]/;
85
105
 
86
106
  /**
107
+ * @param {import('eslint').SourceCode} sourceCode
87
108
  * @param {any} node
88
109
  */
89
- const isPropertyInitializedWithInject = (node) => {
110
+ const isPropertyInitializedWithInject = (sourceCode, node) => {
90
111
  if (node.type !== 'PropertyDefinition') return false;
112
+ if (getAngularCallName(sourceCode, node.value) === 'inject') return true;
91
113
 
92
- const apiName = getCallRootName(node.value);
93
- return apiName !== null && (apiName === 'inject' || INJECT_HELPER_NAME_PATTERN.test(apiName));
114
+ const rootName = getCallRootName(node.value);
115
+ return rootName !== null && INJECT_HELPER_NAME_PATTERN.test(rootName);
94
116
  };
95
117
 
96
118
  /**
119
+ * @param {import('eslint').SourceCode} sourceCode
97
120
  * @param {any} node
98
121
  * @returns {TMemberGroup | null}
99
122
  */
100
- const getMemberGroup = (node) => {
123
+ const getMemberGroup = (sourceCode, node) => {
101
124
  if (node.static) return null;
102
125
 
103
126
  if (node.type === 'PropertyDefinition') {
104
- if (isPropertyInitializedWithInject(node)) {
127
+ if (isPropertyInitializedWithInject(sourceCode, node)) {
105
128
  return 'inject';
106
129
  }
107
130
 
108
- if (isPropertyInitializedWith(node, INPUT_APIS)) {
131
+ if (isPropertyInitializedWith(sourceCode, node, INPUT_APIS)) {
109
132
  return 'input';
110
133
  }
111
134
 
112
- if (isPropertyInitializedWith(node, OUTPUT_APIS)) {
135
+ if (isPropertyInitializedWith(sourceCode, node, OUTPUT_APIS)) {
113
136
  return 'output';
114
137
  }
115
138
 
116
- if (isPropertyInitializedWith(node, QUERY_APIS)) {
139
+ if (isPropertyInitializedWith(sourceCode, node, QUERY_APIS)) {
117
140
  return 'query';
118
141
  }
119
142
 
@@ -188,12 +211,13 @@ const getInitializerDependencies = (node) => {
188
211
  };
189
212
 
190
213
  /**
214
+ * @param {import('eslint').SourceCode} sourceCode
191
215
  * @param {any} node
192
216
  * @param {number} originalIndex
193
217
  * @returns {TMemberEntry | null}
194
218
  */
195
- const toMemberEntry = (node, originalIndex) => {
196
- const group = getMemberGroup(node);
219
+ const toMemberEntry = (sourceCode, node, originalIndex) => {
220
+ const group = getMemberGroup(sourceCode, node);
197
221
  const name = getMemberName(node);
198
222
 
199
223
  if (group === null || name === null) {
@@ -273,12 +297,24 @@ const sortMembers = (members) => {
273
297
  return sortedMembers;
274
298
  };
275
299
 
300
+ /**
301
+ * @param {import('eslint').SourceCode} sourceCode
302
+ * @param {any} node
303
+ */
304
+ const getMemberEnd = (sourceCode, node) => {
305
+ const trailingComments = sourceCode
306
+ .getCommentsAfter(node)
307
+ .filter((comment) => comment.loc?.start.line === node.loc.end.line);
308
+ const lastComment = trailingComments.at(-1);
309
+
310
+ return lastComment?.range ? lastComment.range[1] : node.range[1];
311
+ };
312
+
276
313
  /**
277
314
  * @param {import('eslint').SourceCode} sourceCode
278
315
  * @param {any} classBodyNode
279
- * @param {TMemberEntry[]} members
280
316
  */
281
- const getSegmentEntries = (sourceCode, classBodyNode, members) => {
317
+ const getSegments = (sourceCode, classBodyNode) => {
282
318
  const openingBrace = sourceCode.getFirstToken(classBodyNode);
283
319
  const closingBrace = sourceCode.getLastToken(classBodyNode);
284
320
 
@@ -288,22 +324,23 @@ const getSegmentEntries = (sourceCode, classBodyNode, members) => {
288
324
 
289
325
  let segmentStart = openingBrace.range[1];
290
326
 
291
- const segmentEntries = members.map((member) => {
292
- const segmentText = sourceCode.text.slice(segmentStart, member.node.range[1]);
293
- segmentStart = member.node.range[1];
327
+ /** @type {string[]} */
328
+ const segmentTexts = classBodyNode.body.map(
329
+ /** @param {any} node */ (node) => {
330
+ const segmentEnd = getMemberEnd(sourceCode, node);
331
+ const segmentText = sourceCode.text.slice(segmentStart, segmentEnd);
332
+ segmentStart = segmentEnd;
294
333
 
295
- return {
296
- ...member,
297
- segmentText,
298
- };
299
- });
334
+ return segmentText;
335
+ },
336
+ );
300
337
 
301
338
  const suffix = sourceCode.text.slice(segmentStart, closingBrace.range[0]);
302
339
 
303
340
  return {
304
341
  closingBrace,
305
342
  openingBrace,
306
- segmentEntries,
343
+ segmentTexts,
307
344
  suffix,
308
345
  };
309
346
  };
@@ -314,43 +351,37 @@ const getSegmentEntries = (sourceCode, classBodyNode, members) => {
314
351
  * @param {TMemberEntry[]} members
315
352
  */
316
353
  const buildClassOrderFix = (sourceCode, classBodyNode, members) => {
317
- if (classBodyNode.body.length !== members.length) {
318
- return null;
319
- }
320
-
321
354
  const sortedMembers = sortMembers(members);
322
355
 
323
356
  if (!sortedMembers) {
324
357
  return null;
325
358
  }
326
359
 
327
- const segments = getSegmentEntries(sourceCode, classBodyNode, members);
360
+ const isAlreadySorted = sortedMembers.every((member, index) => member === members[index]);
328
361
 
329
- if (!segments) {
362
+ if (isAlreadySorted) {
330
363
  return null;
331
364
  }
332
365
 
333
- const { closingBrace, openingBrace, segmentEntries, suffix } = segments;
334
- const segmentEntriesByOriginalIndex = new Map(
335
- segmentEntries.map(
336
- /** @param {TSegmentEntry} segmentEntry */ (segmentEntry) => [segmentEntry.originalIndex, segmentEntry],
337
- ),
338
- );
339
- const sortedSegmentEntries = sortedMembers.map((member) => segmentEntriesByOriginalIndex.get(member.originalIndex));
366
+ const segments = getSegments(sourceCode, classBodyNode);
340
367
 
341
- if (sortedSegmentEntries.some((entry) => entry === undefined)) {
368
+ if (!segments) {
342
369
  return null;
343
370
  }
344
371
 
345
- const isAlreadySorted = sortedSegmentEntries.every((entry, index) => entry === segmentEntries[index]);
346
-
347
- if (isAlreadySorted) {
348
- return null;
349
- }
372
+ const { closingBrace, openingBrace, segmentTexts, suffix } = segments;
373
+ const rankedIndexes = new Set(members.map((member) => member.originalIndex));
374
+ let nextSortedMember = 0;
350
375
 
351
- const reorderedBody = sortedSegmentEntries.map((entry) => entry.segmentText).join('') + suffix;
376
+ const reorderedBody =
377
+ segmentTexts
378
+ .map((segmentText, index) =>
379
+ rankedIndexes.has(index) ? segmentTexts[sortedMembers[nextSortedMember++].originalIndex] : segmentText,
380
+ )
381
+ .join('') + suffix;
352
382
 
353
- return (fixer) => fixer.replaceTextRange([openingBrace.range[1], closingBrace.range[0]], reorderedBody);
383
+ return (/** @type {import('eslint').Rule.RuleFixer} */ fixer) =>
384
+ fixer.replaceTextRange([openingBrace.range[1], closingBrace.range[0]], reorderedBody);
354
385
  };
355
386
 
356
387
  /** @type {import('eslint').Rule.RuleModule} */
@@ -379,7 +410,7 @@ const classMemberOrder = {
379
410
  const members = node.body
380
411
  .map(
381
412
  /** @param {any} member @param {number} originalIndex */ (member, originalIndex) =>
382
- toMemberEntry(member, originalIndex),
413
+ toMemberEntry(sourceCode, member, originalIndex),
383
414
  )
384
415
  .filter(Boolean);
385
416
 
@@ -2,15 +2,17 @@
2
2
  'use strict';
3
3
 
4
4
  const { getMemberName, isReferencedFromTemplateOrHost } = require('./internals/angular-member-visibility');
5
+ const { isImportedAs } = require('./internals/import-resolution');
5
6
  const { buildAccessibilityFix } = require('./internals/member-accessibility-fix');
6
7
 
7
8
  /**
9
+ * @param {import('eslint').SourceCode} sourceCode
8
10
  * @param {any} node
9
11
  */
10
- const isInjectCall = (node) => {
12
+ const isInjectCall = (sourceCode, node) => {
11
13
  if (!node || node.type !== 'PropertyDefinition' || !node.value) return false;
12
14
  if (node.value.type !== 'CallExpression') return false;
13
- return node.value.callee.type === 'Identifier' && node.value.callee.name === 'inject';
15
+ return isImportedAs(sourceCode, node.value.callee, 'inject');
14
16
  };
15
17
 
16
18
  /** @type {import('eslint').Rule.RuleModule} */
@@ -36,7 +38,7 @@ const injectMemberAccessibility = {
36
38
 
37
39
  return {
38
40
  PropertyDefinition(node) {
39
- if (!isInjectCall(node)) return;
41
+ if (!isInjectCall(context.sourceCode, node)) return;
40
42
 
41
43
  const classNode = node.parent && node.parent.type === 'ClassBody' ? node.parent.parent : null;
42
44
  if (!classNode || (classNode.type !== 'ClassDeclaration' && classNode.type !== 'ClassExpression')) return;
@@ -18,6 +18,10 @@
18
18
  * (or null when the property is not a reactive I/O declaration).
19
19
  */
20
20
 
21
+ const { ANGULAR_CORE, getImportedName } = require('./import-resolution');
22
+
23
+ const ANGULAR_IO_SOURCES = [ANGULAR_CORE, '@angular/core/rxjs-interop'];
24
+
21
25
  /** Factory identifier → I/O kind. */
22
26
  const IO_FACTORIES = {
23
27
  input: 'input',
@@ -31,42 +35,37 @@ const IO_FACTORIES = {
31
35
  * plain form (`input(...)`) and the `.required` member form
32
36
  * (`input.required(...)`).
33
37
  *
38
+ * @param {import('eslint').SourceCode} sourceCode
34
39
  * @param {any} callee
35
40
  * @returns {string | null}
36
41
  */
37
- const getFactoryName = (callee) => {
42
+ const getFactoryName = (sourceCode, callee) => {
38
43
  if (!callee) return null;
39
44
 
40
- if (callee.type === 'Identifier') return callee.name;
41
-
42
- // input.required(...) / model.required(...)
43
- if (
45
+ const isRequired =
44
46
  callee.type === 'MemberExpression' &&
45
47
  !callee.computed &&
46
- callee.object.type === 'Identifier' &&
47
48
  callee.property.type === 'Identifier' &&
48
- callee.property.name === 'required'
49
- ) {
50
- return callee.object.name;
51
- }
49
+ callee.property.name === 'required';
52
50
 
53
- return null;
51
+ return getImportedName(sourceCode, isRequired ? callee.object : callee, ANGULAR_IO_SOURCES);
54
52
  };
55
53
 
56
54
  /**
57
55
  * Classifies a class property as an Angular signal input/model/output.
58
56
  *
57
+ * @param {import('eslint').SourceCode} sourceCode
59
58
  * @param {any} node PropertyDefinition
60
59
  * @returns {{ kind: 'input' | 'model' | 'output', name: string, keyNode: any } | null}
61
60
  */
62
- const getReactiveIo = (node) => {
61
+ const getReactiveIo = (sourceCode, node) => {
63
62
  if (!node || node.type !== 'PropertyDefinition') return null;
64
63
  if (node.computed || node.key.type !== 'Identifier') return null;
65
64
 
66
65
  const value = node.value;
67
66
  if (!value || value.type !== 'CallExpression') return null;
68
67
 
69
- const factory = getFactoryName(value.callee);
68
+ const factory = getFactoryName(sourceCode, value.callee);
70
69
  if (!factory) return null;
71
70
 
72
71
  if (!Object.hasOwn(IO_FACTORIES, factory)) return null;
@@ -1,6 +1,8 @@
1
1
  // @ts-check
2
2
  'use strict';
3
3
 
4
+ const { getAngularDecoratorName } = require('./import-resolution');
5
+
4
6
  const fs = require('fs');
5
7
  const path = require('path');
6
8
 
@@ -10,21 +12,22 @@ const path = require('path');
10
12
  const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
11
13
 
12
14
  /**
15
+ * @param {import('eslint').SourceCode} sourceCode
13
16
  * @param {any} decorator
14
17
  */
15
- const getDecoratorCall = (decorator) => {
16
- if (!decorator || decorator.type !== 'Decorator') return null;
18
+ const getDecoratorCall = (sourceCode, decorator) => {
19
+ const name = getAngularDecoratorName(sourceCode, decorator);
20
+ if (!name) return null;
17
21
 
18
22
  const expression = decorator.expression;
19
23
  if (expression.type !== 'CallExpression') return null;
20
- if (expression.callee.type !== 'Identifier') return null;
21
24
  if (expression.arguments.length === 0) return null;
22
25
 
23
26
  const metadata = expression.arguments[0];
24
27
  if (!metadata || metadata.type !== 'ObjectExpression') return null;
25
28
 
26
29
  return {
27
- name: expression.callee.name,
30
+ name,
28
31
  metadata,
29
32
  };
30
33
  };
@@ -135,11 +138,12 @@ const isDynamicHostBindingKey = (keyName) => {
135
138
  };
136
139
 
137
140
  /**
141
+ * @param {import('eslint').SourceCode} sourceCode
138
142
  * @param {any} classNode
139
143
  */
140
- const getAngularMetadata = (classNode) => {
144
+ const getAngularMetadata = (sourceCode, classNode) => {
141
145
  for (const decorator of classNode.decorators || []) {
142
- const call = getDecoratorCall(decorator);
146
+ const call = getDecoratorCall(sourceCode, decorator);
143
147
  if (!call) continue;
144
148
 
145
149
  if (call.name === 'Component' || call.name === 'Directive') {
@@ -217,7 +221,7 @@ const getMemberName = (node) => {
217
221
  * @param {import('eslint').Rule.RuleContext} context
218
222
  */
219
223
  const isReferencedFromTemplateOrHost = (classNode, memberName, context) => {
220
- const angularMetadata = getAngularMetadata(classNode);
224
+ const angularMetadata = getAngularMetadata(context.sourceCode, classNode);
221
225
 
222
226
  if (!angularMetadata) {
223
227
  return false;