@@ -3,7 +3,7 @@ import path from 'node:path';
33import fg from 'fast-glob' ;
44import ignore from 'ignore' ;
55import { execSync } from 'node:child_process' ;
6- import chalk from 'chalk ' ;
6+ import { styleText } from 'node:util ' ;
77import { findUnusedModules } from './unusedModuleDetector.js' ;
88
99const DEFAULT_CONFIG_FILES = [ '.codeguardianrc.json' , 'codeguardian.config.json' ] ;
@@ -186,46 +186,46 @@ async function run({ configPath = null, staged = false, verbose = false } = {})
186186 }
187187 }
188188 if ( unusedImports . length > 0 ) {
189- console . log ( chalk . yellowBright ( `\nWarning: Unused imports in ${ file } :` ) ) ;
189+ console . log ( styleText ( 'yellow' , `\nWarning: Unused imports in ${ file } :` ) ) ;
190190 for ( const id of unusedImports ) {
191- console . log ( chalk . yellow ( ` ${ id } ` ) ) ;
191+ console . log ( styleText ( 'yellow' , ` ${ id } ` ) ) ;
192192 }
193- console . log ( chalk . gray ( 'These imports are present but never used in this file.' ) ) ;
193+ console . log ( styleText ( 'gray' , 'These imports are present but never used in this file.' ) ) ;
194194 }
195195 }
196196 }
197197
198198 // Print nice output
199199 if ( findings . length === 0 ) {
200- console . log ( chalk . green ( 'Scan successful but no secrets found in.' , process . cwd ( ) ) ) ;
200+ console . log ( styleText ( 'green' , 'Scan successful but no secrets found in.' , process . cwd ( ) ) ) ;
201201 } else {
202- console . log ( chalk . red ( `Found ${ findings . length } file(s) with potential secrets:` ) ) ;
202+ console . log ( styleText ( 'red' , `Found ${ findings . length } file(s) with potential secrets:` ) ) ;
203203 for ( const f of findings ) {
204- console . log ( chalk . yellow ( `\nFile: ${ f . file } ` ) ) ;
204+ console . log ( styleText ( 'yellow' , `\nFile: ${ f . file } ` ) ) ;
205205 for ( const m of f . matches ) {
206- console . log ( ` ${ chalk . magenta ( ' Rule:') } ${ m . rule } ${ chalk . gray ( `(line ${ m . lineNumber } )` ) } \n ${ chalk . red ( m . line ) } ` ) ;
206+ console . log ( ` ${ styleText ( 'magenta' , ' Rule:') } ${ m . rule } ${ styleText ( 'gray' , `(line ${ m . lineNumber } )` ) } \n ${ styleText ( 'red' , m . line ) } ` ) ;
207207 }
208208 }
209209 }
210210
211211 // Unused JS/TS module detection (warn only)
212212 const unused = findUnusedModules ( jsTsFiles , importMap ) ;
213213 if ( unused . length > 0 ) {
214- console . log ( chalk . yellowBright ( `\nWarning: Unused modules detected (not imported by any other file):` ) ) ;
214+ console . log ( styleText ( 'yellowBright' , `\nWarning: Unused modules detected (not imported by any other file):` ) ) ;
215215 for ( const f of unused ) {
216- console . log ( chalk . yellow ( ` ${ f } ` ) ) ;
216+ console . log ( styleText ( 'yellow' , ` ${ f } ` ) ) ;
217217 }
218- console . log ( chalk . gray ( 'These files are not blocking CI, but consider cleaning up unused modules.' ) ) ;
218+ console . log ( styleText ( 'gray' , 'These files are not blocking CI, but consider cleaning up unused modules.' ) ) ;
219219 }
220220
221221 const endTime = process . hrtime . bigint ( ) ;
222222 const endMem = process . memoryUsage ( ) . heapUsed ;
223223 const durationMs = Number ( endTime - startTime ) / 1e6 ;
224224 const memMB = ( endMem - startMem ) / 1024 / 1024 ;
225- console . log ( chalk . cyanBright ( `\nScan stats:` ) ) ;
226- console . log ( chalk . cyan ( ` Files scanned: ${ filesScanned } ` ) ) ;
227- console . log ( chalk . cyan ( ` Time taken: ${ durationMs . toFixed ( 1 ) } ms` ) ) ;
228- console . log ( chalk . cyan ( ` Memory used: ${ memMB . toFixed ( 2 ) } MB` ) ) ;
225+ console . log ( styleText ( 'cyanBright' , `\nScan stats:` ) ) ;
226+ console . log ( styleText ( 'cyan' , ` Files scanned: ${ filesScanned } ` ) ) ;
227+ console . log ( styleText ( 'cyan' , ` Time taken: ${ durationMs . toFixed ( 1 ) } ms` ) ) ;
228+ console . log ( styleText ( 'cyan' , ` Memory used: ${ memMB . toFixed ( 2 ) } MB` ) ) ;
229229
230230 return { findings } ;
231231}
0 commit comments