@@ -44,7 +44,7 @@ interface CallSiteInfo {
44
44
character : number ;
45
45
argumentsText : string [ ] ; // Added to store argument text
46
46
errorMessage : string | undefined ;
47
- errorCode : number ;
47
+ assertionId : number ;
48
48
}
49
49
50
50
/**
@@ -77,7 +77,6 @@ function getTsFilesRecursive(dirPath: string): string[] {
77
77
}
78
78
} catch ( error : any ) {
79
79
console . error ( `Error reading directory ${ dirPath } : ${ error . message } ` ) ;
80
- // Optionally, re-throw or handle differently
81
80
}
82
81
return tsFiles ;
83
82
}
@@ -116,12 +115,6 @@ function findFunctionCalls(filePaths: string[]): CallSiteInfo[] {
116
115
if ( ts . isIdentifier ( expression ) ) {
117
116
functionName = expression . text ;
118
117
}
119
- // Check if the call is to a property access (e.g., utils.fail(), this.hardAssert())
120
- else if ( ts . isPropertyAccessExpression ( expression ) ) {
121
- // We only care about the final property name being called
122
- functionName = expression . name . text ;
123
- }
124
- // Add checks for other forms if needed
125
118
126
119
// If we found a function name, and it's one we're looking for
127
120
if ( functionName && targetFunctionNames . has ( functionName ) ) {
@@ -134,7 +127,7 @@ function findFunctionCalls(filePaths: string[]): CallSiteInfo[] {
134
127
// --- Extract Arguments ---
135
128
const argsText : string [ ] = [ ] ;
136
129
let errorMessage : string | undefined ;
137
- let errorCode : number | undefined ;
130
+ let assertionId : number | undefined ;
138
131
if ( node . arguments && node . arguments . length > 0 ) {
139
132
node . arguments . forEach ( ( arg : ts . Expression ) => {
140
133
// Get the source text of the argument node
@@ -144,7 +137,7 @@ function findFunctionCalls(filePaths: string[]): CallSiteInfo[] {
144
137
errorMessage = arg . getText ( sourceFile ) ;
145
138
}
146
139
else if ( ts . isNumericLiteral ( arg ) ) {
147
- errorCode = parseInt ( arg . getText ( sourceFile ) , 10 ) ;
140
+ assertionId = parseInt ( arg . getText ( sourceFile ) , 10 ) ;
148
141
}
149
142
} ) ;
150
143
}
@@ -158,7 +151,7 @@ function findFunctionCalls(filePaths: string[]): CallSiteInfo[] {
158
151
character : character + 1 ,
159
152
argumentsText : argsText , // Store the extracted arguments,
160
153
errorMessage,
161
- errorCode : errorCode ?? - 1
154
+ assertionId : assertionId ?? - 1
162
155
} ) ;
163
156
}
164
157
}
@@ -183,26 +176,26 @@ function findFunctionCalls(filePaths: string[]): CallSiteInfo[] {
183
176
184
177
function handleList ( occurrences : CallSiteInfo [ ] ) : void {
185
178
if ( occurrences . length === 0 ) {
186
- log ( "No error codes found." ) ;
179
+ log ( "No assertion ids found." ) ;
187
180
return ;
188
181
}
189
182
190
- occurrences . sort ( ( a , b ) => a . errorCode - b . errorCode ) . forEach ( ( call ) => {
183
+ occurrences . sort ( ( a , b ) => a . assertionId - b . assertionId ) . forEach ( ( call ) => {
191
184
console . log (
192
- `CODE : ${ call . errorCode } ; MESSAGE: ${ call . errorMessage } ; SOURCE: '${ call . functionName } ' call at ${ path . relative ( process . cwd ( ) , call . fileName ) } :${ call . line } :${ call . character } `
185
+ `ID : ${ call . assertionId } ; MESSAGE: ${ call . errorMessage } ; SOURCE: '${ call . functionName } ' call at ${ path . relative ( process . cwd ( ) , call . fileName ) } :${ call . line } :${ call . character } `
193
186
) ;
194
187
} ) ;
195
188
196
189
}
197
190
198
- function handleFind ( occurrences : CallSiteInfo [ ] , targetCode : string | number ) : void {
191
+ function handleFind ( occurrences : CallSiteInfo [ ] , targetId : string | number ) : void {
199
192
// Normalize target code for comparison if necessary (e.g., string vs number)
200
- const target = typeof targetCode === 'number' ? targetCode : targetCode . toString ( ) ;
193
+ const target = typeof targetId === 'number' ? targetId : targetId . toString ( ) ;
201
194
202
- const foundLocations = occurrences . filter ( o => String ( o . errorCode ) === String ( target ) ) ; // Compare as strings
195
+ const foundLocations = occurrences . filter ( o => String ( o . assertionId ) === String ( target ) ) ; // Compare as strings
203
196
204
197
if ( foundLocations . length === 0 ) {
205
- log ( `Error code "${ targetCode } " not found.` ) ;
198
+ log ( `Assertion id "${ targetId } " not found.` ) ;
206
199
process . exit ( 1 ) ;
207
200
}
208
201
@@ -211,25 +204,25 @@ function handleFind(occurrences: CallSiteInfo[], targetCode: string | number): v
211
204
212
205
function handleCheck ( occurrences : CallSiteInfo [ ] ) : void {
213
206
if ( occurrences . length === 0 ) {
214
- log ( "No error codes found to check for duplicates." ) ;
207
+ log ( "No assertion ids found to check for duplicates." ) ;
215
208
return ;
216
209
}
217
- const codeCounts : { [ code : string ] : CallSiteInfo [ ] } = { } ;
210
+ const idCounts : { [ id : string ] : CallSiteInfo [ ] } = { } ;
218
211
219
212
occurrences . forEach ( occ => {
220
- const codeStr = String ( occ . errorCode ) ; // Use string representation as key
221
- if ( ! codeCounts [ codeStr ] ) {
222
- codeCounts [ codeStr ] = [ ] ;
213
+ const codeStr = String ( occ . assertionId ) ; // Use string representation as key
214
+ if ( ! idCounts [ codeStr ] ) {
215
+ idCounts [ codeStr ] = [ ] ;
223
216
}
224
- codeCounts [ codeStr ] . push ( occ ) ;
217
+ idCounts [ codeStr ] . push ( occ ) ;
225
218
} ) ;
226
219
227
220
let duplicatesFound = false ;
228
- log ( "Checking for duplicate error code usage:" ) ;
229
- Object . entries ( codeCounts ) . forEach ( ( [ code , locations ] ) => {
221
+ log ( "Checking for duplicate assertion id usage:" ) ;
222
+ Object . entries ( idCounts ) . forEach ( ( [ code , locations ] ) => {
230
223
if ( locations . length > 1 ) {
231
224
duplicatesFound = true ;
232
- console . error ( `\nDuplicate error code "${ code } " found at ${ locations . length } locations:` ) ;
225
+ console . error ( `\nDuplicate assertion id "${ code } " found at ${ locations . length } locations:` ) ;
233
226
locations . forEach ( loc => {
234
227
const relativePath = path . relative ( process . cwd ( ) , loc . fileName ) ;
235
228
console . error ( `- ${ relativePath } :${ loc . line } :${ loc . character } ` ) ;
@@ -238,7 +231,7 @@ function handleCheck(occurrences: CallSiteInfo[]): void {
238
231
} ) ;
239
232
240
233
if ( ! duplicatesFound ) {
241
- log ( "No duplicate error codes found." ) ;
234
+ log ( "No duplicate assertion ids found." ) ;
242
235
}
243
236
else {
244
237
process . exit ( 1 ) ;
@@ -250,8 +243,8 @@ function handleNew(occurrences: CallSiteInfo[]): void {
250
243
let maxCode = 0 ;
251
244
252
245
occurrences . forEach ( occ => {
253
- if ( occ . errorCode > maxCode ) {
254
- maxCode = occ . errorCode ;
246
+ if ( occ . assertionId > maxCode ) {
247
+ maxCode = occ . assertionId ;
255
248
}
256
249
} ) ;
257
250
@@ -281,23 +274,23 @@ async function main(): Promise<void> {
281
274
} )
282
275
. option ( "find" , {
283
276
alias : "F" ,
284
- describe : "Find locations of a specific {errorCode }" ,
277
+ describe : "Find locations of a specific {assertionId }" ,
285
278
type : "string" ,
286
279
nargs : 1 ,
287
280
} )
288
281
. option ( "list" , {
289
282
alias : "L" ,
290
- describe : "List all unique error codes found (default action)" ,
283
+ describe : "List all unique assertion ids found (default action)" ,
291
284
type : "boolean" ,
292
285
} )
293
286
. option ( "new" , {
294
287
alias : "N" ,
295
- describe : "Suggest a new error code based on existing ones" ,
288
+ describe : "Suggest a new assertion id based on existing ones" ,
296
289
type : "boolean" ,
297
290
} )
298
291
. option ( "check" , {
299
292
alias : "C" ,
300
- describe : "Check for duplicate usage of error codes " ,
293
+ describe : "Check for duplicate usage of assertion ids " ,
301
294
type : "boolean" ,
302
295
} )
303
296
. check ( ( argv ) => {
@@ -338,10 +331,10 @@ async function main(): Promise<void> {
338
331
log ( "No relevant .ts or .tsx files found." ) ;
339
332
process . exit ( 0 ) ;
340
333
}
341
- log ( `Found ${ filesToScan . length } files. Analyzing for error codes ...` ) ;
334
+ log ( `Found ${ filesToScan . length } files. Analyzing for assertion ids ...` ) ;
342
335
343
336
const allOccurrences = findFunctionCalls ( filesToScan ) ;
344
- log ( `Scan complete. Found ${ allOccurrences . length } potential error code occurrences.` ) ;
337
+ log ( `Scan complete. Found ${ allOccurrences . length } potential assertion id occurrences.` ) ;
345
338
346
339
// Determine action based on flags
347
340
if ( argv [ 'find' ] ) {
0 commit comments