@webpieces/dev-config 0.2.94 → 0.2.97

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 (183) hide show
  1. package/config/eslint/base.mjs +1 -1
  2. package/executors.json +6 -91
  3. package/package.json +6 -19
  4. package/{executors → src/executors}/help/executor.d.ts +4 -2
  5. package/src/executors/help/executor.js.map +1 -0
  6. package/{executors → src/executors}/validate-eslint-sync/executor.d.ts +3 -2
  7. package/src/executors/validate-eslint-sync/executor.js.map +1 -0
  8. package/{executors → src/executors}/validate-versions-locked/executor.js +5 -3
  9. package/src/executors/validate-versions-locked/executor.js.map +1 -0
  10. package/src/generators/init/generator.js.map +1 -1
  11. package/src/index.d.ts +1 -1
  12. package/src/index.js +1 -1
  13. package/src/index.js.map +1 -1
  14. package/src/plugin.d.ts +86 -0
  15. package/{plugin.js → src/plugin.js} +31 -15
  16. package/src/plugin.js.map +1 -0
  17. package/src/toError.d.ts +5 -0
  18. package/src/toError.js +37 -0
  19. package/src/toError.js.map +1 -0
  20. package/templates/eslint.webpieces.config.mjs +1 -1
  21. package/templates/webpieces.exceptions.md +15 -15
  22. package/architecture/executors/diff-utils.d.ts +0 -24
  23. package/architecture/executors/diff-utils.js +0 -119
  24. package/architecture/executors/diff-utils.js.map +0 -1
  25. package/architecture/executors/diff-utils.ts +0 -127
  26. package/architecture/executors/generate/executor.d.ts +0 -16
  27. package/architecture/executors/generate/executor.js +0 -44
  28. package/architecture/executors/generate/executor.js.map +0 -1
  29. package/architecture/executors/generate/executor.ts +0 -59
  30. package/architecture/executors/generate/schema.json +0 -14
  31. package/architecture/executors/validate-architecture-unchanged/executor.d.ts +0 -17
  32. package/architecture/executors/validate-architecture-unchanged/executor.js +0 -229
  33. package/architecture/executors/validate-architecture-unchanged/executor.js.map +0 -1
  34. package/architecture/executors/validate-architecture-unchanged/executor.ts +0 -251
  35. package/architecture/executors/validate-architecture-unchanged/schema.json +0 -14
  36. package/architecture/executors/validate-code/executor.d.ts +0 -78
  37. package/architecture/executors/validate-code/executor.js +0 -243
  38. package/architecture/executors/validate-code/executor.js.map +0 -1
  39. package/architecture/executors/validate-code/executor.ts +0 -406
  40. package/architecture/executors/validate-code/schema.json +0 -227
  41. package/architecture/executors/validate-dtos/executor.d.ts +0 -42
  42. package/architecture/executors/validate-dtos/executor.js +0 -561
  43. package/architecture/executors/validate-dtos/executor.js.map +0 -1
  44. package/architecture/executors/validate-dtos/executor.ts +0 -689
  45. package/architecture/executors/validate-dtos/schema.json +0 -33
  46. package/architecture/executors/validate-modified-files/executor.d.ts +0 -25
  47. package/architecture/executors/validate-modified-files/executor.js +0 -501
  48. package/architecture/executors/validate-modified-files/executor.js.map +0 -1
  49. package/architecture/executors/validate-modified-files/executor.ts +0 -571
  50. package/architecture/executors/validate-modified-files/schema.json +0 -25
  51. package/architecture/executors/validate-modified-methods/executor.d.ts +0 -31
  52. package/architecture/executors/validate-modified-methods/executor.js +0 -694
  53. package/architecture/executors/validate-modified-methods/executor.js.map +0 -1
  54. package/architecture/executors/validate-modified-methods/executor.ts +0 -797
  55. package/architecture/executors/validate-modified-methods/schema.json +0 -25
  56. package/architecture/executors/validate-new-methods/executor.d.ts +0 -28
  57. package/architecture/executors/validate-new-methods/executor.js +0 -513
  58. package/architecture/executors/validate-new-methods/executor.js.map +0 -1
  59. package/architecture/executors/validate-new-methods/executor.ts +0 -584
  60. package/architecture/executors/validate-new-methods/schema.json +0 -25
  61. package/architecture/executors/validate-no-any-unknown/executor.d.ts +0 -42
  62. package/architecture/executors/validate-no-any-unknown/executor.js +0 -462
  63. package/architecture/executors/validate-no-any-unknown/executor.js.map +0 -1
  64. package/architecture/executors/validate-no-any-unknown/executor.ts +0 -540
  65. package/architecture/executors/validate-no-any-unknown/schema.json +0 -24
  66. package/architecture/executors/validate-no-architecture-cycles/executor.d.ts +0 -16
  67. package/architecture/executors/validate-no-architecture-cycles/executor.js +0 -48
  68. package/architecture/executors/validate-no-architecture-cycles/executor.js.map +0 -1
  69. package/architecture/executors/validate-no-architecture-cycles/executor.ts +0 -60
  70. package/architecture/executors/validate-no-architecture-cycles/schema.json +0 -8
  71. package/architecture/executors/validate-no-destructure/executor.d.ts +0 -52
  72. package/architecture/executors/validate-no-destructure/executor.js +0 -491
  73. package/architecture/executors/validate-no-destructure/executor.js.map +0 -1
  74. package/architecture/executors/validate-no-destructure/executor.ts +0 -578
  75. package/architecture/executors/validate-no-destructure/schema.json +0 -24
  76. package/architecture/executors/validate-no-direct-api-resolver/executor.d.ts +0 -47
  77. package/architecture/executors/validate-no-direct-api-resolver/executor.js +0 -566
  78. package/architecture/executors/validate-no-direct-api-resolver/executor.js.map +0 -1
  79. package/architecture/executors/validate-no-direct-api-resolver/executor.ts +0 -666
  80. package/architecture/executors/validate-no-direct-api-resolver/schema.json +0 -29
  81. package/architecture/executors/validate-no-inline-types/executor.d.ts +0 -91
  82. package/architecture/executors/validate-no-inline-types/executor.js +0 -669
  83. package/architecture/executors/validate-no-inline-types/executor.js.map +0 -1
  84. package/architecture/executors/validate-no-inline-types/executor.ts +0 -775
  85. package/architecture/executors/validate-no-inline-types/schema.json +0 -24
  86. package/architecture/executors/validate-no-skiplevel-deps/executor.d.ts +0 -19
  87. package/architecture/executors/validate-no-skiplevel-deps/executor.js +0 -227
  88. package/architecture/executors/validate-no-skiplevel-deps/executor.js.map +0 -1
  89. package/architecture/executors/validate-no-skiplevel-deps/executor.ts +0 -267
  90. package/architecture/executors/validate-no-skiplevel-deps/schema.json +0 -8
  91. package/architecture/executors/validate-packagejson/executor.d.ts +0 -16
  92. package/architecture/executors/validate-packagejson/executor.js +0 -57
  93. package/architecture/executors/validate-packagejson/executor.js.map +0 -1
  94. package/architecture/executors/validate-packagejson/executor.ts +0 -74
  95. package/architecture/executors/validate-packagejson/schema.json +0 -8
  96. package/architecture/executors/validate-prisma-converters/executor.d.ts +0 -60
  97. package/architecture/executors/validate-prisma-converters/executor.js +0 -634
  98. package/architecture/executors/validate-prisma-converters/executor.js.map +0 -1
  99. package/architecture/executors/validate-prisma-converters/executor.ts +0 -822
  100. package/architecture/executors/validate-prisma-converters/schema.json +0 -38
  101. package/architecture/executors/validate-return-types/executor.d.ts +0 -29
  102. package/architecture/executors/validate-return-types/executor.js +0 -439
  103. package/architecture/executors/validate-return-types/executor.js.map +0 -1
  104. package/architecture/executors/validate-return-types/executor.ts +0 -524
  105. package/architecture/executors/validate-return-types/schema.json +0 -24
  106. package/architecture/executors/visualize/executor.d.ts +0 -17
  107. package/architecture/executors/visualize/executor.js +0 -49
  108. package/architecture/executors/visualize/executor.js.map +0 -1
  109. package/architecture/executors/visualize/executor.ts +0 -63
  110. package/architecture/executors/visualize/schema.json +0 -14
  111. package/architecture/index.d.ts +0 -19
  112. package/architecture/index.js +0 -23
  113. package/architecture/index.js.map +0 -1
  114. package/architecture/index.ts +0 -20
  115. package/architecture/lib/graph-comparator.d.ts +0 -39
  116. package/architecture/lib/graph-comparator.js +0 -100
  117. package/architecture/lib/graph-comparator.js.map +0 -1
  118. package/architecture/lib/graph-comparator.ts +0 -141
  119. package/architecture/lib/graph-generator.d.ts +0 -19
  120. package/architecture/lib/graph-generator.js +0 -84
  121. package/architecture/lib/graph-generator.js.map +0 -1
  122. package/architecture/lib/graph-generator.ts +0 -97
  123. package/architecture/lib/graph-loader.d.ts +0 -31
  124. package/architecture/lib/graph-loader.js +0 -98
  125. package/architecture/lib/graph-loader.js.map +0 -1
  126. package/architecture/lib/graph-loader.ts +0 -116
  127. package/architecture/lib/graph-sorter.d.ts +0 -37
  128. package/architecture/lib/graph-sorter.js +0 -110
  129. package/architecture/lib/graph-sorter.js.map +0 -1
  130. package/architecture/lib/graph-sorter.ts +0 -137
  131. package/architecture/lib/graph-visualizer.d.ts +0 -29
  132. package/architecture/lib/graph-visualizer.js +0 -217
  133. package/architecture/lib/graph-visualizer.js.map +0 -1
  134. package/architecture/lib/graph-visualizer.ts +0 -231
  135. package/architecture/lib/package-validator.d.ts +0 -38
  136. package/architecture/lib/package-validator.js +0 -126
  137. package/architecture/lib/package-validator.js.map +0 -1
  138. package/architecture/lib/package-validator.ts +0 -170
  139. package/eslint-plugin/__tests__/catch-error-pattern.test.ts +0 -359
  140. package/eslint-plugin/__tests__/max-file-lines.test.ts +0 -207
  141. package/eslint-plugin/__tests__/max-method-lines.test.ts +0 -258
  142. package/eslint-plugin/__tests__/no-unmanaged-exceptions.test.ts +0 -359
  143. package/eslint-plugin/index.d.ts +0 -23
  144. package/eslint-plugin/index.js +0 -30
  145. package/eslint-plugin/index.js.map +0 -1
  146. package/eslint-plugin/index.ts +0 -29
  147. package/eslint-plugin/rules/catch-error-pattern.d.ts +0 -11
  148. package/eslint-plugin/rules/catch-error-pattern.js +0 -196
  149. package/eslint-plugin/rules/catch-error-pattern.js.map +0 -1
  150. package/eslint-plugin/rules/catch-error-pattern.ts +0 -281
  151. package/eslint-plugin/rules/enforce-architecture.d.ts +0 -15
  152. package/eslint-plugin/rules/enforce-architecture.js +0 -476
  153. package/eslint-plugin/rules/enforce-architecture.js.map +0 -1
  154. package/eslint-plugin/rules/enforce-architecture.ts +0 -543
  155. package/eslint-plugin/rules/max-file-lines.d.ts +0 -12
  156. package/eslint-plugin/rules/max-file-lines.js +0 -257
  157. package/eslint-plugin/rules/max-file-lines.js.map +0 -1
  158. package/eslint-plugin/rules/max-file-lines.ts +0 -272
  159. package/eslint-plugin/rules/max-method-lines.d.ts +0 -12
  160. package/eslint-plugin/rules/max-method-lines.js +0 -240
  161. package/eslint-plugin/rules/max-method-lines.js.map +0 -1
  162. package/eslint-plugin/rules/max-method-lines.ts +0 -287
  163. package/eslint-plugin/rules/no-unmanaged-exceptions.d.ts +0 -22
  164. package/eslint-plugin/rules/no-unmanaged-exceptions.js +0 -160
  165. package/eslint-plugin/rules/no-unmanaged-exceptions.js.map +0 -1
  166. package/eslint-plugin/rules/no-unmanaged-exceptions.ts +0 -179
  167. package/executors/help/executor.js.map +0 -1
  168. package/executors/help/executor.ts +0 -61
  169. package/executors/validate-eslint-sync/executor.js.map +0 -1
  170. package/executors/validate-eslint-sync/executor.ts +0 -83
  171. package/executors/validate-versions-locked/executor.js.map +0 -1
  172. package/executors/validate-versions-locked/executor.ts +0 -367
  173. package/plugin/README.md +0 -243
  174. package/plugin/index.d.ts +0 -4
  175. package/plugin/index.js +0 -8
  176. package/plugin/index.js.map +0 -1
  177. package/plugin/index.ts +0 -4
  178. /package/{executors → src/executors}/help/executor.js +0 -0
  179. /package/{executors → src/executors}/help/schema.json +0 -0
  180. /package/{executors → src/executors}/validate-eslint-sync/executor.js +0 -0
  181. /package/{executors → src/executors}/validate-eslint-sync/schema.json +0 -0
  182. /package/{executors → src/executors}/validate-versions-locked/executor.d.ts +0 -0
  183. /package/{executors → src/executors}/validate-versions-locked/schema.json +0 -0
@@ -1,47 +0,0 @@
1
- /**
2
- * Validate No Direct API in Resolver Executor
3
- *
4
- * Validates two Angular anti-patterns using LINE-BASED detection:
5
- *
6
- * ============================================================================
7
- * VIOLATIONS (BAD) - These patterns are flagged:
8
- * ============================================================================
9
- *
10
- * 1. In *.routes.ts files: inject(XxxApi) — resolvers should inject services, not APIs directly
11
- * 2. In *.component.ts files: this.<field>.snapshot.data — components should subscribe to
12
- * service BehaviorSubjects, not read route snapshot data
13
- *
14
- * ============================================================================
15
- * CORRECT PATTERNS (GOOD)
16
- * ============================================================================
17
- *
18
- * 1. In resolvers: inject(XxxService) which calls the API internally
19
- * 2. In components: this.myService.someObservable$ (subscribe to service BehaviorSubjects)
20
- *
21
- * ============================================================================
22
- * MODES (LINE-BASED)
23
- * ============================================================================
24
- * - OFF: Skip validation entirely
25
- * - MODIFIED_CODE: Flag violations on changed lines (lines in diff hunks)
26
- * - NEW_AND_MODIFIED_METHODS: Flag violations in new/modified method/route scopes
27
- * - MODIFIED_FILES: Flag ALL violations in files that were modified
28
- *
29
- * ============================================================================
30
- * ESCAPE HATCH
31
- * ============================================================================
32
- * Add comment above the violation:
33
- * // webpieces-disable no-direct-api-resolver -- [your justification]
34
- * const myApi = inject(MyApi);
35
- */
36
- import type { ExecutorContext } from '@nx/devkit';
37
- export type NoDirectApiResolverMode = 'OFF' | 'MODIFIED_CODE' | 'NEW_AND_MODIFIED_METHODS' | 'MODIFIED_FILES';
38
- export interface ValidateNoDirectApiResolverOptions {
39
- mode?: NoDirectApiResolverMode;
40
- disableAllowed?: boolean;
41
- ignoreModifiedUntilEpoch?: number;
42
- enforcePaths?: string[];
43
- }
44
- export interface ExecutorResult {
45
- success: boolean;
46
- }
47
- export default function runExecutor(options: ValidateNoDirectApiResolverOptions, context: ExecutorContext): Promise<ExecutorResult>;
@@ -1,566 +0,0 @@
1
- "use strict";
2
- /**
3
- * Validate No Direct API in Resolver Executor
4
- *
5
- * Validates two Angular anti-patterns using LINE-BASED detection:
6
- *
7
- * ============================================================================
8
- * VIOLATIONS (BAD) - These patterns are flagged:
9
- * ============================================================================
10
- *
11
- * 1. In *.routes.ts files: inject(XxxApi) — resolvers should inject services, not APIs directly
12
- * 2. In *.component.ts files: this.<field>.snapshot.data — components should subscribe to
13
- * service BehaviorSubjects, not read route snapshot data
14
- *
15
- * ============================================================================
16
- * CORRECT PATTERNS (GOOD)
17
- * ============================================================================
18
- *
19
- * 1. In resolvers: inject(XxxService) which calls the API internally
20
- * 2. In components: this.myService.someObservable$ (subscribe to service BehaviorSubjects)
21
- *
22
- * ============================================================================
23
- * MODES (LINE-BASED)
24
- * ============================================================================
25
- * - OFF: Skip validation entirely
26
- * - MODIFIED_CODE: Flag violations on changed lines (lines in diff hunks)
27
- * - NEW_AND_MODIFIED_METHODS: Flag violations in new/modified method/route scopes
28
- * - MODIFIED_FILES: Flag ALL violations in files that were modified
29
- *
30
- * ============================================================================
31
- * ESCAPE HATCH
32
- * ============================================================================
33
- * Add comment above the violation:
34
- * // webpieces-disable no-direct-api-resolver -- [your justification]
35
- * const myApi = inject(MyApi);
36
- */
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.default = runExecutor;
39
- const tslib_1 = require("tslib");
40
- const child_process_1 = require("child_process");
41
- const fs = tslib_1.__importStar(require("fs"));
42
- const path = tslib_1.__importStar(require("path"));
43
- const ts = tslib_1.__importStar(require("typescript"));
44
- const diff_utils_1 = require("../diff-utils");
45
- /**
46
- * Get changed TypeScript files between base and head (or working tree if head not specified).
47
- */
48
- // webpieces-disable max-lines-new-methods -- Git command handling with untracked files requires multiple code paths
49
- function getChangedTypeScriptFiles(workspaceRoot, base, head) {
50
- try {
51
- const diffTarget = head ? `${base} ${head}` : base;
52
- const output = (0, child_process_1.execSync)(`git diff --name-only ${diffTarget} -- '*.ts' '*.tsx'`, {
53
- cwd: workspaceRoot,
54
- encoding: 'utf-8',
55
- });
56
- const changedFiles = output
57
- .trim()
58
- .split('\n')
59
- .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
60
- if (!head) {
61
- try {
62
- const untrackedOutput = (0, child_process_1.execSync)(`git ls-files --others --exclude-standard '*.ts' '*.tsx'`, {
63
- cwd: workspaceRoot,
64
- encoding: 'utf-8',
65
- });
66
- const untrackedFiles = untrackedOutput
67
- .trim()
68
- .split('\n')
69
- .filter((f) => f && !f.includes('.spec.ts') && !f.includes('.test.ts'));
70
- const allFiles = new Set([...changedFiles, ...untrackedFiles]);
71
- return Array.from(allFiles);
72
- }
73
- catch {
74
- return changedFiles;
75
- }
76
- }
77
- return changedFiles;
78
- }
79
- catch {
80
- return [];
81
- }
82
- }
83
- /**
84
- * Check if a line contains a webpieces-disable comment for no-direct-api-resolver.
85
- */
86
- function hasDisableComment(lines, lineNumber) {
87
- const startCheck = Math.max(0, lineNumber - 5);
88
- for (let i = lineNumber - 2; i >= startCheck; i--) {
89
- const line = lines[i]?.trim() ?? '';
90
- if (line.startsWith('function ') || line.startsWith('class ') || line.endsWith('}')) {
91
- break;
92
- }
93
- if (line.includes('webpieces-disable') && line.includes('no-direct-api-resolver')) {
94
- return true;
95
- }
96
- }
97
- return false;
98
- }
99
- /**
100
- * Auto-detect the base branch by finding the merge-base with origin/main.
101
- */
102
- function detectBase(workspaceRoot) {
103
- try {
104
- const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD origin/main', {
105
- cwd: workspaceRoot,
106
- encoding: 'utf-8',
107
- stdio: ['pipe', 'pipe', 'pipe'],
108
- }).trim();
109
- if (mergeBase) {
110
- return mergeBase;
111
- }
112
- }
113
- catch {
114
- try {
115
- const mergeBase = (0, child_process_1.execSync)('git merge-base HEAD main', {
116
- cwd: workspaceRoot,
117
- encoding: 'utf-8',
118
- stdio: ['pipe', 'pipe', 'pipe'],
119
- }).trim();
120
- if (mergeBase) {
121
- return mergeBase;
122
- }
123
- }
124
- catch {
125
- // Ignore
126
- }
127
- }
128
- return null;
129
- }
130
- /**
131
- * Find inject(XxxApi) calls in *.routes.ts files.
132
- * Flags any CallExpression where callee is `inject` and the first argument is an identifier ending with `Api`.
133
- */
134
- function findDirectApiInjections(filePath, workspaceRoot, disableAllowed) {
135
- if (!filePath.endsWith('.routes.ts'))
136
- return [];
137
- const fullPath = path.join(workspaceRoot, filePath);
138
- if (!fs.existsSync(fullPath))
139
- return [];
140
- const content = fs.readFileSync(fullPath, 'utf-8');
141
- const fileLines = content.split('\n');
142
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
143
- const violations = [];
144
- function visit(node) {
145
- try {
146
- if (ts.isCallExpression(node)) {
147
- const callee = node.expression;
148
- if (ts.isIdentifier(callee) && callee.text === 'inject') {
149
- const firstArg = node.arguments[0];
150
- if (firstArg && ts.isIdentifier(firstArg) && firstArg.text.endsWith('Api')) {
151
- const startPos = node.getStart(sourceFile);
152
- if (startPos >= 0) {
153
- const pos = sourceFile.getLineAndCharacterOfPosition(startPos);
154
- const line = pos.line + 1;
155
- const column = pos.character + 1;
156
- const disabled = hasDisableComment(fileLines, line);
157
- if (!disableAllowed && disabled) {
158
- violations.push({ line, column, context: `inject(${firstArg.text}) in route resolver`, hasDisableComment: false });
159
- }
160
- else {
161
- violations.push({ line, column, context: `inject(${firstArg.text}) in route resolver`, hasDisableComment: disabled });
162
- }
163
- }
164
- }
165
- }
166
- }
167
- }
168
- catch {
169
- // Skip nodes that cause errors during analysis
170
- }
171
- ts.forEachChild(node, visit);
172
- }
173
- visit(sourceFile);
174
- return violations;
175
- }
176
- /**
177
- * Find this.<field>.snapshot.data access patterns in *.component.ts files.
178
- * Flags PropertyAccessExpression chains: this.<anything>.snapshot.data
179
- */
180
- function findSnapshotDataAccess(filePath, workspaceRoot, disableAllowed) {
181
- if (!filePath.endsWith('.component.ts'))
182
- return [];
183
- const fullPath = path.join(workspaceRoot, filePath);
184
- if (!fs.existsSync(fullPath))
185
- return [];
186
- const content = fs.readFileSync(fullPath, 'utf-8');
187
- const fileLines = content.split('\n');
188
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
189
- const violations = [];
190
- function visit(node) {
191
- try {
192
- // Looking for: this.<field>.snapshot.data
193
- // AST shape: PropertyAccessExpression(.data) -> PropertyAccessExpression(.snapshot) -> PropertyAccessExpression(.<field>) -> this
194
- if (ts.isPropertyAccessExpression(node) && node.name.text === 'data') {
195
- const snapshotAccess = node.expression;
196
- if (ts.isPropertyAccessExpression(snapshotAccess) && snapshotAccess.name.text === 'snapshot') {
197
- const fieldAccess = snapshotAccess.expression;
198
- if (ts.isPropertyAccessExpression(fieldAccess)) {
199
- const receiver = fieldAccess.expression;
200
- if (receiver.kind === ts.SyntaxKind.ThisKeyword) {
201
- const fieldName = fieldAccess.name.text;
202
- const startPos = node.getStart(sourceFile);
203
- if (startPos >= 0) {
204
- const pos = sourceFile.getLineAndCharacterOfPosition(startPos);
205
- const line = pos.line + 1;
206
- const column = pos.character + 1;
207
- const disabled = hasDisableComment(fileLines, line);
208
- if (!disableAllowed && disabled) {
209
- violations.push({ line, column, context: `this.${fieldName}.snapshot.data in component`, hasDisableComment: false });
210
- }
211
- else {
212
- violations.push({ line, column, context: `this.${fieldName}.snapshot.data in component`, hasDisableComment: disabled });
213
- }
214
- }
215
- }
216
- }
217
- }
218
- }
219
- }
220
- catch {
221
- // Skip nodes that cause errors during analysis
222
- }
223
- ts.forEachChild(node, visit);
224
- }
225
- visit(sourceFile);
226
- return violations;
227
- }
228
- /**
229
- * Find all violations in a file (both inject(Api) and snapshot.data patterns).
230
- */
231
- function findViolationsInFile(filePath, workspaceRoot, disableAllowed) {
232
- const apiViolations = findDirectApiInjections(filePath, workspaceRoot, disableAllowed);
233
- const snapshotViolations = findSnapshotDataAccess(filePath, workspaceRoot, disableAllowed);
234
- return [...apiViolations, ...snapshotViolations];
235
- }
236
- /**
237
- * MODIFIED_CODE mode: Flag violations on changed lines in diff hunks.
238
- */
239
- // webpieces-disable max-lines-new-methods -- File iteration with diff parsing and line filtering
240
- function findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed) {
241
- const violations = [];
242
- for (const file of changedFiles) {
243
- const diff = (0, diff_utils_1.getFileDiff)(workspaceRoot, file, base, head);
244
- const changedLines = (0, diff_utils_1.getChangedLineNumbers)(diff);
245
- if (changedLines.size === 0)
246
- continue;
247
- const allViolations = findViolationsInFile(file, workspaceRoot, disableAllowed);
248
- for (const v of allViolations) {
249
- if (disableAllowed && v.hasDisableComment)
250
- continue;
251
- // LINE-BASED: Only include if the violation is on a changed line
252
- if (!changedLines.has(v.line))
253
- continue;
254
- violations.push({
255
- file,
256
- line: v.line,
257
- column: v.column,
258
- context: v.context,
259
- });
260
- }
261
- }
262
- return violations;
263
- }
264
- /**
265
- * MODIFIED_FILES mode: Flag ALL violations in files that were modified.
266
- */
267
- function findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed) {
268
- const violations = [];
269
- for (const file of changedFiles) {
270
- const allViolations = findViolationsInFile(file, workspaceRoot, disableAllowed);
271
- for (const v of allViolations) {
272
- if (disableAllowed && v.hasDisableComment)
273
- continue;
274
- violations.push({
275
- file,
276
- line: v.line,
277
- column: v.column,
278
- context: v.context,
279
- });
280
- }
281
- }
282
- return violations;
283
- }
284
- /**
285
- * Find route object ranges in *.routes.ts files.
286
- * A route object is an ObjectLiteralExpression that contains (directly or in descendants)
287
- * a `resolve` property. Returns the line range of each such top-level route object.
288
- */
289
- function findRouteObjectRanges(filePath, workspaceRoot) {
290
- const fullPath = path.join(workspaceRoot, filePath);
291
- if (!fs.existsSync(fullPath))
292
- return [];
293
- const content = fs.readFileSync(fullPath, 'utf-8');
294
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
295
- const ranges = [];
296
- function hasResolveProperty(node) {
297
- if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === 'resolve') {
298
- return true;
299
- }
300
- let found = false;
301
- ts.forEachChild(node, (child) => {
302
- if (hasResolveProperty(child)) {
303
- found = true;
304
- }
305
- });
306
- return found;
307
- }
308
- function visitTopLevel(node) {
309
- if (ts.isObjectLiteralExpression(node) && hasResolveProperty(node)) {
310
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
311
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
312
- ranges.push({
313
- name: `route@${start.line + 1}`,
314
- startLine: start.line + 1,
315
- endLine: end.line + 1,
316
- });
317
- return;
318
- }
319
- ts.forEachChild(node, visitTopLevel);
320
- }
321
- visitTopLevel(sourceFile);
322
- return ranges;
323
- }
324
- /**
325
- * Find method/function ranges in *.component.ts files.
326
- * Returns ranges for class methods, function declarations, and arrow functions in variable declarations.
327
- */
328
- function findMethodRanges(filePath, workspaceRoot) {
329
- const fullPath = path.join(workspaceRoot, filePath);
330
- if (!fs.existsSync(fullPath))
331
- return [];
332
- const content = fs.readFileSync(fullPath, 'utf-8');
333
- const sourceFile = ts.createSourceFile(filePath, content, ts.ScriptTarget.Latest, true);
334
- const ranges = [];
335
- function visit(node) {
336
- let methodName;
337
- let startLine;
338
- let endLine;
339
- if (ts.isMethodDeclaration(node) && node.name) {
340
- methodName = node.name.getText(sourceFile);
341
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
342
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
343
- startLine = start.line + 1;
344
- endLine = end.line + 1;
345
- }
346
- else if (ts.isFunctionDeclaration(node) && node.name) {
347
- methodName = node.name.getText(sourceFile);
348
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
349
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
350
- startLine = start.line + 1;
351
- endLine = end.line + 1;
352
- }
353
- else if (ts.isArrowFunction(node)) {
354
- if (ts.isVariableDeclaration(node.parent) && ts.isIdentifier(node.parent.name)) {
355
- methodName = node.parent.name.getText(sourceFile);
356
- const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
357
- const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
358
- startLine = start.line + 1;
359
- endLine = end.line + 1;
360
- }
361
- }
362
- if (methodName && startLine !== undefined && endLine !== undefined) {
363
- ranges.push({ name: methodName, startLine, endLine });
364
- }
365
- ts.forEachChild(node, visit);
366
- }
367
- visit(sourceFile);
368
- return ranges;
369
- }
370
- /**
371
- * NEW_AND_MODIFIED_METHODS mode: Flag violations in new/modified method/route scopes.
372
- * - For *.routes.ts: If any line in a route object is changed, flag all inject(XxxApi) violations in that route
373
- * - For *.component.ts: If a method is new/modified, flag all snapshot.data violations in that method
374
- */
375
- // webpieces-disable max-lines-new-methods -- Method-scoped validation with route objects and component methods
376
- function findViolationsForModifiedMethods(workspaceRoot, changedFiles, base, head, disableAllowed) {
377
- const violations = [];
378
- for (const file of changedFiles) {
379
- const diff = (0, diff_utils_1.getFileDiff)(workspaceRoot, file, base, head);
380
- const changedLines = (0, diff_utils_1.getChangedLineNumbers)(diff);
381
- const newMethodNames = (0, diff_utils_1.findNewMethodSignaturesInDiff)(diff);
382
- if (changedLines.size === 0 && newMethodNames.size === 0)
383
- continue;
384
- if (file.endsWith('.routes.ts')) {
385
- const routeRanges = findRouteObjectRanges(file, workspaceRoot);
386
- const allViolations = findDirectApiInjections(file, workspaceRoot, disableAllowed);
387
- for (const range of routeRanges) {
388
- let rangeHasChanges = false;
389
- for (let line = range.startLine; line <= range.endLine; line++) {
390
- if (changedLines.has(line)) {
391
- rangeHasChanges = true;
392
- break;
393
- }
394
- }
395
- if (!rangeHasChanges)
396
- continue;
397
- for (const v of allViolations) {
398
- if (disableAllowed && v.hasDisableComment)
399
- continue;
400
- if (v.line >= range.startLine && v.line <= range.endLine) {
401
- violations.push({
402
- file,
403
- line: v.line,
404
- column: v.column,
405
- context: v.context,
406
- });
407
- }
408
- }
409
- }
410
- }
411
- else if (file.endsWith('.component.ts')) {
412
- const methodRanges = findMethodRanges(file, workspaceRoot);
413
- const allViolations = findSnapshotDataAccess(file, workspaceRoot, disableAllowed);
414
- for (const range of methodRanges) {
415
- const isNewMethod = newMethodNames.has(range.name);
416
- let rangeHasChanges = false;
417
- if (!isNewMethod) {
418
- for (let line = range.startLine; line <= range.endLine; line++) {
419
- if (changedLines.has(line)) {
420
- rangeHasChanges = true;
421
- break;
422
- }
423
- }
424
- }
425
- if (!isNewMethod && !rangeHasChanges)
426
- continue;
427
- for (const v of allViolations) {
428
- if (disableAllowed && v.hasDisableComment)
429
- continue;
430
- if (v.line >= range.startLine && v.line <= range.endLine) {
431
- violations.push({
432
- file,
433
- line: v.line,
434
- column: v.column,
435
- context: v.context,
436
- });
437
- }
438
- }
439
- }
440
- }
441
- }
442
- return violations;
443
- }
444
- /**
445
- * Report violations to console.
446
- */
447
- // webpieces-disable max-lines-new-methods -- Console output with examples and escape hatch information
448
- function reportViolations(violations, mode, disableAllowed) {
449
- console.error('');
450
- console.error('\u274c Direct API usage in resolvers or snapshot.data in components found!');
451
- console.error('');
452
- console.error('\ud83d\udcda Resolvers should use services, and components should subscribe to service observables:');
453
- console.error('');
454
- console.error(' BAD (in *.routes.ts resolver):');
455
- console.error(' const myApi = inject(MyApi);');
456
- console.error(' resolve: () => inject(MyApi).fetchData()');
457
- console.error('');
458
- console.error(' GOOD (in *.routes.ts resolver):');
459
- console.error(' const myService = inject(MyService);');
460
- console.error(' resolve: () => inject(MyService).loadData()');
461
- console.error('');
462
- console.error(' BAD (in *.component.ts):');
463
- console.error(' const data = this.route.snapshot.data;');
464
- console.error('');
465
- console.error(' GOOD (in *.component.ts):');
466
- console.error(' this.myService.data$.subscribe(data => ...)');
467
- console.error('');
468
- for (const v of violations) {
469
- console.error(` \u274c ${v.file}:${v.line}:${v.column}`);
470
- console.error(` ${v.context}`);
471
- }
472
- console.error('');
473
- if (disableAllowed) {
474
- console.error(' Escape hatch (use sparingly):');
475
- console.error(' // webpieces-disable no-direct-api-resolver -- [your reason]');
476
- }
477
- else {
478
- console.error(' Escape hatch: DISABLED (disableAllowed: false)');
479
- console.error(' Disable comments are ignored. Fix the pattern directly.');
480
- }
481
- console.error('');
482
- console.error(` Current mode: ${mode}`);
483
- console.error('');
484
- }
485
- /**
486
- * Resolve mode considering ignoreModifiedUntilEpoch override.
487
- * When active, downgrades to OFF. When expired, logs a warning.
488
- */
489
- function resolveMode(normalMode, epoch) {
490
- if (epoch === undefined || normalMode === 'OFF') {
491
- return normalMode;
492
- }
493
- const nowSeconds = Date.now() / 1000;
494
- if (nowSeconds < epoch) {
495
- const expiresDate = new Date(epoch * 1000).toISOString().split('T')[0];
496
- console.log(`\n\u23ed\ufe0f Skipping no-direct-api-resolver validation (ignoreModifiedUntilEpoch active, expires: ${expiresDate})`);
497
- console.log('');
498
- return 'OFF';
499
- }
500
- return normalMode;
501
- }
502
- /**
503
- * Filter changed files to only those under enforcePaths (if configured).
504
- */
505
- function filterByEnforcePaths(changedFiles, enforcePaths) {
506
- if (!enforcePaths || enforcePaths.length === 0) {
507
- return changedFiles;
508
- }
509
- return changedFiles.filter((file) => enforcePaths.some((prefix) => file.startsWith(prefix)));
510
- }
511
- /**
512
- * Filter to only relevant Angular files (*.routes.ts and *.component.ts).
513
- */
514
- function filterRelevantFiles(changedFiles) {
515
- return changedFiles.filter((file) => file.endsWith('.routes.ts') || file.endsWith('.component.ts'));
516
- }
517
- async function runExecutor(options, context) {
518
- const workspaceRoot = context.root;
519
- const mode = resolveMode(options.mode ?? 'OFF', options.ignoreModifiedUntilEpoch);
520
- const disableAllowed = options.disableAllowed ?? true;
521
- if (mode === 'OFF') {
522
- console.log('\n\u23ed\ufe0f Skipping no-direct-api-resolver validation (mode: OFF)');
523
- console.log('');
524
- return { success: true };
525
- }
526
- console.log('\n\ud83d\udccf Validating No Direct API in Resolver\n');
527
- console.log(` Mode: ${mode}`);
528
- let base = process.env['NX_BASE'];
529
- const head = process.env['NX_HEAD'];
530
- if (!base) {
531
- base = detectBase(workspaceRoot) ?? undefined;
532
- if (!base) {
533
- console.log('\n\u23ed\ufe0f Skipping no-direct-api-resolver validation (could not detect base branch)');
534
- console.log('');
535
- return { success: true };
536
- }
537
- }
538
- console.log(` Base: ${base}`);
539
- console.log(` Head: ${head ?? 'working tree (includes uncommitted changes)'}`);
540
- console.log('');
541
- const allChangedFiles = getChangedTypeScriptFiles(workspaceRoot, base, head);
542
- const scopedFiles = filterByEnforcePaths(allChangedFiles, options.enforcePaths);
543
- const changedFiles = filterRelevantFiles(scopedFiles);
544
- if (changedFiles.length === 0) {
545
- console.log('\u2705 No relevant Angular files changed (*.routes.ts, *.component.ts)');
546
- return { success: true };
547
- }
548
- console.log(`\ud83d\udcc2 Checking ${changedFiles.length} changed file(s)...`);
549
- let violations = [];
550
- if (mode === 'MODIFIED_CODE') {
551
- violations = findViolationsForModifiedCode(workspaceRoot, changedFiles, base, head, disableAllowed);
552
- }
553
- else if (mode === 'NEW_AND_MODIFIED_METHODS') {
554
- violations = findViolationsForModifiedMethods(workspaceRoot, changedFiles, base, head, disableAllowed);
555
- }
556
- else if (mode === 'MODIFIED_FILES') {
557
- violations = findViolationsForModifiedFiles(workspaceRoot, changedFiles, disableAllowed);
558
- }
559
- if (violations.length === 0) {
560
- console.log('\u2705 No direct API resolver patterns found');
561
- return { success: true };
562
- }
563
- reportViolations(violations, mode, disableAllowed);
564
- return { success: false };
565
- }
566
- //# sourceMappingURL=executor.js.map