driftdetect-core 0.6.1 → 0.7.1

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 (141) hide show
  1. package/LICENSE +21 -0
  2. package/dist/constants/analysis/categorizer.d.ts +27 -0
  3. package/dist/constants/analysis/categorizer.d.ts.map +1 -0
  4. package/dist/constants/analysis/categorizer.js +364 -0
  5. package/dist/constants/analysis/categorizer.js.map +1 -0
  6. package/dist/constants/analysis/consistency-analyzer.d.ts +77 -0
  7. package/dist/constants/analysis/consistency-analyzer.d.ts.map +1 -0
  8. package/dist/constants/analysis/consistency-analyzer.js +176 -0
  9. package/dist/constants/analysis/consistency-analyzer.js.map +1 -0
  10. package/dist/constants/analysis/dead-constant-detector.d.ts +79 -0
  11. package/dist/constants/analysis/dead-constant-detector.d.ts.map +1 -0
  12. package/dist/constants/analysis/dead-constant-detector.js +242 -0
  13. package/dist/constants/analysis/dead-constant-detector.js.map +1 -0
  14. package/dist/constants/analysis/magic-detector.d.ts +116 -0
  15. package/dist/constants/analysis/magic-detector.d.ts.map +1 -0
  16. package/dist/constants/analysis/magic-detector.js +425 -0
  17. package/dist/constants/analysis/magic-detector.js.map +1 -0
  18. package/dist/constants/analysis/reference-finder.d.ts +87 -0
  19. package/dist/constants/analysis/reference-finder.d.ts.map +1 -0
  20. package/dist/constants/analysis/reference-finder.js +269 -0
  21. package/dist/constants/analysis/reference-finder.js.map +1 -0
  22. package/dist/constants/analysis/security-scanner.d.ts +115 -0
  23. package/dist/constants/analysis/security-scanner.d.ts.map +1 -0
  24. package/dist/constants/analysis/security-scanner.js +429 -0
  25. package/dist/constants/analysis/security-scanner.js.map +1 -0
  26. package/dist/constants/extractors/base-extractor.d.ts +97 -0
  27. package/dist/constants/extractors/base-extractor.d.ts.map +1 -0
  28. package/dist/constants/extractors/base-extractor.js +285 -0
  29. package/dist/constants/extractors/base-extractor.js.map +1 -0
  30. package/dist/constants/extractors/regex/base-regex.d.ts +67 -0
  31. package/dist/constants/extractors/regex/base-regex.d.ts.map +1 -0
  32. package/dist/constants/extractors/regex/base-regex.js +209 -0
  33. package/dist/constants/extractors/regex/base-regex.js.map +1 -0
  34. package/dist/constants/extractors/regex/csharp-regex.d.ts +39 -0
  35. package/dist/constants/extractors/regex/csharp-regex.d.ts.map +1 -0
  36. package/dist/constants/extractors/regex/csharp-regex.js +316 -0
  37. package/dist/constants/extractors/regex/csharp-regex.js.map +1 -0
  38. package/dist/constants/extractors/regex/go-regex.d.ts +40 -0
  39. package/dist/constants/extractors/regex/go-regex.d.ts.map +1 -0
  40. package/dist/constants/extractors/regex/go-regex.js +297 -0
  41. package/dist/constants/extractors/regex/go-regex.js.map +1 -0
  42. package/dist/constants/extractors/regex/java-regex.d.ts +43 -0
  43. package/dist/constants/extractors/regex/java-regex.d.ts.map +1 -0
  44. package/dist/constants/extractors/regex/java-regex.js +276 -0
  45. package/dist/constants/extractors/regex/java-regex.js.map +1 -0
  46. package/dist/constants/extractors/regex/php-regex.d.ts +39 -0
  47. package/dist/constants/extractors/regex/php-regex.d.ts.map +1 -0
  48. package/dist/constants/extractors/regex/php-regex.js +270 -0
  49. package/dist/constants/extractors/regex/php-regex.js.map +1 -0
  50. package/dist/constants/extractors/regex/python-regex.d.ts +39 -0
  51. package/dist/constants/extractors/regex/python-regex.d.ts.map +1 -0
  52. package/dist/constants/extractors/regex/python-regex.js +287 -0
  53. package/dist/constants/extractors/regex/python-regex.js.map +1 -0
  54. package/dist/constants/extractors/regex/typescript-regex.d.ts +35 -0
  55. package/dist/constants/extractors/regex/typescript-regex.d.ts.map +1 -0
  56. package/dist/constants/extractors/regex/typescript-regex.js +313 -0
  57. package/dist/constants/extractors/regex/typescript-regex.js.map +1 -0
  58. package/dist/constants/index.d.ts +26 -0
  59. package/dist/constants/index.d.ts.map +1 -0
  60. package/dist/constants/index.js +36 -0
  61. package/dist/constants/index.js.map +1 -0
  62. package/dist/constants/integration/callgraph-adapter.d.ts +167 -0
  63. package/dist/constants/integration/callgraph-adapter.d.ts.map +1 -0
  64. package/dist/constants/integration/callgraph-adapter.js +287 -0
  65. package/dist/constants/integration/callgraph-adapter.js.map +1 -0
  66. package/dist/constants/integration/index.d.ts +10 -0
  67. package/dist/constants/integration/index.d.ts.map +1 -0
  68. package/dist/constants/integration/index.js +13 -0
  69. package/dist/constants/integration/index.js.map +1 -0
  70. package/dist/constants/integration/pattern-adapter.d.ts +171 -0
  71. package/dist/constants/integration/pattern-adapter.d.ts.map +1 -0
  72. package/dist/constants/integration/pattern-adapter.js +331 -0
  73. package/dist/constants/integration/pattern-adapter.js.map +1 -0
  74. package/dist/constants/integration/scanner-adapter.d.ts +153 -0
  75. package/dist/constants/integration/scanner-adapter.d.ts.map +1 -0
  76. package/dist/constants/integration/scanner-adapter.js +337 -0
  77. package/dist/constants/integration/scanner-adapter.js.map +1 -0
  78. package/dist/constants/store/constant-store.d.ts +117 -0
  79. package/dist/constants/store/constant-store.d.ts.map +1 -0
  80. package/dist/constants/store/constant-store.js +367 -0
  81. package/dist/constants/store/constant-store.js.map +1 -0
  82. package/dist/constants/types.d.ts +423 -0
  83. package/dist/constants/types.d.ts.map +1 -0
  84. package/dist/constants/types.js +43 -0
  85. package/dist/constants/types.js.map +1 -0
  86. package/dist/constraints/store/constraint-store.d.ts.map +1 -1
  87. package/dist/constraints/store/constraint-store.js +37 -2
  88. package/dist/constraints/store/constraint-store.js.map +1 -1
  89. package/dist/environment/env-scanner.d.ts +53 -0
  90. package/dist/environment/env-scanner.d.ts.map +1 -0
  91. package/dist/environment/env-scanner.js +290 -0
  92. package/dist/environment/env-scanner.js.map +1 -0
  93. package/dist/environment/env-store.d.ts +70 -0
  94. package/dist/environment/env-store.d.ts.map +1 -0
  95. package/dist/environment/env-store.js +201 -0
  96. package/dist/environment/env-store.js.map +1 -0
  97. package/dist/environment/extractors/base-env-extractor.d.ts +56 -0
  98. package/dist/environment/extractors/base-env-extractor.d.ts.map +1 -0
  99. package/dist/environment/extractors/base-env-extractor.js +74 -0
  100. package/dist/environment/extractors/base-env-extractor.js.map +1 -0
  101. package/dist/environment/extractors/csharp-env-extractor.d.ts +49 -0
  102. package/dist/environment/extractors/csharp-env-extractor.d.ts.map +1 -0
  103. package/dist/environment/extractors/csharp-env-extractor.js +240 -0
  104. package/dist/environment/extractors/csharp-env-extractor.js.map +1 -0
  105. package/dist/environment/extractors/go-env-extractor.d.ts +53 -0
  106. package/dist/environment/extractors/go-env-extractor.d.ts.map +1 -0
  107. package/dist/environment/extractors/go-env-extractor.js +267 -0
  108. package/dist/environment/extractors/go-env-extractor.js.map +1 -0
  109. package/dist/environment/extractors/index.d.ts +13 -0
  110. package/dist/environment/extractors/index.d.ts.map +1 -0
  111. package/dist/environment/extractors/index.js +13 -0
  112. package/dist/environment/extractors/index.js.map +1 -0
  113. package/dist/environment/extractors/java-env-extractor.d.ts +58 -0
  114. package/dist/environment/extractors/java-env-extractor.d.ts.map +1 -0
  115. package/dist/environment/extractors/java-env-extractor.js +219 -0
  116. package/dist/environment/extractors/java-env-extractor.js.map +1 -0
  117. package/dist/environment/extractors/php-env-extractor.d.ts +58 -0
  118. package/dist/environment/extractors/php-env-extractor.d.ts.map +1 -0
  119. package/dist/environment/extractors/php-env-extractor.js +231 -0
  120. package/dist/environment/extractors/php-env-extractor.js.map +1 -0
  121. package/dist/environment/extractors/python-env-extractor.d.ts +50 -0
  122. package/dist/environment/extractors/python-env-extractor.d.ts.map +1 -0
  123. package/dist/environment/extractors/python-env-extractor.js +219 -0
  124. package/dist/environment/extractors/python-env-extractor.js.map +1 -0
  125. package/dist/environment/extractors/typescript-env-extractor.d.ts +54 -0
  126. package/dist/environment/extractors/typescript-env-extractor.d.ts.map +1 -0
  127. package/dist/environment/extractors/typescript-env-extractor.js +228 -0
  128. package/dist/environment/extractors/typescript-env-extractor.js.map +1 -0
  129. package/dist/environment/index.d.ts +11 -0
  130. package/dist/environment/index.d.ts.map +1 -0
  131. package/dist/environment/index.js +15 -0
  132. package/dist/environment/index.js.map +1 -0
  133. package/dist/environment/types.d.ts +145 -0
  134. package/dist/environment/types.d.ts.map +1 -0
  135. package/dist/environment/types.js +84 -0
  136. package/dist/environment/types.js.map +1 -0
  137. package/dist/index.d.ts +4 -0
  138. package/dist/index.d.ts.map +1 -1
  139. package/dist/index.js +40 -0
  140. package/dist/index.js.map +1 -1
  141. package/package.json +13 -13
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Geoffrey Fernald
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Constant Categorizer
3
+ *
4
+ * Infers the category of a constant based on its name, value, and context.
5
+ */
6
+ import type { ConstantExtraction, ConstantCategory } from '../types.js';
7
+ /**
8
+ * Infer the category of a constant
9
+ */
10
+ export declare function inferCategory(constant: ConstantExtraction): ConstantCategory;
11
+ /**
12
+ * Get category display name
13
+ */
14
+ export declare function getCategoryDisplayName(category: ConstantCategory): string;
15
+ /**
16
+ * Get category description
17
+ */
18
+ export declare function getCategoryDescription(category: ConstantCategory): string;
19
+ /**
20
+ * Check if a category is security-sensitive
21
+ */
22
+ export declare function isSecuritySensitive(category: ConstantCategory): boolean;
23
+ /**
24
+ * Suggest a better name for a constant based on its value
25
+ */
26
+ export declare function suggestConstantName(value: string | number, category: ConstantCategory): string;
27
+ //# sourceMappingURL=categorizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"categorizer.d.ts","sourceRoot":"","sources":["../../../src/constants/analysis/categorizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AA6NxE;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,gBAAgB,CA6C5E;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAezE;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CAezE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAEvE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,QAAQ,EAAE,gBAAgB,GAAG,MAAM,CA6B9F"}
@@ -0,0 +1,364 @@
1
+ /**
2
+ * Constant Categorizer
3
+ *
4
+ * Infers the category of a constant based on its name, value, and context.
5
+ */
6
+ /**
7
+ * Category inference patterns
8
+ */
9
+ const CATEGORY_PATTERNS = {
10
+ config: {
11
+ namePatterns: [
12
+ /config/i,
13
+ /settings?/i,
14
+ /options?/i,
15
+ /defaults?/i,
16
+ /params?/i,
17
+ /preferences?/i,
18
+ ],
19
+ valuePatterns: [],
20
+ parentPatterns: [/config/i, /settings/i],
21
+ },
22
+ api: {
23
+ namePatterns: [
24
+ /^api/i,
25
+ /url$/i,
26
+ /endpoint/i,
27
+ /base_?url/i,
28
+ /host/i,
29
+ /port$/i,
30
+ /header/i,
31
+ /content.?type/i,
32
+ /accept/i,
33
+ /method/i,
34
+ ],
35
+ valuePatterns: [
36
+ /^https?:\/\//i,
37
+ /^\/api\//i,
38
+ /application\/json/i,
39
+ /text\/html/i,
40
+ ],
41
+ parentPatterns: [/api/i, /http/i, /client/i],
42
+ },
43
+ status: {
44
+ namePatterns: [
45
+ /status/i,
46
+ /state/i,
47
+ /phase/i,
48
+ /stage/i,
49
+ /step/i,
50
+ /mode/i,
51
+ ],
52
+ valuePatterns: [
53
+ /pending/i,
54
+ /active/i,
55
+ /completed/i,
56
+ /failed/i,
57
+ /success/i,
58
+ /error/i,
59
+ /cancelled/i,
60
+ /processing/i,
61
+ ],
62
+ parentPatterns: [/status/i, /state/i],
63
+ },
64
+ error: {
65
+ namePatterns: [
66
+ /^err_/i, // ERR_ prefix
67
+ /^error_/i, // ERROR_ prefix
68
+ /^e_/i, // E_ prefix
69
+ /_error$/i, // _ERROR suffix
70
+ /_err$/i, // _ERR suffix
71
+ /exception/i,
72
+ /^fault$/i, // Only match exact "fault", not "default"
73
+ /failure/i,
74
+ ],
75
+ valuePatterns: [
76
+ /error/i,
77
+ /failed/i,
78
+ /invalid/i,
79
+ /not.?found/i,
80
+ /unauthorized/i,
81
+ /forbidden/i,
82
+ ],
83
+ parentPatterns: [/error/i, /exception/i],
84
+ },
85
+ feature_flag: {
86
+ namePatterns: [
87
+ /feature/i,
88
+ /flag/i,
89
+ /^ff_/i,
90
+ /enable/i,
91
+ /disable/i,
92
+ /toggle/i,
93
+ /experiment/i,
94
+ /^is_/i,
95
+ /^has_/i,
96
+ /^can_/i,
97
+ /^should_/i,
98
+ /^use_/i,
99
+ ],
100
+ valuePatterns: [],
101
+ parentPatterns: [/feature/i, /flag/i],
102
+ },
103
+ limit: {
104
+ namePatterns: [
105
+ /^max_/i,
106
+ /^min_/i,
107
+ /_max$/i,
108
+ /_min$/i,
109
+ /^limit/i,
110
+ /_limit$/i,
111
+ /threshold/i,
112
+ /timeout/i,
113
+ /^size_/i,
114
+ /_size$/i,
115
+ /^count_/i,
116
+ /_count$/i,
117
+ /^length_/i,
118
+ /_length$/i,
119
+ /capacity/i,
120
+ /^rate_/i,
121
+ /_rate$/i,
122
+ /interval/i,
123
+ /delay/i,
124
+ /ttl/i,
125
+ /expire/i,
126
+ /duration/i,
127
+ /^retry_/i,
128
+ /_retry$/i,
129
+ /attempt/i,
130
+ ],
131
+ valuePatterns: [],
132
+ parentPatterns: [/limit/i, /config/i],
133
+ },
134
+ regex: {
135
+ namePatterns: [
136
+ /regex/i,
137
+ /regexp/i,
138
+ /pattern/i,
139
+ /^re_/i,
140
+ ],
141
+ valuePatterns: [
142
+ /^\/.+\/[gimsuvy]*$/,
143
+ /^\^.*\$$/,
144
+ /\[.*\]/,
145
+ /\(.*\)/,
146
+ /\\d|\\w|\\s/,
147
+ ],
148
+ parentPatterns: [/regex/i, /pattern/i, /validator/i],
149
+ },
150
+ path: {
151
+ namePatterns: [
152
+ /path/i,
153
+ /route/i,
154
+ /dir/i,
155
+ /directory/i,
156
+ /folder/i,
157
+ /file/i,
158
+ /location/i,
159
+ ],
160
+ valuePatterns: [
161
+ /^\/[a-z]/i,
162
+ /^\.\//,
163
+ /^\.\.\//,
164
+ /^[a-z]:\\/i,
165
+ ],
166
+ parentPatterns: [/path/i, /route/i],
167
+ },
168
+ env: {
169
+ namePatterns: [
170
+ /^env/i,
171
+ /environment/i,
172
+ /^node_env/i,
173
+ /^app_env/i,
174
+ ],
175
+ valuePatterns: [
176
+ /development/i,
177
+ /production/i,
178
+ /staging/i,
179
+ /test/i,
180
+ /local/i,
181
+ ],
182
+ parentPatterns: [/env/i, /environment/i],
183
+ },
184
+ security: {
185
+ namePatterns: [
186
+ /secret/i,
187
+ /password/i,
188
+ /passwd/i,
189
+ /credential/i,
190
+ /auth/i,
191
+ /token/i,
192
+ /key$/i,
193
+ /^api.?key/i,
194
+ /^private/i,
195
+ /^public.?key/i,
196
+ /certificate/i,
197
+ /cert$/i,
198
+ /salt/i,
199
+ /hash/i,
200
+ /encrypt/i,
201
+ /decrypt/i,
202
+ ],
203
+ valuePatterns: [
204
+ /^sk_/i,
205
+ /^pk_/i,
206
+ /^-----BEGIN/,
207
+ /^bearer /i,
208
+ /^basic /i,
209
+ ],
210
+ parentPatterns: [/auth/i, /security/i, /credential/i],
211
+ },
212
+ uncategorized: {
213
+ namePatterns: [],
214
+ valuePatterns: [],
215
+ parentPatterns: [],
216
+ },
217
+ };
218
+ /**
219
+ * Infer the category of a constant
220
+ */
221
+ export function inferCategory(constant) {
222
+ const name = constant.name;
223
+ const value = String(constant.value ?? constant.rawValue ?? '');
224
+ const parentName = constant.parentName ?? '';
225
+ // Check each category in priority order
226
+ const priorityOrder = [
227
+ 'security', // Security first - most important to flag
228
+ 'feature_flag', // Feature flags are distinctive
229
+ 'api', // API-related
230
+ 'status', // Status values
231
+ 'error', // Error codes
232
+ 'limit', // Limits and thresholds
233
+ 'config', // Configuration (after more specific categories)
234
+ 'regex', // Regex patterns
235
+ 'path', // File paths
236
+ 'env', // Environment
237
+ ];
238
+ for (const category of priorityOrder) {
239
+ const patterns = CATEGORY_PATTERNS[category];
240
+ // Check name patterns
241
+ for (const pattern of patterns.namePatterns) {
242
+ if (pattern.test(name)) {
243
+ return category;
244
+ }
245
+ }
246
+ // Check value patterns
247
+ for (const pattern of patterns.valuePatterns) {
248
+ if (pattern.test(value)) {
249
+ return category;
250
+ }
251
+ }
252
+ // Check parent patterns
253
+ for (const pattern of patterns.parentPatterns) {
254
+ if (pattern.test(parentName)) {
255
+ return category;
256
+ }
257
+ }
258
+ }
259
+ return 'uncategorized';
260
+ }
261
+ /**
262
+ * Get category display name
263
+ */
264
+ export function getCategoryDisplayName(category) {
265
+ const displayNames = {
266
+ config: 'Configuration',
267
+ api: 'API',
268
+ status: 'Status',
269
+ error: 'Error',
270
+ feature_flag: 'Feature Flag',
271
+ limit: 'Limit',
272
+ regex: 'Regex',
273
+ path: 'Path',
274
+ env: 'Environment',
275
+ security: 'Security',
276
+ uncategorized: 'Uncategorized',
277
+ };
278
+ return displayNames[category];
279
+ }
280
+ /**
281
+ * Get category description
282
+ */
283
+ export function getCategoryDescription(category) {
284
+ const descriptions = {
285
+ config: 'Configuration values and settings',
286
+ api: 'API endpoints, URLs, headers, and related values',
287
+ status: 'Status codes, states, and phases',
288
+ error: 'Error codes and error messages',
289
+ feature_flag: 'Feature toggles and experiment flags',
290
+ limit: 'Limits, thresholds, timeouts, and sizes',
291
+ regex: 'Regular expression patterns',
292
+ path: 'File paths, routes, and directories',
293
+ env: 'Environment-related values',
294
+ security: 'Security-sensitive values (potential secrets)',
295
+ uncategorized: 'Constants that don\'t fit other categories',
296
+ };
297
+ return descriptions[category];
298
+ }
299
+ /**
300
+ * Check if a category is security-sensitive
301
+ */
302
+ export function isSecuritySensitive(category) {
303
+ return category === 'security';
304
+ }
305
+ /**
306
+ * Suggest a better name for a constant based on its value
307
+ */
308
+ export function suggestConstantName(value, category) {
309
+ const strValue = String(value);
310
+ // Common value-to-name mappings
311
+ const commonMappings = {
312
+ '3600': 'ONE_HOUR_SECONDS',
313
+ '86400': 'ONE_DAY_SECONDS',
314
+ '604800': 'ONE_WEEK_SECONDS',
315
+ '1000': 'ONE_SECOND_MS',
316
+ '60000': 'ONE_MINUTE_MS',
317
+ '3600000': 'ONE_HOUR_MS',
318
+ 'application/json': 'CONTENT_TYPE_JSON',
319
+ 'application/xml': 'CONTENT_TYPE_XML',
320
+ 'text/html': 'CONTENT_TYPE_HTML',
321
+ 'text/plain': 'CONTENT_TYPE_TEXT',
322
+ 'utf-8': 'ENCODING_UTF8',
323
+ 'utf8': 'ENCODING_UTF8',
324
+ };
325
+ const lowerValue = strValue.toLowerCase();
326
+ if (commonMappings[lowerValue]) {
327
+ return commonMappings[lowerValue];
328
+ }
329
+ // Generate name based on category and value
330
+ const prefix = getCategoryPrefix(category);
331
+ const sanitized = sanitizeForConstantName(strValue);
332
+ return `${prefix}${sanitized}`;
333
+ }
334
+ /**
335
+ * Get prefix for a category
336
+ */
337
+ function getCategoryPrefix(category) {
338
+ const prefixes = {
339
+ config: 'CONFIG_',
340
+ api: 'API_',
341
+ status: 'STATUS_',
342
+ error: 'ERROR_',
343
+ feature_flag: 'FF_',
344
+ limit: 'MAX_',
345
+ regex: 'PATTERN_',
346
+ path: 'PATH_',
347
+ env: 'ENV_',
348
+ security: 'SECRET_',
349
+ uncategorized: '',
350
+ };
351
+ return prefixes[category];
352
+ }
353
+ /**
354
+ * Sanitize a value for use as a constant name
355
+ */
356
+ function sanitizeForConstantName(value) {
357
+ return value
358
+ .toUpperCase()
359
+ .replace(/[^A-Z0-9]/g, '_')
360
+ .replace(/_+/g, '_')
361
+ .replace(/^_|_$/g, '')
362
+ .slice(0, 30);
363
+ }
364
+ //# sourceMappingURL=categorizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"categorizer.js","sourceRoot":"","sources":["../../../src/constants/analysis/categorizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;GAEG;AACH,MAAM,iBAAiB,GAA8C;IACnE,MAAM,EAAE;QACN,YAAY,EAAE;YACZ,SAAS;YACT,YAAY;YACZ,WAAW;YACX,YAAY;YACZ,UAAU;YACV,eAAe;SAChB;QACD,aAAa,EAAE,EAAE;QACjB,cAAc,EAAE,CAAC,SAAS,EAAE,WAAW,CAAC;KACzC;IACD,GAAG,EAAE;QACH,YAAY,EAAE;YACZ,OAAO;YACP,OAAO;YACP,WAAW;YACX,YAAY;YACZ,OAAO;YACP,QAAQ;YACR,SAAS;YACT,gBAAgB;YAChB,SAAS;YACT,SAAS;SACV;QACD,aAAa,EAAE;YACb,eAAe;YACf,WAAW;YACX,oBAAoB;YACpB,aAAa;SACd;QACD,cAAc,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC;KAC7C;IACD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E,CAAC,CAAC;AAClB,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Constant Consistency Analyzer
3
+ *
4
+ * Detects inconsistent constants - same name with different values
5
+ * across the codebase.
6
+ */
7
+ import type { ConstantExtraction, InconsistentConstant, ConstantCategory } from '../types.js';
8
+ /**
9
+ * Configuration for consistency analysis
10
+ */
11
+ export interface ConsistencyConfig {
12
+ /** Ignore case when comparing names */
13
+ ignoreCase: boolean;
14
+ /** Categories to analyze (empty = all) */
15
+ categories: ConstantCategory[];
16
+ /** File patterns to exclude */
17
+ excludePatterns: string[];
18
+ /** Minimum instances to report */
19
+ minInstances: number;
20
+ }
21
+ /**
22
+ * Default consistency config
23
+ */
24
+ export declare const DEFAULT_CONSISTENCY_CONFIG: ConsistencyConfig;
25
+ /**
26
+ * Result of consistency analysis
27
+ */
28
+ export interface ConsistencyResult {
29
+ /** Inconsistent constants found */
30
+ inconsistencies: InconsistentConstant[];
31
+ /** Total constants analyzed */
32
+ totalAnalyzed: number;
33
+ /** Unique names analyzed */
34
+ uniqueNames: number;
35
+ /** Analysis time in ms */
36
+ analysisTimeMs: number;
37
+ }
38
+ /**
39
+ * Consistency analyzer
40
+ */
41
+ export declare class ConsistencyAnalyzer {
42
+ private config;
43
+ constructor(config?: Partial<ConsistencyConfig>);
44
+ /**
45
+ * Analyze constants for inconsistencies
46
+ */
47
+ analyze(constants: ConstantExtraction[]): ConsistencyResult;
48
+ /**
49
+ * Group constants by name
50
+ */
51
+ private groupByName;
52
+ /**
53
+ * Find inconsistencies in grouped constants
54
+ */
55
+ private findInconsistencies;
56
+ /**
57
+ * Get unique values from constants
58
+ */
59
+ private getUniqueValues;
60
+ /**
61
+ * Normalize a value for comparison
62
+ */
63
+ private normalizeValue;
64
+ /**
65
+ * Generate a recommendation for fixing inconsistency
66
+ */
67
+ private generateRecommendation;
68
+ /**
69
+ * Check if a file should be excluded
70
+ */
71
+ private shouldExcludeFile;
72
+ }
73
+ /**
74
+ * Quick check for potential inconsistency
75
+ */
76
+ export declare function hasPotentialInconsistency(constant: ConstantExtraction, existingConstants: ConstantExtraction[]): ConstantExtraction | null;
77
+ //# sourceMappingURL=consistency-analyzer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consistency-analyzer.d.ts","sourceRoot":"","sources":["../../../src/constants/analysis/consistency-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EAEpB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAErB;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,uCAAuC;IACvC,UAAU,EAAE,OAAO,CAAC;IACpB,0CAA0C;IAC1C,UAAU,EAAE,gBAAgB,EAAE,CAAC;IAC/B,+BAA+B;IAC/B,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,eAAO,MAAM,0BAA0B,EAAE,iBAKxC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,mCAAmC;IACnC,eAAe,EAAE,oBAAoB,EAAE,CAAC;IACxC,+BAA+B;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,4BAA4B;IAC5B,WAAW,EAAE,MAAM,CAAC;IACpB,0BAA0B;IAC1B,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAoB;gBAEtB,MAAM,GAAE,OAAO,CAAC,iBAAiB,CAAM;IAInD;;OAEG;IACH,OAAO,CAAC,SAAS,EAAE,kBAAkB,EAAE,GAAG,iBAAiB;IAgC3D;;OAEG;IACH,OAAO,CAAC,WAAW;IAgBnB;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAyC3B;;OAEG;IACH,OAAO,CAAC,eAAe;IAWvB;;OAEG;IACH,OAAO,CAAC,cAAc;IAUtB;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAmC9B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAQ1B;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,kBAAkB,EAC5B,iBAAiB,EAAE,kBAAkB,EAAE,GACtC,kBAAkB,GAAG,IAAI,CAW3B"}
@@ -0,0 +1,176 @@
1
+ /**
2
+ * Constant Consistency Analyzer
3
+ *
4
+ * Detects inconsistent constants - same name with different values
5
+ * across the codebase.
6
+ */
7
+ /**
8
+ * Default consistency config
9
+ */
10
+ export const DEFAULT_CONSISTENCY_CONFIG = {
11
+ ignoreCase: true,
12
+ categories: [], // All categories
13
+ minInstances: 2,
14
+ excludePatterns: ['node_modules', 'dist', 'build', '.git'],
15
+ };
16
+ /**
17
+ * Consistency analyzer
18
+ */
19
+ export class ConsistencyAnalyzer {
20
+ config;
21
+ constructor(config = {}) {
22
+ this.config = { ...DEFAULT_CONSISTENCY_CONFIG, ...config };
23
+ }
24
+ /**
25
+ * Analyze constants for inconsistencies
26
+ */
27
+ analyze(constants) {
28
+ const startTime = performance.now();
29
+ // Filter constants
30
+ const filtered = constants.filter(c => {
31
+ // Exclude by file pattern
32
+ if (this.shouldExcludeFile(c.file)) {
33
+ return false;
34
+ }
35
+ // Filter by category if specified
36
+ if (this.config.categories.length > 0 && !this.config.categories.includes(c.category)) {
37
+ return false;
38
+ }
39
+ return true;
40
+ });
41
+ // Group by name
42
+ const byName = this.groupByName(filtered);
43
+ // Find inconsistencies
44
+ const inconsistencies = this.findInconsistencies(byName);
45
+ return {
46
+ inconsistencies,
47
+ totalAnalyzed: filtered.length,
48
+ uniqueNames: byName.size,
49
+ analysisTimeMs: performance.now() - startTime,
50
+ };
51
+ }
52
+ /**
53
+ * Group constants by name
54
+ */
55
+ groupByName(constants) {
56
+ const groups = new Map();
57
+ for (const constant of constants) {
58
+ const key = this.config.ignoreCase
59
+ ? constant.name.toLowerCase()
60
+ : constant.name;
61
+ const group = groups.get(key) || [];
62
+ group.push(constant);
63
+ groups.set(key, group);
64
+ }
65
+ return groups;
66
+ }
67
+ /**
68
+ * Find inconsistencies in grouped constants
69
+ */
70
+ findInconsistencies(groups) {
71
+ const inconsistencies = [];
72
+ for (const [name, constants] of groups) {
73
+ // Skip if not enough instances
74
+ if (constants.length < this.config.minInstances) {
75
+ continue;
76
+ }
77
+ // Check if values are different
78
+ const uniqueValues = this.getUniqueValues(constants);
79
+ if (uniqueValues.size <= 1) {
80
+ continue; // All same value, not inconsistent
81
+ }
82
+ // Build instances
83
+ const instances = constants.map(c => ({
84
+ id: c.id,
85
+ file: c.file,
86
+ line: c.line,
87
+ value: c.value ?? null,
88
+ }));
89
+ // Generate recommendation
90
+ const recommendation = this.generateRecommendation(name, constants, uniqueValues);
91
+ inconsistencies.push({
92
+ name: constants[0]?.name ?? name, // Use original case
93
+ instances,
94
+ recommendation,
95
+ });
96
+ }
97
+ // Sort by number of instances (most first)
98
+ inconsistencies.sort((a, b) => b.instances.length - a.instances.length);
99
+ return inconsistencies;
100
+ }
101
+ /**
102
+ * Get unique values from constants
103
+ */
104
+ getUniqueValues(constants) {
105
+ const values = new Set();
106
+ for (const constant of constants) {
107
+ const valueStr = this.normalizeValue(constant.value);
108
+ values.add(valueStr);
109
+ }
110
+ return values;
111
+ }
112
+ /**
113
+ * Normalize a value for comparison
114
+ */
115
+ normalizeValue(value) {
116
+ if (value === null || value === undefined) {
117
+ return 'null';
118
+ }
119
+ if (typeof value === 'string') {
120
+ return `"${value}"`;
121
+ }
122
+ return String(value);
123
+ }
124
+ /**
125
+ * Generate a recommendation for fixing inconsistency
126
+ */
127
+ generateRecommendation(name, constants, uniqueValues) {
128
+ const valueCount = uniqueValues.size;
129
+ const instanceCount = constants.length;
130
+ // Find most common value
131
+ const valueCounts = new Map();
132
+ for (const c of constants) {
133
+ const valueStr = this.normalizeValue(c.value);
134
+ valueCounts.set(valueStr, (valueCounts.get(valueStr) || 0) + 1);
135
+ }
136
+ let mostCommonValue = '';
137
+ let maxCount = 0;
138
+ for (const [value, count] of valueCounts) {
139
+ if (count > maxCount) {
140
+ maxCount = count;
141
+ mostCommonValue = value;
142
+ }
143
+ }
144
+ // Generate recommendation
145
+ if (valueCount === 2) {
146
+ return `Constant '${name}' has 2 different values across ${instanceCount} locations. ` +
147
+ `Consider standardizing to ${mostCommonValue} (used ${maxCount} times).`;
148
+ }
149
+ return `Constant '${name}' has ${valueCount} different values across ${instanceCount} locations. ` +
150
+ `Most common value is ${mostCommonValue} (used ${maxCount} times). ` +
151
+ `Consider consolidating into a single source of truth.`;
152
+ }
153
+ /**
154
+ * Check if a file should be excluded
155
+ */
156
+ shouldExcludeFile(filePath) {
157
+ for (const pattern of this.config.excludePatterns) {
158
+ if (filePath.includes(pattern)) {
159
+ return true;
160
+ }
161
+ }
162
+ return false;
163
+ }
164
+ }
165
+ /**
166
+ * Quick check for potential inconsistency
167
+ */
168
+ export function hasPotentialInconsistency(constant, existingConstants) {
169
+ const sameName = existingConstants.find(c => c.name.toLowerCase() === constant.name.toLowerCase() &&
170
+ c.file !== constant.file);
171
+ if (sameName && sameName.value !== constant.value) {
172
+ return sameName;
173
+ }
174
+ return null;
175
+ }
176
+ //# sourceMappingURL=consistency-analyzer.js.map