Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/ui/scan/printMissing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function printMissing(
if (missing.length === 0) return false;

const fileType = comparedAgainst || 'environment file';
console.log(chalk.red(`❌ Missing in ${fileType}:`));
const label = chalk.bgRed.white.bold(' ERROR ');
console.log(
`${label} ${chalk.red(`Missing in ${fileType} (defined in code):`)}`,
);

// Group by variable → find their usages
const grouped = missing.reduce((acc: VariableUsages, variable: string) => {
Expand All @@ -43,11 +46,16 @@ export function printMissing(

// Print grouped by file
for (const [file, items] of byFile) {
console.log(chalk.bold(` ${file}`));
console.log();
console.log(chalk.bold(`${file}`));

for (const { variable, usage } of items) {
console.log(chalk.red(` ${variable}: Line ${usage.line}`));
console.log(chalk.red.dim(` ${usage.context.trim()}`));
const line = usage.line ?? 0;
const column = (usage as EnvUsage).column ?? 0;

const position = column > 0 ? `${line}:${column}` : `${line}`;

console.log(`${chalk.gray(position)} ${chalk.red(variable)}`);
}
}
console.log();
Expand Down
10 changes: 5 additions & 5 deletions test/unit/ui/scan/printMissing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('printMissing', () => {
expect(result).toBe(true);

expect(logSpy).toHaveBeenCalledWith(
chalk.red('Missing in .env.example:'),
chalk.red(' ERROR Missing in .env.example (defined in code):'),
);

expect(
Expand All @@ -75,13 +75,13 @@ describe('printMissing', () => {

expect(
logSpy.mock.calls.some((call: [string]) =>
String(call[0]).includes('API_KEY: Line 10'),
String(call[0]).includes('10:1 API_KEY'),
),
).toBe(true);

expect(
logSpy.mock.calls.some((call: [string]) =>
String(call[0]).includes('SECRET: Line 20'),
String(call[0]).includes('20:1 SECRET'),
),
).toBe(true);

Expand All @@ -103,7 +103,7 @@ describe('printMissing', () => {
printMissing(['A'], used, '');

expect(logSpy).toHaveBeenCalledWith(
chalk.red('Missing in environment file:'),
chalk.red(' ERROR Missing in environment file (defined in code):'),
);
});

Expand All @@ -114,6 +114,6 @@ describe('printMissing', () => {

expect(result).toBe(true);

expect(logSpy).toHaveBeenCalledWith(chalk.red('Missing in .env:'));
expect(logSpy).toHaveBeenCalledWith(chalk.red(' ERROR Missing in .env (defined in code):'));
});
});
Loading