Skip to content

Commit 96b4400

Browse files
authored
refactor: replace chalk with node.js built-in styleText function (#19)
1 parent d678002 commit 96b4400

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

package-lock.json

Lines changed: 0 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
"access": "public"
3939
},
4040
"dependencies": {
41-
"chalk": "^5.6.2",
4241
"commander": "^14.0.2",
4342
"fast-glob": "^3.3.3",
4443
"ignore": "^7.0.5"

src/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { Command } from 'commander';
44
import path from 'node:path';
55
import scanner from './scanner.js';
6-
import chalk from 'chalk';
6+
import { styleText } from 'node:util';
77

88
const program = new Command();
99
program
@@ -22,7 +22,7 @@ const logo = `
2222
2323
`;
2424

25-
console.log(chalk.magenta(logo));
25+
console.log(styleText('magenta', logo));
2626

2727
(async () => {
2828
const opts = program.opts();

src/scanner.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'node:path';
33
import fg from 'fast-glob';
44
import ignore from 'ignore';
55
import { execSync } from 'node:child_process';
6-
import chalk from 'chalk';
6+
import { styleText } from 'node:util';
77
import { findUnusedModules } from './unusedModuleDetector.js';
88

99
const 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

Comments
 (0)