@angular-eslint/eslint-plugin 22.0.1-alpha.7 → 22.0.1-alpha.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"no-implicit-take-until-destroyed.d.ts","sourceRoot":"","sources":["../../src/rules/no-implicit-take-until-destroyed.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,8BAA8B,CAAC;AACxD,eAAO,MAAM,SAAS,qCAAqC,CAAC;;;;AAO5D,wBAgCG;AAqEH,eAAO,MAAM,mBAAmB;;CAE/B,CAAC"}
1
+ {"version":3,"file":"no-implicit-take-until-destroyed.d.ts","sourceRoot":"","sources":["../../src/rules/no-implicit-take-until-destroyed.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,8BAA8B,CAAC;AACxD,eAAO,MAAM,SAAS,qCAAqC,CAAC;;;;AAO5D,wBAgCG;AAwMH,eAAO,MAAM,mBAAmB;;CAE/B,CAAC"}
@@ -55,6 +55,17 @@ function isInInjectionContext(node) {
55
55
  return true;
56
56
  }
57
57
  }
58
+ if (isNonConstructorMethod(current)) {
59
+ const classDeclaration = utils_1.ASTUtils.getNearestNodeFrom(current, utils_1.ASTUtils.isClassDeclaration);
60
+ if (classDeclaration) {
61
+ const decorator = utils_1.ASTUtils.getAngularClassDecorator(classDeclaration);
62
+ if (decorator &&
63
+ decorator !== 'NgModule' &&
64
+ isMethodCalledFromInjectionContext(current, classDeclaration)) {
65
+ return true;
66
+ }
67
+ }
68
+ }
58
69
  current = current.parent;
59
70
  }
60
71
  return false;
@@ -62,6 +73,78 @@ function isInInjectionContext(node) {
62
73
  function isConstructorMethod(node) {
63
74
  return (node.type === utils_2.AST_NODE_TYPES.MethodDefinition && node.kind === 'constructor');
64
75
  }
76
+ function isNonConstructorMethod(node) {
77
+ return (node.type === utils_2.AST_NODE_TYPES.MethodDefinition && node.kind !== 'constructor');
78
+ }
79
+ function getMethodName(node) {
80
+ if (node.key.type === utils_2.AST_NODE_TYPES.Identifier ||
81
+ node.key.type === utils_2.AST_NODE_TYPES.PrivateIdentifier) {
82
+ return node.key.name;
83
+ }
84
+ return null;
85
+ }
86
+ function isMethodCalledFromInjectionContext(method, classDeclaration) {
87
+ const methodName = getMethodName(method);
88
+ if (!methodName) {
89
+ return false;
90
+ }
91
+ const isPrivateField = method.key.type === utils_2.AST_NODE_TYPES.PrivateIdentifier;
92
+ for (const member of classDeclaration.body.body) {
93
+ if (!isConstructorMethod(member) &&
94
+ !utils_1.ASTUtils.isPropertyDefinition(member)) {
95
+ continue;
96
+ }
97
+ if (containsCallToMethod(member, methodName, isPrivateField)) {
98
+ return true;
99
+ }
100
+ }
101
+ return false;
102
+ }
103
+ function isASTNode(value) {
104
+ return (value !== null &&
105
+ typeof value === 'object' &&
106
+ 'type' in value &&
107
+ typeof value.type === 'string');
108
+ }
109
+ function containsCallToMethod(node, methodName, isPrivateField) {
110
+ if (node.type === utils_2.AST_NODE_TYPES.CallExpression &&
111
+ node.callee.type === utils_2.AST_NODE_TYPES.MemberExpression) {
112
+ const { object, property } = node.callee;
113
+ if (object.type === utils_2.AST_NODE_TYPES.ThisExpression) {
114
+ if (isPrivateField &&
115
+ property.type === utils_2.AST_NODE_TYPES.PrivateIdentifier &&
116
+ property.name === methodName) {
117
+ return true;
118
+ }
119
+ if (!isPrivateField &&
120
+ property.type === utils_2.AST_NODE_TYPES.Identifier &&
121
+ property.name === methodName) {
122
+ return true;
123
+ }
124
+ }
125
+ }
126
+ for (const key of Object.keys(node)) {
127
+ if (key === 'parent')
128
+ continue;
129
+ const child = node[key];
130
+ if (child && typeof child === 'object') {
131
+ if (Array.isArray(child)) {
132
+ for (const item of child) {
133
+ if (isASTNode(item) &&
134
+ containsCallToMethod(item, methodName, isPrivateField)) {
135
+ return true;
136
+ }
137
+ }
138
+ }
139
+ else if (isASTNode(child)) {
140
+ if (containsCallToMethod(child, methodName, isPrivateField)) {
141
+ return true;
142
+ }
143
+ }
144
+ }
145
+ }
146
+ return false;
147
+ }
65
148
  function isInFactoryFunction(node) {
66
149
  if (node.type !== utils_2.AST_NODE_TYPES.ArrowFunctionExpression &&
67
150
  node.type !== utils_2.AST_NODE_TYPES.FunctionExpression) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@angular-eslint/eslint-plugin",
3
- "version": "22.0.1-alpha.7",
3
+ "version": "22.0.1-alpha.9",
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,11 +19,11 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "ts-api-utils": "^2.1.0",
22
- "@angular-eslint/utils": "22.0.1-alpha.7",
23
- "@angular-eslint/bundled-angular-compiler": "22.0.1-alpha.7"
22
+ "@angular-eslint/bundled-angular-compiler": "22.0.1-alpha.9",
23
+ "@angular-eslint/utils": "22.0.1-alpha.9"
24
24
  },
25
25
  "devDependencies": {
26
- "@angular-eslint/test-utils": "22.0.1-alpha.7"
26
+ "@angular-eslint/test-utils": "22.0.1-alpha.9"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@typescript-eslint/utils": "^8.0.0",